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)
|
||||
|
||||
if variant == "station" or variant == "track":
|
||||
identifier = int(identifier)
|
||||
radio_data = self.backend.radionet.get_station_by_id(identifier)
|
||||
try:
|
||||
identifier = int(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)
|
||||
|
||||
@@ -43,7 +46,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
||||
album = Album(
|
||||
artists=[artist],
|
||||
name=name,
|
||||
uri="radionet:station:%s" % (identifier),
|
||||
uri="radionet:station:%s" % (radio_data.id),
|
||||
)
|
||||
|
||||
track = Track(
|
||||
@@ -52,7 +55,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
||||
name=radio_data.name,
|
||||
genre=radio_data.genres,
|
||||
comment=radio_data.description,
|
||||
uri="radionet:track:%s" % (identifier),
|
||||
uri="radionet:track:%s" % (radio_data.id),
|
||||
)
|
||||
return [track]
|
||||
|
||||
@@ -277,4 +280,14 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
||||
category = result[0][0]
|
||||
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
|
||||
|
||||
@@ -162,8 +162,15 @@ def test_search(library):
|
||||
|
||||
def test_lookup(library):
|
||||
|
||||
results = library.browse('radionet:favorites');
|
||||
results = library.browse('radionet:favorites')
|
||||
assert 1 == len(results)
|
||||
|
||||
for result in results:
|
||||
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