Compare commits
6 commits
master
...
fetch_sing
Author | SHA1 | Date | |
---|---|---|---|
|
82635eb9db | ||
|
fedca94507 | ||
|
cc8eb48a4b | ||
|
195c6fdc5b | ||
|
4f6be40da9 | ||
|
b447eccd02 |
3 changed files with 32 additions and 4 deletions
|
@ -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():
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue