From 314002237da2e7d1734a6c18ce32349e574a3e53 Mon Sep 17 00:00:00 2001 From: hhm Date: Fri, 17 Mar 2017 02:21:27 -0400 Subject: [PATCH 1/2] B"H urlencode subsonic api urls --- mopidy_subidy/subsonic_api.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index 3aaa7f2..ec9ef06 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -1,4 +1,5 @@ from urlparse import urlparse +from urllib import urlencode import libsonic import logging import itertools @@ -57,13 +58,21 @@ class SubsonicApi(): logger.error('Unabled to reach subsonic server: %s' % e) exit() + def get_subsonic_uri(self, view_name, params, censor=False): + di_params = {} + di_params.update(params) + di_params.update(c='mopidy', v=self.connection.apiVersion) + if censor: + params.update(u='*****', p='*****') + else: + params.update(u=self.username, p=self.password) + return '{}/{}.view?{}'.format(self.url, view_name, urlencode(params)) + def get_song_stream_uri(self, song_id): - template = '%s/stream.view?id=%s&u=%s&p=%s&c=mopidy&v=1.14' - return template % (self.url, song_id, self.username, self.password) + return self.get_subsonic_uri('stream', dict(id=song_id)) def get_censored_song_stream_uri(self, song_id): - template = '%s/stream.view?id=%s&u=******&p=******&c=mopidy&v=1.14' - return template % (self.url, song_id) + return self.get_subsonic_uri('stream', dict(id=song_id), True) def find_raw(self, query, exclude_artists=False, exclude_albums=False, exclude_songs=False): try: From e004816794939158a849ddd38cadfb3f803774dd Mon Sep 17 00:00:00 2001 From: hhm Date: Sat, 18 Mar 2017 23:51:18 -0400 Subject: [PATCH 2/2] B"H split subsonic uri params to make clearer --- mopidy_subidy/subsonic_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index ec9ef06..c9f1a46 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -61,7 +61,8 @@ class SubsonicApi(): def get_subsonic_uri(self, view_name, params, censor=False): di_params = {} di_params.update(params) - di_params.update(c='mopidy', v=self.connection.apiVersion) + di_params.update(c='mopidy') + di_params.update(v=self.connection.apiVersion) if censor: params.update(u='*****', p='*****') else: