diff --git a/mopidy_funkwhale/actor.py b/mopidy_funkwhale/actor.py index 000a3fb..39afd47 100644 --- a/mopidy_funkwhale/actor.py +++ b/mopidy_funkwhale/actor.py @@ -42,4 +42,6 @@ class FunkwhalePlaybackProvider(backend.PlaybackProvider): url = track['listen_url'] if url.startswith('/'): url = self.backend.config['funkwhale']['url'] + url + if self.backend.remote.token: + url += '?jwt=' + self.backend.remote.token return url diff --git a/mopidy_funkwhale/client.py b/mopidy_funkwhale/client.py index 226ad52..9b685ac 100644 --- a/mopidy_funkwhale/client.py +++ b/mopidy_funkwhale/client.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import requests -from mopidy import httpclient +from mopidy import httpclient, exceptions from . import Extension, __version__ @@ -42,10 +42,10 @@ def login(session, username, password): try: response.raise_for_status() except requests.exceptions.HTTPError: - raise BackendError('Authentication failed for user %s' % (username,)) + raise exceptions.BackendError('Authentication failed for user %s' % (username,)) token = response.json()['token'] session.headers.update({'Authorization': 'JWT %s' % (token,)}) - + return token class APIClient(object): def __init__(self, session): @@ -82,8 +82,9 @@ class FunkwhaleClient(object): ) ) self.username = config['funkwhale']['username'] + self.token = None if config['funkwhale']['username']: - login( + self.token = login( self.http_client.session, config['funkwhale']['username'], config['funkwhale']['password']) diff --git a/tests/test_library.py b/tests/test_library.py index 2ea4555..7632b13 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -94,6 +94,7 @@ def test_convert_album_to_model(): assert result.album == mopidy_funkwhale.library.convert_to_album(payload['album']) assert result.artists == frozenset([mopidy_funkwhale.library.convert_to_artist(payload['artist'])]) + @pytest.mark.parametrize('uri, expected', [ ('funkwhale:albums:42', ('album', 42)), ('funkwhale:tracks:42', ('track', 42)),