zwischenstand
This commit is contained in:
parent
9b4a5f4f1b
commit
3222c2d77f
7 changed files with 254 additions and 6 deletions
|
@ -17,6 +17,9 @@ class Station:
|
|||
def to_vtuner(self):
|
||||
return vtuner.Station(self.id, self.name, self.tag, self.url, self.icon, self.tag, None, None, None, None)
|
||||
|
||||
def to_dict(self):
|
||||
return {'name': self.name , 'url': self.url, 'icon': self.icon, 'description': self.tag }
|
||||
|
||||
|
||||
def get_station_by_id(vtune_id):
|
||||
my_stations_yaml = get_stations_yaml()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import base64
|
||||
import json
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
@ -29,6 +30,7 @@ class Station:
|
|||
self.url = generic.get_json_attr(station_json, 'url')
|
||||
|
||||
self.icon = generic.get_json_attr(station_json, 'favicon')
|
||||
self.description = generic.get_json_attr(station_json, 'tags')
|
||||
self.tags = generic.get_json_attr(station_json, 'tags').split(',')
|
||||
self.countrycode = generic.get_json_attr(station_json, 'countrycode')
|
||||
self.language = generic.get_json_attr(station_json, 'language')
|
||||
|
@ -39,8 +41,10 @@ class Station:
|
|||
|
||||
def to_vtuner(self):
|
||||
return vtuner.Station(self.id, self.name,
|
||||
', '.join(self.tags), self.url, self.icon,
|
||||
self.description, self.url, self.icon,
|
||||
self.tags[0], self.countrycode, self.codec, self.bitrate, None)
|
||||
def to_dict(self):
|
||||
return {'name': self.name , 'url': self.url, 'icon': self.icon, 'description': self.description }
|
||||
|
||||
def get_playable_url(self):
|
||||
try:
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
from flask import Flask, request, url_for, redirect, abort, make_response
|
||||
import flask
|
||||
from flask import Flask, request, url_for, redirect, abort, make_response, render_template
|
||||
|
||||
import ycast.vtuner as vtuner
|
||||
import ycast.radiobrowser as radiobrowser
|
||||
|
@ -135,9 +136,45 @@ def upstream(path):
|
|||
abort(404)
|
||||
|
||||
|
||||
@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('countrycode'):
|
||||
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())
|
||||
|
||||
return flask.jsonify(stations_dict)
|
||||
|
||||
if path.endswith('bookmarks'):
|
||||
category = request.args.get('category')
|
||||
stations = my_stations.get_stations_by_category(category)
|
||||
return flask.jsonify({'stations': stations})
|
||||
return abort(400,'Not implemented: ' + path)
|
||||
|
||||
|
||||
@app.route('/',
|
||||
defaults={'path': ''},
|
||||
methods=['GET', 'POST'])
|
||||
def landing_root(path=''):
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
|
||||
@app.route('/' + PATH_ROOT + '/',
|
||||
defaults={'path': ''},
|
||||
methods=['GET', 'POST'])
|
||||
|
|
36
ycast/static/script.js
Normal file
36
ycast/static/script.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
function createItem(name, icon, description) {
|
||||
|
||||
var itemElem = document.createElement("div");
|
||||
itemElem.className = "item";
|
||||
|
||||
var itemicon = document.createElement("div");
|
||||
itemicon.className = "itemicon";
|
||||
var itemiconimg = document.createElement("img");
|
||||
itemiconimg.src = icon;
|
||||
|
||||
var itemtext = document.createElement("div");
|
||||
itemtext.className = "itemtext";
|
||||
var h4text = document.createElement("h4");
|
||||
h4text.textContent = name;
|
||||
var desc = document.createElement("p");
|
||||
desc.textContent = description;
|
||||
|
||||
itemicon.appendChild(itemiconimg);
|
||||
|
||||
itemtext.appendChild(h4text);
|
||||
itemtext.appendChild(desc);
|
||||
|
||||
itemElem.appendChild(itemicon);
|
||||
itemElem.appendChild(itemtext);
|
||||
|
||||
return itemElem;
|
||||
}
|
||||
|
||||
function stationsAddItem() {
|
||||
var listElemet = document.createElement("li");
|
||||
listElemet.className = "item";
|
||||
listElemet.appendChild(createItem(" Halle self created","http://www.klassikradio.de/_nuxt/icons/icon_64.a00w80w0000.png","classic, poppi"));
|
||||
|
||||
document.getElementById("stationList").appendChild(listElemet);
|
||||
}
|
||||
|
102
ycast/static/style.css
Normal file
102
ycast/static/style.css
Normal file
|
@ -0,0 +1,102 @@
|
|||
body {
|
||||
font-family: sans-serif;
|
||||
height: 100%;
|
||||
}
|
||||
.header {
|
||||
height = 30rem;
|
||||
width: 90%;
|
||||
background-color: blue;
|
||||
color: white;
|
||||
text-align: center;
|
||||
border: 4px #eee solid;
|
||||
min-width: 20rem;
|
||||
}
|
||||
.container {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-height: auto;
|
||||
background-color: aquamarine;
|
||||
}
|
||||
.content {
|
||||
position: relative;
|
||||
border: 2px #eee solid;
|
||||
width: 45%;
|
||||
min-width: 20rem;
|
||||
float: left;
|
||||
margin: 0rem;
|
||||
height: 20rem;
|
||||
}
|
||||
|
||||
.contentheader {
|
||||
background-color: blue;
|
||||
color: white;
|
||||
align-items: center;
|
||||
margin: 0rem;
|
||||
padding: 0.2rem;
|
||||
}
|
||||
|
||||
.contentitems {
|
||||
position: absolute;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.item {
|
||||
border: 2px #eee solid;
|
||||
margin: 0rem;
|
||||
display: flex;
|
||||
height: 2.4rem;
|
||||
align-items: center;
|
||||
|
||||
}
|
||||
.item:hover {
|
||||
background-color: beige;
|
||||
}
|
||||
|
||||
.itemicon {
|
||||
height: 2.4rem;
|
||||
width: 2.4rem;
|
||||
}
|
||||
|
||||
.itemtext {
|
||||
|
||||
}
|
||||
|
||||
ul {
|
||||
padding: 0.2rem;
|
||||
margin: 0rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: contents;
|
||||
}
|
||||
li {
|
||||
width: 95%;
|
||||
padding: 0rem;
|
||||
margin: 0rem;
|
||||
}
|
||||
h3 {
|
||||
border: 2px #eee solid;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
margin: 0rem;
|
||||
}
|
||||
|
||||
h4 {
|
||||
text-align: left;
|
||||
padding-left: 1rem;
|
||||
margin: auto
|
||||
}
|
||||
p {
|
||||
padding-left: 1.1rem;
|
||||
margin: auto;
|
||||
font-size: 0.8rem;
|
||||
|
||||
}
|
||||
img {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
56
ycast/templates/index.html
Normal file
56
ycast/templates/index.html
Normal file
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="../static/style.css">
|
||||
<script type="text/javascript"
|
||||
src="../static/script.js"></script> <title>YCast</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>Hallo YCast</h2>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="contentheader" onclick="stationsAddItem()">
|
||||
<h3>Stations</h3>
|
||||
</div>
|
||||
<div class="contentitems">
|
||||
<ul id="stationList">
|
||||
<li class="item">
|
||||
<div class="itemicon">
|
||||
<img src="http://www.klassikradio.de/_nuxt/icons/icon_64.a00w80w0000.png">
|
||||
</div>
|
||||
<div class="itemtext">
|
||||
<h4>Radio</h4>
|
||||
<p>ard,actuell</p>
|
||||
</div>
|
||||
</li>
|
||||
<li class="item">
|
||||
<div class="itemicon">
|
||||
<img src="http://wgbh.org//apple-touch-icon.png">
|
||||
</div>
|
||||
<div class="itemtext">
|
||||
<h4>Radio</h4>
|
||||
<p>ard,actuell</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="contentheader"><h3>Bookmarks</h3></div>
|
||||
<ul>
|
||||
<li class="item">
|
||||
<div class="itemicon">
|
||||
<img src="http://www.klassikradio.de/_nuxt/icons/icon_64.a00w80w0000.png">
|
||||
</div>
|
||||
<div class="itemtext">
|
||||
<h4>Radio</h4>
|
||||
<p>ard,actuell</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -4,9 +4,9 @@ import os
|
|||
import unittest
|
||||
from io import StringIO
|
||||
|
||||
import my_filter
|
||||
import generic
|
||||
from ycast import radiobrowser, my_recentlystation
|
||||
import flask
|
||||
|
||||
from ycast import my_filter, generic, radiobrowser, my_recentlystation
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
|
@ -78,11 +78,21 @@ class MyTestCase(unittest.TestCase):
|
|||
result = my_filter.get_limit('irgendwas',20)
|
||||
assert result == 20
|
||||
|
||||
def test_jsonable_classes(self):
|
||||
generic.init_base_dir('.ycast')
|
||||
my_filter.init_filter_file()
|
||||
stations = radiobrowser.get_stations_by_country('Germany')
|
||||
station = stations[0]
|
||||
text = station.to_vtuner()
|
||||
response = station.toJson()
|
||||
response = json.dumps(station, skipkeys= True)
|
||||
|
||||
assert response is not None
|
||||
|
||||
def test_recently_hit(self):
|
||||
|
||||
try:
|
||||
os.remove(my_recentlystation.recently_file)
|
||||
os.remove(my_recentlystation.get_recently_file())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue