Radiobrowser: Add support for fetching playable station URL

We now get the playable station URL directly from the Radiobrowser API.
This fixes the issue with playlists in the 'url' attribute.

Does not work if played station tracking would be disabled.
It _could_ work but we would need to create an additional API request for every single listed station, even the ones not enqueued for playing.
This would then be way slower and put extra strain on the Radiobrowser API.
This commit is contained in:
milaq 2019-08-26 20:39:36 +02:00
parent 87c7753fee
commit f2f4c7a908
2 changed files with 10 additions and 1 deletions

View file

@ -37,6 +37,13 @@ class Station:
return vtuner.Station(self.id, self.name, ', '.join(self.tags), self.url, self.icon,
self.tags[0], self.country, self.codec, self.bitrate, None)
def get_playable_url(self):
try:
playable_url_json = request('url/' + generic.get_stationid_without_prefix(self.id))[0]
self.url = playable_url_json['url']
except (IndexError, KeyError):
logging.error("Could not retrieve first playlist item for station with id '%s'", self.id)
def request(url):
logging.debug("Radiobrowser API request: %s", url)

View file

@ -97,7 +97,9 @@ def get_station_by_id(stationid):
if station_id_prefix == my_stations.ID_PREFIX:
return my_stations.get_station_by_id(generic.get_stationid_without_prefix(stationid))
elif station_id_prefix == radiobrowser.ID_PREFIX:
return radiobrowser.get_station_by_id(generic.get_stationid_without_prefix(stationid))
station = radiobrowser.get_station_by_id(generic.get_stationid_without_prefix(stationid))
station.get_playable_url()
return station
return None