1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Fixed issues with float bitrate and empty tags

Thanks to @nextfullstorm
Closes #139
This commit is contained in:
spl0k 2019-03-23 17:08:46 +01:00
parent e2cc51a0f0
commit 780c96c404
5 changed files with 56 additions and 2 deletions

View File

@ -142,7 +142,7 @@ class Scanner:
trdict['duration'] = int(tag.info.length) trdict['duration'] = int(tag.info.length)
trdict['has_art'] = bool(Track._extract_cover_art(path)) trdict['has_art'] = bool(Track._extract_cover_art(path))
trdict['bitrate'] = (tag.info.bitrate if hasattr(tag.info, 'bitrate') else int(os.path.getsize(path) * 8 / tag.info.length)) // 1000 trdict['bitrate'] = int(tag.info.bitrate if hasattr(tag.info, 'bitrate') else os.path.getsize(path) * 8 / tag.info.length) // 1000
trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream' trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream'
trdict['last_modification'] = int(os.path.getmtime(path)) trdict['last_modification'] = int(os.path.getmtime(path))
@ -309,7 +309,10 @@ class Scanner:
if transform: if transform:
value = transform(value) value = transform(value)
return value if value else default return value if value else default
except (KeyError, ValueError): # KeyError: missing tag
# IndexError: tag is present but doesn't have any value
# ValueError: tag can't be transformed to correct type
except (KeyError, IndexError, ValueError):
return default return default
def stats(self): def stats(self):

View File

@ -18,6 +18,7 @@ from . import frontend
from .issue101 import Issue101TestCase from .issue101 import Issue101TestCase
from .issue129 import Issue129TestCase from .issue129 import Issue129TestCase
from .issue133 import Issue133TestCase from .issue133 import Issue133TestCase
from .issue139 import Issue139TestCase
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
@ -29,6 +30,7 @@ def suite():
suite.addTest(unittest.makeSuite(Issue101TestCase)) suite.addTest(unittest.makeSuite(Issue101TestCase))
suite.addTest(unittest.makeSuite(Issue129TestCase)) suite.addTest(unittest.makeSuite(Issue129TestCase))
suite.addTest(unittest.makeSuite(Issue133TestCase)) suite.addTest(unittest.makeSuite(Issue133TestCase))
suite.addTest(unittest.makeSuite(Issue139TestCase))
return suite return suite

BIN
tests/assets/issue139.aac Normal file

Binary file not shown.

BIN
tests/assets/issue139.mp3 Normal file

Binary file not shown.

49
tests/issue139.py Normal file
View File

@ -0,0 +1,49 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2019 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
import shutil
import tempfile
import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.db import Folder, Track
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner
class Issue139TestCase(unittest.TestCase):
def setUp(self):
self.__dir = tempfile.mkdtemp()
init_database('sqlite:')
with db_session:
FolderManager.add('folder', self.__dir)
def tearDown(self):
release_database()
shutil.rmtree(self.__dir)
@db_session
def do_scan(self):
scanner = Scanner()
folder = Folder.select(lambda f: f.root).first()
scanner.scan(folder)
scanner.finish()
del scanner
def test_null_genre(self):
shutil.copy('tests/assets/issue139.mp3', self.__dir)
self.do_scan()
def test_float_bitrate(self):
shutil.copy('tests/assets/issue139.aac', self.__dir)
self.do_scan()
if __name__ == '__main__':
unittest.main()