mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-09 19:52:16 +00:00
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.
This commit is contained in:
parent
dc93b43c41
commit
109f81e713
@ -239,7 +239,7 @@ class Scanner(Thread):
|
|||||||
trdict["duration"] = int(tag.length)
|
trdict["duration"] = int(tag.length)
|
||||||
trdict["has_art"] = bool(tag.images)
|
trdict["has_art"] = bool(tag.images)
|
||||||
|
|
||||||
trdict["bitrate"] = tag.bitrate
|
trdict["bitrate"] = tag.bitrate // 1000
|
||||||
trdict["last_modification"] = mtime
|
trdict["last_modification"] = mtime
|
||||||
|
|
||||||
tralbum = self.__find_album(albumartist, album)
|
tralbum = self.__find_album(albumartist, album)
|
||||||
|
@ -70,6 +70,22 @@ class ScannerTestCase(unittest.TestCase):
|
|||||||
self.scanner.scan_file("/some/inexistent/path")
|
self.scanner.scan_file("/some/inexistent/path")
|
||||||
self.assertEqual(db.Track.select().count(), 1)
|
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):
|
def test_remove_file(self):
|
||||||
track = db.Track.select().first()
|
track = db.Track.select().first()
|
||||||
self.assertRaises(TypeError, self.scanner.remove_file, None)
|
self.assertRaises(TypeError, self.scanner.remove_file, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user