-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add REST API for federation * update year to 2021 * Add GPL * remove obsolete template parameter * fix player Co-authored by bsod <[email protected]> * Update frontend/app/api.py Co-authored-by: Christoph <[email protected]> * Update frontend/app/api.py Co-authored-by: Christoph <[email protected]> * Update frontend/app/zomstream.py Co-authored-by: Christoph <[email protected]> * Update frontend/app/zomstream.py Co-authored-by: Christoph <[email protected]> * Update frontend/app/zomstream.py Co-authored-by: Christoph <[email protected]> * Update frontend/app/api.py Co-authored-by: Christoph <[email protected]> Co-authored-by: Jonas <[email protected]> Co-authored-by: Christoph <[email protected]>
- Loading branch information
1 parent
1ed1765
commit 7e16ef2
Showing
11 changed files
with
795 additions
and
56 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
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
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
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,29 @@ | ||
import flask | ||
import json | ||
|
||
from zomstream import Zomstream | ||
|
||
api_version = "0.1" | ||
api = flask.Blueprint('api', __name__) | ||
zomstream = Zomstream() | ||
|
||
def construct_response(r): | ||
# Expecting a JSON-serializable object as an argument | ||
# Returning a JSON string with the API response | ||
|
||
# Add Version String | ||
r.append({"version":api_version}) | ||
return flask.jsonify(r) | ||
|
||
|
||
@api.route("/api/stream/", methods = ['GET']) | ||
@api.route("/api/streams/", methods = ['GET']) | ||
def api_list_streams(): | ||
return construct_response(zomstream.getStreams()) | ||
|
||
|
||
@api.route("/api/stream/<app_name>/<stream_name>/", methods = ['GET']) | ||
def api_stream(app_name, stream_name): | ||
# Filter for streams with 'name' == stream_name | ||
stream = list(filter(lambda stream: stream['name'] == stream_name, zomstream.getStreams())) | ||
return construct_response(stream) |
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,11 @@ | ||
import flask | ||
import urllib | ||
import frontend | ||
import api | ||
|
||
import logging | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
web = flask.Flask(__name__) | ||
web.register_blueprint(api.api) | ||
web.register_blueprint(frontend.frontend) |
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 |
---|---|---|
@@ -1,71 +1,33 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
|
||
# imports | ||
import flask | ||
import pathlib | ||
import yaml | ||
import sys | ||
import xml.etree.ElementTree as etree | ||
import urllib | ||
import logging | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
# load configuration from config.yml file | ||
if pathlib.Path("config.yml").is_file(): | ||
stream = open('config.yml', 'r') | ||
configuration = yaml.load(stream) | ||
stream.close() | ||
else: | ||
print('missing configuration.') | ||
sys.exit(1) | ||
|
||
def getStreamNames(url): | ||
streamnames = [] | ||
# get data from the streaming server | ||
response = urllib.request.urlopen(url) | ||
content = response.read().decode('utf-8') | ||
# parse the xml / walk the tree | ||
tree = etree.fromstring(content) | ||
server = tree.find('server') | ||
applications = server.findall('application') | ||
for application in applications: | ||
appname = application.find('name') | ||
if appname.text == "live" or appname.text == "rec": | ||
streams = application.find('live').findall('stream') | ||
for stream in streams: | ||
name = stream.find('name') | ||
rate = stream.find('bw_video') | ||
if rate.text != "0": | ||
streamnames.append( [appname.text, name.text] ) | ||
|
||
return streamnames | ||
from zomstream import Zomstream | ||
|
||
streamList = [] | ||
frontend = flask.Flask(__name__) | ||
zomstream = Zomstream() | ||
|
||
frontend = flask.Blueprint('frontend', __name__) | ||
|
||
@frontend.route("/") | ||
def start(): | ||
mainTemplate = '%s/main.html.j2' % configuration['template_folder'] | ||
streamList = getStreamNames(configuration['stat_url']) | ||
mainTemplate = '%s/main.html.j2' % zomstream.configuration['template_folder'] | ||
streamList = zomstream.getStreamNames() | ||
page = flask.render_template( | ||
mainTemplate, | ||
items=streamList, | ||
configuration=configuration | ||
configuration=zomstream.configuration | ||
) | ||
return page | ||
|
||
@frontend.route("/player/<appname>/<streamname>") | ||
def show_player(appname, streamname): | ||
playerTemplate = '%s/player.html.j2' % configuration['template_folder'] | ||
playerTemplate = '%s/player.html.j2' % zomstream.configuration['template_folder'] | ||
page = flask.render_template( | ||
playerTemplate, | ||
streamname=streamname, | ||
appname=appname, | ||
hls_url='%s://%s/video/hls/%s.m3u8' % ( | ||
configuration['web_proto'], | ||
configuration['base_url'], | ||
streamname), | ||
configuration=configuration | ||
configuration=zomstream.configuration | ||
) | ||
return page |
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
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
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
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,59 @@ | ||
import pathlib | ||
import xml.etree.ElementTree as etree | ||
import sys | ||
import yaml | ||
import urllib | ||
|
||
|
||
class Stream: | ||
def __init__(self, url, name, streamType, app): | ||
self.url = url | ||
self.name = name | ||
self.streamType = streamType | ||
self.app = app | ||
|
||
|
||
class Zomstream: | ||
def __init__(self): | ||
# load configuration from config.yml file | ||
if pathlib.Path("config.yml").is_file(): | ||
stream = open('config.yml', 'r') | ||
self.configuration = yaml.load(stream) | ||
stream.close() | ||
else: | ||
print('missing configuration.') | ||
sys.exit(1) | ||
self.streamnames = [] | ||
def getStreamNames(self): | ||
self.streamnames = [] | ||
# get data from the streaming server | ||
response = urllib.request.urlopen(self.configuration['stat_url']) | ||
content = response.read().decode('utf-8') | ||
# parse the xml / walk the tree | ||
tree = etree.fromstring(content) | ||
server = tree.find('server') | ||
applications = server.findall('application') | ||
for application in applications: | ||
appname = application.find('name') | ||
if appname.text == "live" or appname.text == "rec": | ||
streams = application.find('live').findall('stream') | ||
for stream in streams: | ||
name = stream.find('name') | ||
rate = stream.find('bw_video') | ||
if rate.text != "0": | ||
self.streamnames.append( [appname.text, name.text] ) | ||
|
||
return self.streamnames | ||
|
||
|
||
def getStreams(self): | ||
streams = [] | ||
for streamName in self.getStreamNames(): | ||
stream_url = '%s://%s/flv?app=%s&stream=%s' % ( | ||
self.configuration['web_proto'], | ||
self.configuration['base_url'], | ||
streamName[0], | ||
streamName[1]) | ||
stream = Stream(url=stream_url, app=streamName[0], name=streamName[1], streamType='http_flv') | ||
streams.append(stream.__dict__) | ||
return streams |