Support for track uri with station slug instead of id
This commit is contained in:
@@ -23,8 +23,11 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
variant, identifier, sorting, page = self.parse_uri(uri)
|
variant, identifier, sorting, page = self.parse_uri(uri)
|
||||||
|
|
||||||
if variant == "station" or variant == "track":
|
if variant == "station" or variant == "track":
|
||||||
|
try:
|
||||||
identifier = int(identifier)
|
identifier = int(identifier)
|
||||||
radio_data = self.backend.radionet.get_station_by_id(identifier)
|
radio_data = self.backend.radionet.get_station_by_id(identifier)
|
||||||
|
except ValueError:
|
||||||
|
radio_data = self.backend.radionet.get_station_by_slug(identifier)
|
||||||
|
|
||||||
artist = Artist(name=radio_data.name)
|
artist = Artist(name=radio_data.name)
|
||||||
|
|
||||||
@@ -43,7 +46,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
album = Album(
|
album = Album(
|
||||||
artists=[artist],
|
artists=[artist],
|
||||||
name=name,
|
name=name,
|
||||||
uri="radionet:station:%s" % (identifier),
|
uri="radionet:station:%s" % (radio_data.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
track = Track(
|
track = Track(
|
||||||
@@ -52,7 +55,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
name=radio_data.name,
|
name=radio_data.name,
|
||||||
genre=radio_data.genres,
|
genre=radio_data.genres,
|
||||||
comment=radio_data.description,
|
comment=radio_data.description,
|
||||||
uri="radionet:track:%s" % (identifier),
|
uri="radionet:track:%s" % (radio_data.id),
|
||||||
)
|
)
|
||||||
return [track]
|
return [track]
|
||||||
|
|
||||||
@@ -277,4 +280,14 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
category = result[0][0]
|
category = result[0][0]
|
||||||
page = result[0][2]
|
page = result[0][2]
|
||||||
|
|
||||||
|
else:
|
||||||
|
result = re.findall(
|
||||||
|
r"^radionet:(track):([^:]+)$",
|
||||||
|
uri,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
category = result[0][0]
|
||||||
|
page = result[0][1]
|
||||||
|
|
||||||
return category, page, value, sorting
|
return category, page, value, sorting
|
||||||
|
|||||||
@@ -162,8 +162,15 @@ def test_search(library):
|
|||||||
|
|
||||||
def test_lookup(library):
|
def test_lookup(library):
|
||||||
|
|
||||||
results = library.browse('radionet:favorites');
|
results = library.browse('radionet:favorites')
|
||||||
assert 1 == len(results)
|
assert 1 == len(results)
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
assert library.lookup(result.uri) is not None
|
assert library.lookup(result.uri) is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_track_by_slug(library):
|
||||||
|
|
||||||
|
results = library.lookup('radionet:track:dancefm')
|
||||||
|
assert 1 == len(results)
|
||||||
|
assert results[0].uri == 'radionet:track:2180'
|
||||||
|
|||||||
Reference in New Issue
Block a user