From 780c96c404090f237d5fc6b59ce6e51c3b7d37cc Mon Sep 17 00:00:00 2001 From: spl0k Date: Sat, 23 Mar 2019 17:08:46 +0100 Subject: [PATCH] Fixed issues with float bitrate and empty tags Thanks to @nextfullstorm Closes #139 --- supysonic/scanner.py | 7 ++++-- tests/__init__.py | 2 ++ tests/assets/issue139.aac | Bin 0 -> 2760 bytes tests/assets/issue139.mp3 | Bin 0 -> 85812 bytes tests/issue139.py | 49 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/assets/issue139.aac create mode 100644 tests/assets/issue139.mp3 create mode 100644 tests/issue139.py diff --git a/supysonic/scanner.py b/supysonic/scanner.py index 6da6d22..a4c0022 100644 --- a/supysonic/scanner.py +++ b/supysonic/scanner.py @@ -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): diff --git a/tests/__init__.py b/tests/__init__.py index d6897a2..6df5548 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 diff --git a/tests/assets/issue139.aac b/tests/assets/issue139.aac new file mode 100644 index 0000000000000000000000000000000000000000..b16037a4ac1a6313f79dc3dfc1e405ca61556df7 GIT binary patch literal 2760 zcmezWF`$9@{-1kH3_giv$)*;1CgysE2F46d3LFO|EdB#!8TbED6kti{ks0NThQVk$ c7|jc#<-ur~I9e}^R)?cag3)HtplKQc0CTatMgRZ+ literal 0 HcmV?d00001 diff --git a/tests/assets/issue139.mp3 b/tests/assets/issue139.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..71f5f7232bd3092db7cdccaa5bd795af3626c3c3 GIT binary patch literal 85812 zcmeI1J!(`@07kDUL~#KY7N)Tke-@ze2N6X@(*+9?rU)cPG7;M>!4-+ia0%`~aJ)`s z5zOfh$a#c$!+mG+G3S)??D4&eV_x@fZ$I0!lS`E86#t1i*N4D|JMW>2bOOpAlK&E}LT_7OIL<(fu2ipY#l1!vPrhTwoARx&^3S`;`+XVuW zOr$`jeXw01Ajw1uWZDPY1p<;xq(G*9uw5V^$wUfd+6UVO0+LLmK&E}LT_7OIL<(fu z2ipY#l1!vPrhTwoARx&^3S`;`+XVuWOr$`jeXw01Ajw1uWZDPY1p<;xq(G*9uw5V^ z$wUfd+6UVO0+LLmK&E}LT_7OIL<(fu2ipY#l1!vPrhTwoARx&^3S`;`+XVuWOr$`j zeXw01Ajw1uWZDPY1p<;xq(G*9uw5V^$wUfd+6UVO0+LLmK&E}LT_7OIL<(fu2ipY# zl1!vPrhTwoARx&^3S`;`+XVuWOr$`jeXw01Ajw1uWZDPY1p<;xq(G*9uw5V^$wUfd z+6UVO0+LLmK&E}LT_7OIL<(fu2ipY#l1!vPrhTwoARx&^3S`;`+XVuWOr$`jeXw01 zAjw1uWZDPY1p<;xq(G*9uw5V^$wUfd+6UVO0+LLmK&E}LT_7OIL<(fu2ipY#l1!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