mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 02:37:18 +03:00
Ignore case in extracted tags
This commit is contained in:
parent
d9abb7fc2c
commit
461b7424e9
@ -30,8 +30,8 @@ func (m *Metadata) AlbumArtist() string { return m.tags["album_artist"]
|
||||
func (m *Metadata) Composer() string { return m.tags["composer"] }
|
||||
func (m *Metadata) Genre() string { return m.tags["genre"] }
|
||||
func (m *Metadata) Year() int { return m.parseInt("year") }
|
||||
func (m *Metadata) TrackNumber() (int, int) { return m.parseTuple("trackNum") }
|
||||
func (m *Metadata) DiscNumber() (int, int) { return m.parseTuple("discNum") }
|
||||
func (m *Metadata) TrackNumber() (int, int) { return m.parseTuple("trackNum", "trackTotal") }
|
||||
func (m *Metadata) DiscNumber() (int, int) { return m.parseTuple("discNum", "discTotal") }
|
||||
func (m *Metadata) HasPicture() bool { return m.tags["hasPicture"] == "Video" }
|
||||
func (m *Metadata) Comment() string { return m.tags["comment"] }
|
||||
func (m *Metadata) Compilation() bool { return m.parseBool("compilation") }
|
||||
@ -132,19 +132,21 @@ func isAudioFile(extension string) bool {
|
||||
|
||||
var (
|
||||
tagsRx = map[*regexp.Regexp]string{
|
||||
regexp.MustCompile(`^\s{4}compilation\s+:(.*)`): "compilation",
|
||||
regexp.MustCompile(`^\s{4}genre\s+:\s(.*)`): "genre",
|
||||
regexp.MustCompile(`^\s{4}title\s+:\s(.*)`): "title",
|
||||
regexp.MustCompile(`^\s{4}comment\s+:\s(.*)`): "comment",
|
||||
regexp.MustCompile(`^\s{4}artist\s+:\s(.*)`): "artist",
|
||||
regexp.MustCompile(`^\s{4}album_artist\s+:\s(.*)`): "album_artist",
|
||||
regexp.MustCompile(`^\s{4}TCM\s+:\s(.*)`): "composer",
|
||||
regexp.MustCompile(`^\s{4}album\s+:\s(.*)`): "album",
|
||||
regexp.MustCompile(`^\s{4}track\s+:\s(.*)`): "trackNum",
|
||||
regexp.MustCompile(`^\s{4}disc\s+:\s(.*)`): "discNum",
|
||||
regexp.MustCompile(`^\s{4}TPA\s+:\s(.*)`): "discNum",
|
||||
regexp.MustCompile(`^\s{4}date\s+:\s(.*)`): "year",
|
||||
regexp.MustCompile(`^\s{4}Stream #\d+:1: (.+):\s`): "hasPicture",
|
||||
regexp.MustCompile(`(?i)^\s{4}compilation\s+:(.*)`): "compilation",
|
||||
regexp.MustCompile(`(?i)^\s{4}genre\s+:\s(.*)`): "genre",
|
||||
regexp.MustCompile(`(?i)^\s{4}title\s+:\s(.*)`): "title",
|
||||
regexp.MustCompile(`(?i)^\s{4}comment\s+:\s(.*)`): "comment",
|
||||
regexp.MustCompile(`(?i)^\s{4}artist\s+:\s(.*)`): "artist",
|
||||
regexp.MustCompile(`(?i)^\s{4}album_artist\s+:\s(.*)`): "album_artist",
|
||||
regexp.MustCompile(`(?i)^\s{4}TCM\s+:\s(.*)`): "composer",
|
||||
regexp.MustCompile(`(?i)^\s{4}album\s+:\s(.*)`): "album",
|
||||
regexp.MustCompile(`(?i)^\s{4}track\s+:\s(.*)`): "trackNum",
|
||||
regexp.MustCompile(`(?i)^\s{4}tracktotal\s+:\s(.*)`): "trackTotal",
|
||||
regexp.MustCompile(`(?i)^\s{4}disc\s+:\s(.*)`): "discNum",
|
||||
regexp.MustCompile(`(?i)^\s{4}disctotal\s+:\s(.*)`): "discTotal",
|
||||
regexp.MustCompile(`(?i)^\s{4}TPA\s+:\s(.*)`): "discNum",
|
||||
regexp.MustCompile(`(?i)^\s{4}date\s+:\s(.*)`): "year",
|
||||
regexp.MustCompile(`^\s{4}Stream #\d+:\d+: (.+):\s`): "hasPicture",
|
||||
}
|
||||
|
||||
durationRx = regexp.MustCompile(`^\s\sDuration: ([\d.:]+).*bitrate: (\d+)`)
|
||||
@ -181,13 +183,15 @@ func (m *Metadata) parseInt(tagName string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Metadata) parseTuple(tagName string) (int, int) {
|
||||
if v, ok := m.tags[tagName]; ok {
|
||||
func (m *Metadata) parseTuple(numTag string, totalTag string) (int, int) {
|
||||
if v, ok := m.tags[numTag]; ok {
|
||||
tuple := strings.Split(v, "/")
|
||||
t1, t2 := 0, 0
|
||||
t1, _ = strconv.Atoi(tuple[0])
|
||||
if len(tuple) > 1 {
|
||||
t2, _ = strconv.Atoi(tuple[1])
|
||||
} else {
|
||||
t2, _ = strconv.Atoi(m.tags[totalTag])
|
||||
}
|
||||
return t1, t2
|
||||
}
|
||||
|
@ -103,6 +103,42 @@ At least one output file must be specified`
|
||||
Expect(md.Title()).To(Equal("Groovin' (feat. Daniel Sneijers, Susanne Alt)"))
|
||||
})
|
||||
|
||||
It("ignores case in the tag name", func() {
|
||||
const outputWithOverlappingTitleTag = `
|
||||
Input #0, flac, from '/Users/deluan/Downloads/06. Back In Black.flac':
|
||||
Metadata:
|
||||
ALBUM : Back In Black
|
||||
album_artist : AC/DC
|
||||
ARTIST : AC/DC
|
||||
COMPOSER : Angus Young;Malcolm Young;Brian Johnson
|
||||
DATE : 1980.07.25
|
||||
disc : 1
|
||||
GENRE : Hard Rock
|
||||
LANGUAGE : EN
|
||||
RATING : 2
|
||||
TITLE : Back In Black
|
||||
DISCTOTAL : 1
|
||||
TRACKTOTAL : 10
|
||||
track : 6
|
||||
REPLAYGAIN_TRACK_GAIN: -8.51 dB
|
||||
REPLAYGAIN_TRACK_PEAK: 0.998322
|
||||
Duration: 00:04:16.00, start: 0.000000, bitrate: 995 kb/s
|
||||
Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
|
||||
Side data:
|
||||
replaygain: track gain - -8.510000, track peak - 0.000023, album gain - unknown, album peak - unknown,`
|
||||
md, _ := extractMetadata("groovin.mp3", outputWithOverlappingTitleTag)
|
||||
Expect(md.Title()).To(Equal("Back In Black"))
|
||||
Expect(md.Album()).To(Equal("Back In Black"))
|
||||
Expect(md.Genre()).To(Equal("Hard Rock"))
|
||||
n, t := md.TrackNumber()
|
||||
Expect(n).To(Equal(6))
|
||||
Expect(t).To(Equal(10))
|
||||
n, t = md.DiscNumber()
|
||||
Expect(n).To(Equal(1))
|
||||
Expect(t).To(Equal(1))
|
||||
|
||||
})
|
||||
|
||||
// TODO Handle multiline tags
|
||||
XIt("parses multiline tags", func() {
|
||||
const outputWithMultilineComment = `
|
||||
|
Loading…
x
Reference in New Issue
Block a user