Skip to content

Commit

Permalink
Merge 55014d1 into 52c4a6f
Browse files Browse the repository at this point in the history
  • Loading branch information
kriim committed Feb 21, 2016
2 parents 52c4a6f + 55014d1 commit 47a24a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
5 changes: 1 addition & 4 deletions mopidy_soundcloud/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from mopidy import backend, models
from mopidy.models import SearchResult, Track

from mopidy_soundcloud.soundcloud import safe_url


logger = logging.getLogger(__name__)


Expand All @@ -22,7 +19,7 @@ def generate_uri(path):
def new_folder(name, path):
return models.Ref.directory(
uri=generate_uri(path),
name=safe_url(name)
name=name
)


Expand Down
12 changes: 4 additions & 8 deletions mopidy_soundcloud/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@

import requests


logger = logging.getLogger(__name__)


def safe_url(uri):
return quote_plus(
unicodedata.normalize('NFKD', unicode(uri)).encode('ASCII', 'ignore'))


def readable_url(uri):
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
safe_uri = unicodedata.normalize('NFKD', unicode(uri)).encode('ASCII',
Expand Down Expand Up @@ -110,12 +104,14 @@ def get_user_stream(self):

@cache()
def get_explore_categories(self):
return self._get('explore/categories', 'api-v2').get('music')
explore_categories = self._get('explore/categories', 'api-v2')
return explore_categories.get('music')

def get_explore(self, query_explore_id=None):
explore = self.get_explore_categories()
if query_explore_id:
url = 'explore/{urn}?limit={limit}&offset=0&linked_partitioning=1'\
url = \
'explore/{urn}?limit={limit}&offset=0&linked_partitioning=1' \
.format(
urn=explore[int(query_explore_id)],
limit=self.explore_songs
Expand Down
20 changes: 11 additions & 9 deletions tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from mopidy_soundcloud import SoundCloudExtension, actor
from mopidy_soundcloud.library import (
SoundCloudLibraryProvider, new_folder, simplify_search_query)
from mopidy_soundcloud.soundcloud import safe_url


class ApiTest(unittest.TestCase):
Expand Down Expand Up @@ -36,6 +35,17 @@ def test_add_folder(self):
uri='soundcloud:directory:test')
)

def test_add_folder_with_spaces(self):
try:
from mopidy.models import Ref
except ImportError as e:
self.skipTest(e.message)
self.assertEquals(
new_folder('This is a test folder', ['This_is_a_test_folder']),
Ref(name='This is a test folder', type='directory',
uri='soundcloud:directory:This_is_a_test_folder')
)

def test_mpc_search(self):
self.assertEquals(
simplify_search_query({u'any': [u'explosions in the sky']}),
Expand Down Expand Up @@ -69,14 +79,6 @@ def test_only_resolves_soundcloud_uris(self):
self.assertIsNone(self.library.search(
{'uri': 'http://www.youtube.com/watch?v=wD6H6Yhluo8'}))

def test_returns_url_safe_string(self):
self.assertEquals(
safe_url('Alternative/Indie/rock/pop '),
'Alternative%2FIndie%2Frock%2Fpop+')
self.assertEquals(
safe_url('D∃∃P Hau⑀ iNDiE DᴬNCE | №➊ ²⁰¹⁴'),
'DP+Hau+iNDiE+DANCE+%7C+No+2014')

def test_default_folders(self):
try:
from mopidy.models import Ref
Expand Down

0 comments on commit 47a24a6

Please sign in to comment.