Skip to content

🎧 Your Personal Streaming Service

Fix ffmpeg bitrate parsing for flac files

Deluan174ad9e9daa8
diff --git a/scanner/metadata/ffmpeg/ffmpeg.go b/scanner/metadata/ffmpeg/ffmpeg.go
index a4c8c66bd..21a9c57b2 100644
--- a/scanner/metadata/ffmpeg/ffmpeg.go
+++ b/scanner/metadata/ffmpeg/ffmpeg.go
@@ -73,7 +73,11 @@ var (
durationRx = regexp.MustCompile(`^\s\sDuration: ([\d.:]+).*bitrate: (\d+)`)
// Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
- audioStreamRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+.*: (Audio): (.*), (.* Hz), ([\w\.]+),*(.*.,)*(.(\d+).kb/s)*`)
+ bitRateRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+: Audio:.*, (\d+) kb/s`)
+
+ // Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
+ // Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
+ audioStreamRx = regexp.MustCompile(`^\s{2,4}Stream #\d+:\d+.*: Audio: (.*), (.* Hz), ([\w\.]+),*(.*.,)*`)
// 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,10 +155,14 @@ func (e *Parser) parseInfo(info string) map[string][]string {
continue
}
+ match = bitRateRx.FindStringSubmatch(line)
+ if len(match) > 0 {
+ tags["bitrate"] = []string{match[1]}
+ }
+
match = audioStreamRx.FindStringSubmatch(line)
if len(match) > 0 {
- tags["bitrate"] = []string{match[7]}
- tags["channels"] = []string{e.parseChannels(match[4])}
+ tags["channels"] = []string{e.parseChannels(match[3])}
}
}
diff --git a/scanner/metadata/ffmpeg/ffmpeg_test.go b/scanner/metadata/ffmpeg/ffmpeg_test.go
index 94bed0f45..32fb217cf 100644
--- a/scanner/metadata/ffmpeg/ffmpeg_test.go
+++ b/scanner/metadata/ffmpeg/ffmpeg_test.go
@@ -97,7 +97,7 @@ 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() {
+ It("parse flac bitrates", 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
@@ -106,6 +106,19 @@ Input #0, mp3, from '/Users/deluan/Music/iTunes/iTunes Media/Music/Compilations/
Expect(md).To(HaveKeyWithValue("channels", []string{"2"}))
})
+ It("parse channels from the stream with bitrate", func() {
+ const output = `
+Input #0, flac, from '/Users/deluan/Music/Music/Media/__/Crazy For You/01-01 Crazy For You.flac':
+ Metadata:
+ TITLE : Crazy For You
+ Duration: 00:04:13.00, start: 0.000000, bitrate: 852 kb/s
+ Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
+ Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 600x600, 90k tbr, 90k tbn, 90k tbc (attached pic)
+`
+ md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
+ Expect(md).To(HaveKeyWithValue("bitrate", []string{"852"}))
+ })
+
It("parse 7.1 channels from the stream", func() {
const output = `
Input #0, wav, from '/Users/deluan/Music/Music/Media/_/multichannel/Nums_7dot1_24_48000.wav':