mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Fixed issues with float bitrate and empty tags
Thanks to @nextfullstorm Closes #139
This commit is contained in:
parent
e2cc51a0f0
commit
780c96c404
@ -142,7 +142,7 @@ class Scanner:
|
||||
trdict['duration'] = int(tag.info.length)
|
||||
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['last_modification'] = int(os.path.getmtime(path))
|
||||
|
||||
@ -309,7 +309,10 @@ class Scanner:
|
||||
if transform:
|
||||
value = transform(value)
|
||||
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
|
||||
|
||||
def stats(self):
|
||||
|
@ -18,6 +18,7 @@ from . import frontend
|
||||
from .issue101 import Issue101TestCase
|
||||
from .issue129 import Issue129TestCase
|
||||
from .issue133 import Issue133TestCase
|
||||
from .issue139 import Issue139TestCase
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
@ -29,6 +30,7 @@ def suite():
|
||||
suite.addTest(unittest.makeSuite(Issue101TestCase))
|
||||
suite.addTest(unittest.makeSuite(Issue129TestCase))
|
||||
suite.addTest(unittest.makeSuite(Issue133TestCase))
|
||||
suite.addTest(unittest.makeSuite(Issue139TestCase))
|
||||
|
||||
return suite
|
||||
|
||||
|
BIN
tests/assets/issue139.aac
Normal file
BIN
tests/assets/issue139.aac
Normal file
Binary file not shown.
BIN
tests/assets/issue139.mp3
Normal file
BIN
tests/assets/issue139.mp3
Normal file
Binary file not shown.
49
tests/issue139.py
Normal file
49
tests/issue139.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user