Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,5 @@ replace go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.202411151126
exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible

replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a

replace github.com/dhowden/tag => github.com/dschmidt/tag v0.0.0-20260730135516-8eb6fc4a6973
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 h1:OtSeLS5y0Uy01jaKK4mA/WVIYtpzVm63vLVAPzJXigg=
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E=
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
Expand All @@ -310,6 +308,8 @@ github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pM
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dschmidt/tag v0.0.0-20260730135516-8eb6fc4a6973 h1:XnAwTTbblPJI6OVkRwqVA2MGjre29B/+wsi16lQfJ+E=
github.com/dschmidt/tag v0.0.0-20260730135516-8eb6fc4a6973/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e h1:rcHHSQqzCgvlwP0I/fQ8rQMn/MpHE5gWSLdtpxtP6KQ=
Expand Down
23 changes: 22 additions & 1 deletion services/thumbnails/pkg/preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (i AudioDecoder) Convert(r io.Reader) (any, error) {
return nil, err
}

picture := m.Picture()
picture := selectCoverArt(m.Pictures())
if picture == nil {
return nil, thumbnailerErrors.ErrNoImageFromAudioFile
}
Expand All @@ -102,6 +102,27 @@ func (i AudioDecoder) Convert(r io.Reader) (any, error) {
return converter.Convert(bytes.NewReader(picture.Data))
}

// frontCoverType is the ID3/APIC picture type byte for a front cover, shared by
// the ID3v2, FLAC and OGG tag formats (see github.com/dhowden/tag pictureTypes).
const frontCoverType byte = 0x03

// selectCoverArt deterministically picks the cover art from an audio file's
// embedded pictures: the explicitly tagged front cover if present, otherwise
// the first available picture. Many taggers store the cover as type "Other"
// (0x00) instead of "Cover (front)" (0x03), so the fallback is the common case.
// It returns nil when there are no pictures.
func selectCoverArt(pictures []tag.Picture) *tag.Picture {
if len(pictures) == 0 {
return nil
}
for i := range pictures {
if pictures[i].RawType == frontCoverType {
return &pictures[i]
}
}
return &pictures[0]
}

// TxtToImageConverter is a converter for the text file
type TxtToImageConverter struct {
fontLoader *FontLoader
Expand Down
23 changes: 23 additions & 0 deletions services/thumbnails/pkg/preprocessor/preprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/dhowden/tag"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"

Expand Down Expand Up @@ -127,6 +128,28 @@ var _ = Describe("ImageDecoder", func() {
})
})

Describe("selectCoverArt", func() {
front := tag.Picture{RawType: frontCoverType, MIMEType: "image/jpeg", Data: []byte("front")}
back := tag.Picture{RawType: 0x04, MIMEType: "image/jpeg", Data: []byte("back")}
other := tag.Picture{RawType: 0x00, MIMEType: "image/png", Data: []byte("other")}

It("returns nil when there are no pictures", func() {
Expect(selectCoverArt(nil)).To(BeNil())
Expect(selectCoverArt([]tag.Picture{})).To(BeNil())
})
It("prefers the front cover regardless of order", func() {
got := selectCoverArt([]tag.Picture{back, other, front})
Expect(got).ToNot(BeNil())
Expect(got.RawType).To(Equal(frontCoverType))
Expect(got.Data).To(Equal([]byte("front")))
})
It("falls back to the first picture when none is a front cover", func() {
got := selectCoverArt([]tag.Picture{other, back})
Expect(got).ToNot(BeNil())
Expect(got.Data).To(Equal([]byte("other")))
})
})

Describe("should decode text", func() {
var decoder TxtToImageConverter
BeforeEach(func() {
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/dhowden/tag/dsf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/dhowden/tag/id3v1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/dhowden/tag/id3v2frames.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/dhowden/tag/id3v2metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/dhowden/tag/mp4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/dhowden/tag/tag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions vendor/github.com/dhowden/tag/vorbis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ github.com/dgraph-io/ristretto/z/simd
# github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f
## explicit
github.com/dgryski/go-rendezvous
# github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
# github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 => github.com/dschmidt/tag v0.0.0-20260730135516-8eb6fc4a6973
## explicit; go 1.20
github.com/dhowden/tag
# github.com/distribution/reference v0.6.0
Expand Down Expand Up @@ -2738,3 +2738,4 @@ stash.kopano.io/kgol/rndm
# github.com/unrolled/secure => github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4
# go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3
# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a
# github.com/dhowden/tag => github.com/dschmidt/tag v0.0.0-20260730135516-8eb6fc4a6973