feat: Adds Audio Channel Metadata - #1036

This commit is contained in:
Miguel A. Arroyo
2021-08-20 17:35:59 -07:00
committed by Deluan Quintão
parent 0079a9b938
commit e12a14a87d
14 changed files with 115 additions and 12 deletions
+20 -3
View File
@@ -73,7 +73,7 @@ var (
durationRx = regexp.MustCompile(`^\s\sDuration: ([\d.:]+).*bitrate: (\d+)`)
// Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
bitRateRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+: (Audio):.*, (\d+) kb/s`)
audioStreamRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+.*: (Audio): (.*), (.* Hz), (mono|stereo|5.1),*(.*.,)*(.(\d+).kb/s)*`)
// Stream #0:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 600x600 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn, 90k tbc`
coverRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+: (Video):.*`)
@@ -151,9 +151,14 @@ func (e *Parser) parseInfo(info string) map[string][]string {
continue
}
match = bitRateRx.FindStringSubmatch(line)
match = audioStreamRx.FindStringSubmatch(line)
if len(match) > 0 {
tags["bitrate"] = []string{match[2]}
tags["bitrate"] = []string{match[7]}
}
match = audioStreamRx.FindStringSubmatch(line)
if len(match) > 0 {
tags["channels"] = []string{e.parseChannels(match[4])}
}
}
@@ -175,6 +180,18 @@ func (e *Parser) parseDuration(tag string) string {
return strconv.FormatFloat(d.Sub(zeroTime).Seconds(), 'f', 2, 32)
}
func (e *Parser) parseChannels(tag string) string {
if tag == "mono" {
return "1"
} else if tag == "stereo" {
return "2"
} else if tag == "5.1" {
return "6"
}
return "0"
}
// Inputs will always be absolute paths
func (e *Parser) createProbeCommand(inputs []string) []string {
split := strings.Split(conf.Server.ProbeCommand, " ")
+36
View File
@@ -97,6 +97,42 @@ Input #0, mp3, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/
Expect(md).To(HaveKeyWithValue("duration", []string{"302.63"}))
})
It("parse channels from the stream with bitrate", func() {
const output = `
Input #0, mp3, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/Putumayo Presents Blues Lounge/09 Pablo's Blues.mp3':
Duration: 00:00:01.02, start: 0.000000, bitrate: 477 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s`
md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
Expect(md).To(HaveKeyWithValue("channels", []string{"2"}))
})
It("parse channels from the stream without bitrate", func() {
const output = `
Input #0, flac, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/Putumayo Presents Blues Lounge/09 Pablo's Blues.flac':
Duration: 00:00:01.02, start: 0.000000, bitrate: 1371 kb/s
Stream #0:0: Audio: flac, 44100 Hz, stereo, fltp, s32 (24 bit)`
md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
Expect(md).To(HaveKeyWithValue("channels", []string{"2"}))
})
It("parse channels from the stream with lang", func() {
const output = `
Input #0, flac, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/Putumayo Presents Blues Lounge/09 Pablo's Blues.m4a':
Duration: 00:00:01.02, start: 0.000000, bitrate: 1371 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 262 kb/s (default)`
md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
Expect(md).To(HaveKeyWithValue("channels", []string{"2"}))
})
It("parse channels from the stream with lang 2", func() {
const output = `
Input #0, flac, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/Putumayo Presents Blues Lounge/09 Pablo's Blues.m4a':
Duration: 00:00:01.02, start: 0.000000, bitrate: 1371 kb/s
Stream #0:0(eng): Audio: vorbis, 44100 Hz, stereo, fltp, 192 kb/s`
md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
Expect(md).To(HaveKeyWithValue("channels", []string{"2"}))
})
It("parses stream level tags", func() {
const output = `
Input #0, ogg, from './01-02 Drive (Teku).opus':