Don't call lookup on backends with uris they don't support
This commit is contained in:
parent
8e8d840767
commit
7674775718
@ -11,11 +11,15 @@ def add(frontend, uri):
|
||||
Adds the file ``URI`` to the playlist (directories add recursively).
|
||||
``URI`` can also be a single file.
|
||||
"""
|
||||
track = frontend.backend.library.lookup(uri)
|
||||
if track is None:
|
||||
raise MpdNoExistError(
|
||||
u'directory or file not found', command=u'add')
|
||||
frontend.backend.current_playlist.add(track)
|
||||
for handler_prefix in frontend.backend.uri_handlers:
|
||||
if uri.startswith(handler_prefix):
|
||||
track = frontend.backend.library.lookup(uri)
|
||||
if track is not None:
|
||||
frontend.backend.current_playlist.add(track)
|
||||
return
|
||||
|
||||
raise MpdNoExistError(
|
||||
u'directory or file not found', command=u'add')
|
||||
|
||||
@handle_pattern(r'^addid "(?P<uri>[^"]*)"( "(?P<songpos>\d+)")*$')
|
||||
def addid(frontend, uri, songpos=None):
|
||||
|
||||
@ -22,6 +22,12 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_add_with_uri_not_found_in_library_should_not_call_lookup(self):
|
||||
self.b.library.lookup = lambda uri: self.fail("Shouldn't run")
|
||||
result = self.h.handle_request(u'add "foo"')
|
||||
self.assertEqual(result[0],
|
||||
u'ACK [50@0] {add} directory or file not found')
|
||||
|
||||
def test_add_with_uri_not_found_in_library_should_ack(self):
|
||||
result = self.h.handle_request(u'add "dummy://foo"')
|
||||
self.assertEqual(result[0],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user