Files
bvandeusenandClaude Opus 5.5 80ecc2f7e7
release / govulncheck (push) Successful in 14s
release / web (push) Successful in 1m21s
release / go (push) Successful in 1m29s
release / integration (push) Successful in 5m1s
release / android (push) Successful in 5m5s
release / Build signed APK (releases and dev) (push) Successful in 5m21s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 16s
release / Verify release artifacts (tag releases only) (push) Skipped
fix: imported FLAC, Ogg and Opus files keep their track and disc numbers (#6171)
The importer wrote track=N/M for every format, which ffmpeg stores in a
Vorbis comment as TRACKNUMBER=3/20; dhowden/tag reads a Vorbis TRACKNUMBER
with a bare Atoi, so it came back 0. All 245 tracks imported since
2026-10-10 (Humanz, Plastic Beach, the Gorillaz super deluxe and twelve
more albums) have no track or disc number, and their album pages have no
order.

- The importer writes a Vorbis track and disc number alone, with
  TRACKTOTAL and DISCTOTAL, as Picard does. ID3 and MP4 keep N/M.
- ReadTrackAndDisc takes the number before a slash when the Vorbis reader
  returns 0, for the scanner and for the import's own check of a download.
- tagReadVersion 6 re-reads the files already held (tag reads only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 11:49:44 -04:00

41 lines
978 B
Go

package library
import (
"strconv"
"strings"
"github.com/dhowden/tag"
)
// ReadTrackAndDisc reads a file's track and disc numbers. dhowden/tag reads a
// Vorbis TRACKNUMBER or DISCNUMBER only as a bare number, but taggers also
// write "3/20" there (Minstrel's own importer did until #6171), and that
// reads as 0. For Vorbis the number before the slash is taken instead.
func ReadTrackAndDisc(m tag.Metadata) (track, disc int) {
track, _ = m.Track()
disc, _ = m.Disc()
if m.Format() != tag.VORBIS {
return track, disc
}
raw := m.Raw()
if track == 0 {
track = leadingNumber(raw["tracknumber"])
}
if disc == 0 {
disc = leadingNumber(raw["discnumber"])
}
return track, disc
}
// leadingNumber is the number in a tag value of "3" or "3/20"; 0 for
// anything else.
func leadingNumber(v any) int {
s, _ := v.(string)
before, _, _ := strings.Cut(s, "/")
n, err := strconv.Atoi(strings.TrimSpace(before))
if err != nil || n < 0 {
return 0
}
return n
}