FE save stations.yml
This commit is contained in:
parent
8f28a1ac6c
commit
221db3cc64
4 changed files with 83 additions and 40 deletions
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
|
||||
import ycast.vtuner as vtuner
|
||||
import ycast.generic as generic
|
||||
|
@ -80,3 +81,15 @@ def get_all_bookmarks_stations():
|
|||
station_icon = param_list[1]
|
||||
stations.append(Station(station_name, station_url, category, station_icon))
|
||||
return stations
|
||||
|
||||
|
||||
def putBookmarkJson(elements):
|
||||
newDict={}
|
||||
for stationJson in elements:
|
||||
logging.debug("%s ... %s",stationJson['description'], stationJson['name'])
|
||||
if stationJson['description'] not in newDict:
|
||||
newDict[stationJson['description']] = {}
|
||||
|
||||
newDict[stationJson['description']][stationJson['name']] = stationJson['url'] + "|" + stationJson['icon']
|
||||
generic.write_yaml_file(generic.get_stations_file(),newDict)
|
||||
return elements
|
||||
|
|
|
@ -139,49 +139,57 @@ def upstream(path):
|
|||
@app.route('/api/<path:path>',
|
||||
methods=['GET', 'POST'])
|
||||
def landing_api(path):
|
||||
if path.endswith('stations'):
|
||||
category = request.args.get('category')
|
||||
stations = None
|
||||
if category.endswith('recently'):
|
||||
stations = my_recentlystation.get_stations_by_recently()
|
||||
if category.endswith('voted'):
|
||||
stations = radiobrowser.get_stations_by_votes()
|
||||
if category.endswith('language'):
|
||||
language = request.args.get('language','german')
|
||||
stations = radiobrowser.get_stations_by_language(language)
|
||||
if category.endswith('country'):
|
||||
country = request.args.get('country','Germany')
|
||||
stations = radiobrowser.get_stations_by_country(country)
|
||||
if request.method == 'GET':
|
||||
if path.endswith('stations'):
|
||||
category = request.args.get('category')
|
||||
stations = None
|
||||
if category.endswith('recently'):
|
||||
stations = my_recentlystation.get_stations_by_recently()
|
||||
if category.endswith('voted'):
|
||||
stations = radiobrowser.get_stations_by_votes()
|
||||
if category.endswith('language'):
|
||||
language = request.args.get('language','german')
|
||||
stations = radiobrowser.get_stations_by_language(language)
|
||||
if category.endswith('country'):
|
||||
country = request.args.get('country','Germany')
|
||||
stations = radiobrowser.get_stations_by_country(country)
|
||||
|
||||
if stations is not None:
|
||||
stations_dict = []
|
||||
for station in stations:
|
||||
stations_dict.append(station.to_dict())
|
||||
if stations is not None:
|
||||
stations_dict = []
|
||||
for station in stations:
|
||||
stations_dict.append(station.to_dict())
|
||||
|
||||
return flask.jsonify(stations_dict)
|
||||
return flask.jsonify(stations_dict)
|
||||
|
||||
if path.endswith('bookmarks'):
|
||||
category = request.args.get('category')
|
||||
stations = my_stations.get_all_bookmarks_stations()
|
||||
if stations is not None:
|
||||
stations_dict = []
|
||||
for station in stations:
|
||||
stations_dict.append(station.to_dict())
|
||||
return flask.jsonify(stations_dict)
|
||||
if path.endswith('bookmarks'):
|
||||
category = request.args.get('category')
|
||||
stations = my_stations.get_all_bookmarks_stations()
|
||||
if stations is not None:
|
||||
stations_dict = []
|
||||
for station in stations:
|
||||
stations_dict.append(station.to_dict())
|
||||
return flask.jsonify(stations_dict)
|
||||
|
||||
if path.endswith('paramlist'):
|
||||
category = request.args.get('category')
|
||||
directories = None
|
||||
if category.endswith('language'):
|
||||
directories = radiobrowser.get_language_directories();
|
||||
if category.endswith('country'):
|
||||
directories = radiobrowser.get_country_directories();
|
||||
if directories is not None:
|
||||
directories_dict = []
|
||||
for directory in directories:
|
||||
directories_dict.append(directory.to_dict())
|
||||
return flask.jsonify(directories_dict)
|
||||
if path.endswith('paramlist'):
|
||||
category = request.args.get('category')
|
||||
directories = None
|
||||
if category.endswith('language'):
|
||||
directories = radiobrowser.get_language_directories();
|
||||
if category.endswith('country'):
|
||||
directories = radiobrowser.get_country_directories();
|
||||
if directories is not None:
|
||||
directories_dict = []
|
||||
for directory in directories:
|
||||
directories_dict.append(directory.to_dict())
|
||||
return flask.jsonify(directories_dict)
|
||||
|
||||
if request.method == 'POST':
|
||||
content_type = request.headers.get('Content-Type')
|
||||
if (content_type == 'application/json'):
|
||||
json = request.json
|
||||
return flask.jsonify(my_stations.putBookmarkJson(json))
|
||||
else:
|
||||
return abort(400,'Content-Type not supported!: ' + path)
|
||||
|
||||
return abort(400,'Not implemented: ' + path)
|
||||
|
||||
|
|
|
@ -247,7 +247,6 @@ function setBookmarkCategoryList() {
|
|||
if(!listItem.dataset.isemptyelement) {
|
||||
var category = listItem.dataset.category;
|
||||
if (!categoryList.find(function(arElem) { return (category == arElem);})) {
|
||||
console.log(category);
|
||||
categoryList.push(category);
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +254,6 @@ function setBookmarkCategoryList() {
|
|||
console.error(listItem, e)
|
||||
}
|
||||
})
|
||||
console.log(categoryList);
|
||||
if (categoryList.length >0) {
|
||||
var myOldList = document.getElementById('categorylist');
|
||||
var myList = myOldList.cloneNode(false);
|
||||
|
@ -313,3 +311,26 @@ function keyUpEvent(e, objElem) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function saveBookmarks(){
|
||||
var bookmarkJsonlist=[]
|
||||
var bookmarkList = Array.from(document.getElementById("bookmarkList").childNodes);
|
||||
bookmarkList.forEach(function (listItem) {
|
||||
if(!listItem.dataset.isemptyelement) {
|
||||
station = JSON.parse(listItem.dataset.json)
|
||||
bookmarkJsonlist.push( station )
|
||||
}
|
||||
})
|
||||
var data = JSON.stringify(bookmarkJsonlist)
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", 'api/bookmarks', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
console.log(json);
|
||||
}
|
||||
};
|
||||
xhr.send(data);
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
<div class="page">
|
||||
<div class="header">
|
||||
<h2>YCast advanced</h2>
|
||||
<button onclick="saveBookmarks()">Save</button>
|
||||
<div>
|
||||
<label for="id_category">station-source:</label>
|
||||
<select tabindex="1" id="id_category" name="category" oninput="onInputSelect(event, this)">
|
||||
|
|
Loading…
Add table
Reference in a new issue