From f36e88c0eeccbf5386b683b786d8a381d3642a74 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 25 Feb 2026 20:53:46 -0500 Subject: [PATCH] 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 --- IMPLEMENTATION_PLAN_COVER_PDF.md | 78 -------------------------------- 1 file changed, 78 deletions(-) diff --git a/IMPLEMENTATION_PLAN_COVER_PDF.md b/IMPLEMENTATION_PLAN_COVER_PDF.md index 99ea207..76ffeab 100644 --- a/IMPLEMENTATION_PLAN_COVER_PDF.md +++ b/IMPLEMENTATION_PLAN_COVER_PDF.md @@ -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.