-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8697238
Showing
86 changed files
with
12,559 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
# Created by https://www.gitignore.io/api/linux,python | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# End of https://www.gitignore.io/api/linux,python | ||
|
||
# Ignore IntelliJ | ||
.idea/ | ||
|
||
# Application specific | ||
|
||
# Local settings | ||
/settings.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from flask import Flask, request, redirect, url_for, abort, render_template | ||
import requests | ||
import yaml | ||
app = Flask(__name__) | ||
|
||
with open('settings.yaml', encoding='utf8') as file: | ||
conf = yaml.load(file) | ||
|
||
|
||
@app.route("/") | ||
def root(): | ||
# This is a work-around the fact that we cannot grab the GET parameters | ||
# since they are stuck behind the hash (#), thus being kept in the browser | ||
# and not sent to us. We solve this by running some JavaScript which is | ||
# able to grab those client-side values and redirect so they can be | ||
# processed server-side. | ||
return '''<!-- Yes, this is stupid --><script type="text/javascript"> | ||
// Credit goes to http://stackoverflow.com/a/7866932 | ||
// Gather the URL | ||
var url = window.location.href; | ||
var splitted_url = url.split("?"); | ||
var new_url = null; | ||
// Was there a question mark present? | ||
if (splitted_url.length == 2) { | ||
// Yes, redirect in a way that makes the GET parameters accessible | ||
// on the server | ||
var params = splitted_url[1]; | ||
new_url = "/play/?" + params; | ||
} else { | ||
// No, just redirect to the server with no parameters | ||
new_url = "/play/"; | ||
} | ||
// Do the actual redirect | ||
window.location = new_url; | ||
</script> | ||
<noscript>Du må aktivere Javascript for å lytte til episodene.</noscript> | ||
<p>Omdirigerer, vennligst vent…</p>''' | ||
|
||
|
||
@app.route("/play/") | ||
def play(): | ||
show_id = None | ||
episode_id = None | ||
|
||
if 'showID' in request.args: | ||
try: | ||
show_id = int(request.args['showID']) | ||
except ValueError: | ||
abort(400) | ||
return | ||
|
||
if 'broadcastID' in request.args: | ||
try: | ||
episode_id = int(request.args['broadcastID']) | ||
except ValueError: | ||
abort(400) | ||
return | ||
|
||
show_id_present = show_id is not None | ||
episode_id_present = episode_id is not None | ||
if show_id_present and episode_id_present: | ||
r = requests.get(conf['radio-rest-api'] + "/v2/lyd/ondemand/{}/{}" | ||
.format(show_id, episode_id)) | ||
r.raise_for_status() | ||
episode_data = r.json() | ||
if not "url" in episode_data: | ||
# Assuming empty response, thus these IDs are not found | ||
abort(404) | ||
return | ||
|
||
return render_template('play.html', episode=episode_data) | ||
else: | ||
abort(404) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
requests | ||
Flask | ||
PyYAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
requests==2.13.0 | ||
Flask==0.12.1 | ||
PyYAML==3.12 | ||
## The following requirements were added by pip freeze: | ||
appdirs==1.4.3 | ||
click==6.7 | ||
itsdangerous==0.24 | ||
Jinja2==2.9.6 | ||
MarkupSafe==1.0 | ||
packaging==16.8 | ||
pkg-resources==0.0.0 | ||
pyparsing==2.2.0 | ||
six==1.10.0 | ||
Werkzeug==0.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from app import app | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# The URL at which the Radio REST API is accessible. Don't include /v2. | ||
radio-rest-api: https://api.example.com |
Oops, something went wrong.