Clean up implementation plan: remove duplicate Step 3.2

- Remove duplicate extractPDFCover function documentation
- Fixes issue identified during plan review where Step 3.2
  appeared twice with identical content
This commit is contained in:
2026-02-25 20:53:46 -05:00
parent 9878f998db
commit f36e88c0ee
-78
View File
@@ -449,84 +449,6 @@ func (s *MediaScanner) extractPDFMetadata(path string) (*MediaMetadata, error) {
**Exact Code to INSERT:**
```go
// extractPDFCover extracts a cover image from a PDF file.
// It uses pdfcpu to extract images from the first page.
// Returns the path to the saved cover, or empty string if no cover found.
func (s *MediaScanner) extractPDFCover(pdfPath string) (string, error) {
// Create a temporary directory for extracted images
tmpDir, err := os.MkdirTemp("", "pdf-cover-")
if err != nil {
return "", fmt.Errorf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Use pdfcpu API to extract images from first page
// ExtractImagesFile(inFile, outDir string, selectedPages []string, conf *model.Configuration) error
err = pdfcpuapi.ExtractImagesFile(pdfPath, tmpDir, []string{"1"}, nil)
if err != nil {
// No images found or extraction failed - this is OK, just return empty
return "", nil
}
// Check for extracted images in the temp directory
entries, err := os.ReadDir(tmpDir)
if err != nil || len(entries) == 0 {
return "", nil
}
// Find the largest image (likely the cover)
var largestImage string
var largestSize int64
for _, entry := range entries {
if entry.IsDir() {
continue
}
info, err := entry.Info()
if err != nil {
continue
}
// Skip very small files (likely thumbnails or icons)
if info.Size() < 1000 {
continue
}
if info.Size() > largestSize {
largestImage = filepath.Join(tmpDir, entry.Name())
largestSize = info.Size()
}
}
if largestImage == "" {
return "", nil
}
// Read the image
imageData, err := os.ReadFile(largestImage)
if err != nil || len(imageData) == 0 {
return "", nil
}
// Save cover to disk (same pattern as comics: {pdf_path}.cover.jpg)
coverPath := pdfPath + ".cover.jpg"
if err := os.WriteFile(coverPath, imageData, 0644); err != nil {
return "", fmt.Errorf("failed to write cover file: %v", err)
}
return coverPath, nil
}
```
---
### Step 3.2: Add extractPDFCover Helper Function
**File:** `internal/services/media_scanner.go`
**Location:** AFTER the extractPDFMetadata function, BEFORE the ComicInfo struct
**Exact Code to INSERT:**
```go
// extractPDFCover extracts a cover image from a PDF file.
// It uses pdfcpu API to extract images from the first page.