release / go (push) Successful in 2m4s
release / web (push) Successful in 1m21s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m9s
release / android (push) Successful in 4m28s
release / Build signed APK (push) Successful in 4m56s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
Some taggers end a UTF-16 text frame with a two-byte terminator and then one more zero byte, so the frame holds an odd number of bytes. dhowden/tag refuses the whole tag when it meets one, and the scanner then skipped the file: 61 tracks on dev (whole albums from one tagger, with a genre or year frame written this way) never reached the library. internal/tagread.ReadFrom reads with dhowden/tag first. When that fails on an ID3v2.3/2.4 tag, it rebuilds the tag in memory with the stray byte trimmed from each such frame and reads it again. Anything else still fails with dhowden/tag's own error. The scanner, both MBID backfills, embedded cover art and Subsonic lyrics all read through it. The ID3v2 primitives (syncsafe and frame sizes, the extended header, unsynchronisation) move from library/id3v2genre.go into tagread, so the genre reader and the repair share one copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package coverart
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/tagread"
|
|
)
|
|
|
|
// ErrNoEmbeddedArt indicates the audio file has no embedded picture.
|
|
// Distinct from "tag read failed" so the enricher can quietly fall
|
|
// through to the provider chain without logging at warn/error level.
|
|
var ErrNoEmbeddedArt = errors.New("coverart: no embedded album art")
|
|
|
|
// ExtractEmbeddedAlbumArt reads the embedded picture from an audio
|
|
// file's tag block: ID3v2 APIC frames (MP3), FLAC
|
|
// METADATA_BLOCK_PICTURE blocks, MP4 covr atoms (M4A/M4B/AAC), and OGG
|
|
// METADATA_BLOCK_PICTURE base64 in vorbis comments. Whichever format
|
|
// dhowden/tag recognises.
|
|
//
|
|
// Returns ErrNoEmbeddedArt when the tag block parses but contains no
|
|
// usable picture; returns a wrapped error for I/O or tag-parse
|
|
// failures so callers can distinguish "no art" from "couldn't read".
|
|
//
|
|
// Picard-tagged libraries typically carry the canonical
|
|
// art in this block already — extracting it beats every external API
|
|
// guess for accuracy and avoids a network round-trip.
|
|
func ExtractEmbeddedAlbumArt(path string) ([]byte, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open: %w", err)
|
|
}
|
|
defer func() { _ = f.Close() }()
|
|
|
|
meta, err := tagread.ReadFrom(f)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("tag read: %w", err)
|
|
}
|
|
pic := meta.Picture()
|
|
if pic == nil || len(pic.Data) == 0 {
|
|
return nil, ErrNoEmbeddedArt
|
|
}
|
|
return pic.Data, nil
|
|
}
|