Compare commits

...

6 commits

Author SHA1 Message Date
milaq
82635eb9db Return the very first station for a single 'My Stations' fetch 2019-08-22 15:38:37 +02:00
milaq
fedca94507 Also set itemcount for Radiobrowser landing 2019-08-22 15:32:31 +02:00
milaq
cc8eb48a4b remove search element 2019-08-22 15:31:16 +02:00
milaq
195c6fdc5b Single station response seems to require a whole page
That's a random shot, but worth a try.
2019-08-21 00:22:19 +02:00
milaq
4f6be40da9 Handle error if single station request fails 2019-08-19 22:07:45 +02:00
milaq
b447eccd02 Add ability to fetch single station element by id
We don't know what's the correct format for the statxml.asp query.
So let's assume the API just returns a single station element.
2019-08-19 14:04:41 +02:00
3 changed files with 32 additions and 4 deletions

View file

@ -32,7 +32,8 @@ def set_config(config):
def get_station_by_id(uid):
return None # TODO: return correct station when custom station id generation is implemented
# TODO: return correct station when custom station id generation is implemented, for now just return the very first one for testing
return get_stations_by_category(get_category_directories()[0].name)[0]
def get_stations_yaml():

View file

@ -1,10 +1,11 @@
import logging
from flask import Flask, request, url_for
from flask import Flask, request, url_for, abort
import ycast.vtuner as vtuner
import ycast.radiobrowser as radiobrowser
import ycast.my_stations as my_stations
import ycast.generic as generic
PATH_ROOT = 'ycast'
@ -80,14 +81,37 @@ def get_paged_elements(items, requestargs):
return items[offset:limit]
def get_station_by_id(stationid):
station_id_prefix = generic.get_stationid_prefix(stationid)
station = None
if station_id_prefix == my_stations.ID_PREFIX:
station = my_stations.get_station_by_id(generic.get_stationid_without_prefix(stationid))
elif station_id_prefix == radiobrowser.ID_PREFIX:
station = radiobrowser.get_station_by_id(generic.get_stationid_without_prefix(stationid))
if station:
page = vtuner.Page()
page.add(station.to_vtuner())
page.set_count(1)
return page
else:
return None
@app.route('/', defaults={'path': ''})
@app.route('/setupapp/<path:path>')
@app.route('/' + PATH_ROOT + '/', defaults={'path': ''})
def landing(path):
if request.args.get('token') == '0':
return vtuner.get_init_token()
if 'statxml.asp' in path and request.args.get('id'):
station = get_station_by_id(request.args.get('id'))
if station:
return station.to_string()
else:
logging.error("Could not get station with id '%s'", request.args.get('id'))
abort(404)
page = vtuner.Page()
page.add(vtuner.Directory('Radiobrowser', url_for('radiobrowser_landing', _external=True), 4))
page.add(vtuner.Directory('Radiobrowser', url_for('radiobrowser_landing', _external=True), 3))
if my_stations_enabled:
page.add(vtuner.Directory('My Stations', url_for('my_stations_landing', _external=True),
len(my_stations.get_category_directories())))
@ -120,7 +144,7 @@ def radiobrowser_landing():
len(radiobrowser.get_country_directories())))
page.add(vtuner.Directory('Most Popular', url_for('radiobrowser_popular', _external=True),
len(radiobrowser.get_stations_by_votes())))
page.add(vtuner.Search('Search', url_for('radiobrowser_search', _external=True, path='')))
page.set_count(3)
return page.to_string()

View file

@ -132,3 +132,6 @@ class Station:
ET.SubElement(item, 'Relia').text = '3'
ET.SubElement(item, 'Bookmark').text = self.bookmark
return item
def to_string(self):
return XML_HEADER + ET.tostring(self.to_xml()).decode('utf-8')