From 109f81e713cbdea75ed6c24e5a53000f8f5f5153 Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Fri, 31 Mar 2023 20:23:11 -0400 Subject: [PATCH] Fix bitrate units when scanning In `0183bcb6` the scanner switched from using Mutagen to Mediafile for scanning files. Prior to this commit, the bitrate from Mutagen was divided by 1000 to convert it from bps to kbps. After switching to Mediafile, the conversion was dropped even though Mediafile also reports bitrate in bps. This commit adds back the conversion to kbps and adds a test that checks that the bitrate and some other metadata is correct. This commit will fix transcoding being applied in some cases where it isn't needed. This was happening because the bitrate in the DB was always larger than the requested bitrate due to its units. --- supysonic/scanner.py | 2 +- tests/base/test_scanner.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/supysonic/scanner.py b/supysonic/scanner.py index 70b582b..c2f32dd 100644 --- a/supysonic/scanner.py +++ b/supysonic/scanner.py @@ -239,7 +239,7 @@ class Scanner(Thread): trdict["duration"] = int(tag.length) trdict["has_art"] = bool(tag.images) - trdict["bitrate"] = tag.bitrate + trdict["bitrate"] = tag.bitrate // 1000 trdict["last_modification"] = mtime tralbum = self.__find_album(albumartist, album) diff --git a/tests/base/test_scanner.py b/tests/base/test_scanner.py index 4f837f3..9f04f81 100644 --- a/tests/base/test_scanner.py +++ b/tests/base/test_scanner.py @@ -70,6 +70,22 @@ class ScannerTestCase(unittest.TestCase): self.scanner.scan_file("/some/inexistent/path") self.assertEqual(db.Track.select().count(), 1) + def test_scanned_metadata(self): + self.assertEqual(db.Track.select().count(), 1) + + track = db.Track.select().first() + artist = db.Artist.select().where(db.Artist.id == track.artist).first() + album = db.Album.select().where(db.Album.id == track.album).first() + + self.assertEqual(track.bitrate, 128) + self.assertEqual(track.disc, 1) + self.assertEqual(track.number, 1) + self.assertEqual(track.duration, 4) + self.assertEqual(track.has_art, True) + self.assertEqual(track.title, "[silence]") + self.assertEqual(artist.name, "Some artist") + self.assertEqual(album.name, "Awesome album") + def test_remove_file(self): track = db.Track.select().first() self.assertRaises(TypeError, self.scanner.remove_file, None)