From e77a4afaf46f2eff8a700d6eb73082bbb93be419 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 18 Aug 2015 23:44:38 +0200 Subject: [PATCH] audio: Make scanner report MIME for missing plugins --- docs/changelog.rst | 3 +++ mopidy/audio/scan.py | 13 ++++++------- tests/audio/test_scan.py | 11 +++++++++++ tests/data/scanner/plain.txt | 1 + tests/data/scanner/playlist.m3u | 1 + 5 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 tests/data/scanner/plain.txt create mode 100644 tests/data/scanner/playlist.m3u diff --git a/docs/changelog.rst b/docs/changelog.rst index 290806d3..c0328de5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,9 @@ Bug fix release. - Audio: Fix timeout handling in scanner. This regression caused timeouts to expire before it should, causing scans to fail. +- Audio: Update scanner to emit MIME type instead of an error when missing a + plugin. + v1.1.0 (2015-08-09) =================== diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index 13c76d52..d1081788 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -12,8 +12,6 @@ from mopidy import exceptions from mopidy.audio import utils from mopidy.internal import encoding -_missing_plugin_desc = gst.pbutils.missing_plugin_message_get_description - _Result = collections.namedtuple( 'Result', ('uri', 'tags', 'duration', 'seekable', 'mime', 'playable')) @@ -134,7 +132,7 @@ def _process(pipeline, timeout_ms): clock = pipeline.get_clock() bus = pipeline.get_bus() timeout = timeout_ms * gst.MSECOND - tags, mime, have_audio, missing_description = {}, None, False, None + tags, mime, have_audio, missing_message = {}, None, False, None types = (gst.MESSAGE_ELEMENT | gst.MESSAGE_APPLICATION | gst.MESSAGE_ERROR | gst.MESSAGE_EOS | gst.MESSAGE_ASYNC_DONE | gst.MESSAGE_TAG) @@ -147,8 +145,7 @@ def _process(pipeline, timeout_ms): break elif message.type == gst.MESSAGE_ELEMENT: if gst.pbutils.is_missing_plugin_message(message): - missing_description = encoding.locale_decode( - _missing_plugin_desc(message)) + missing_message = message elif message.type == gst.MESSAGE_APPLICATION: if message.structure.get_name() == 'have-type': mime = message.structure['caps'].get_name() @@ -158,8 +155,10 @@ def _process(pipeline, timeout_ms): have_audio = True elif message.type == gst.MESSAGE_ERROR: error = encoding.locale_decode(message.parse_error()[0]) - if missing_description: - error = '%s (%s)' % (missing_description, error) + if missing_message and not mime: + caps = missing_message.structure['detail'] + mime = caps.get_structure(0).get_name() + return tags, mime, have_audio raise exceptions.ScannerError(error) elif message.type == gst.MESSAGE_EOS: return tags, mime, have_audio diff --git a/tests/audio/test_scan.py b/tests/audio/test_scan.py index c558835e..dff753d9 100644 --- a/tests/audio/test_scan.py +++ b/tests/audio/test_scan.py @@ -109,6 +109,17 @@ class ScannerTest(unittest.TestCase): wav = path_to_data_dir('scanner/empty.wav') self.assertEqual(self.result[wav].duration, 0) + def test_uri_list(self): + path = path_to_data_dir('scanner/playlist.m3u') + self.scan([path]) + self.assertEqual(self.result[path].mime, 'text/uri-list') + + def test_text_plain(self): + # GStreamer decode bin hardcodes bad handling of text plain :/ + path = path_to_data_dir('scanner/plain.txt') + self.scan([path]) + self.assertIn(path, self.errors) + @unittest.SkipTest def test_song_without_time_is_handeled(self): pass diff --git a/tests/data/scanner/plain.txt b/tests/data/scanner/plain.txt new file mode 100644 index 00000000..3180d4a9 --- /dev/null +++ b/tests/data/scanner/plain.txt @@ -0,0 +1 @@ +Some plain text file with nothing special in it. diff --git a/tests/data/scanner/playlist.m3u b/tests/data/scanner/playlist.m3u new file mode 100644 index 00000000..df0f0142 --- /dev/null +++ b/tests/data/scanner/playlist.m3u @@ -0,0 +1 @@ +http://example.com/