From e98c53526dfeaa082c87ecc73761db0b5ef1be60 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 19 Nov 2020 08:59:07 -0500 Subject: [PATCH] Upgrade all pages to Templates --- data/www/templates/base.html | 54 +++++++++++++++++ data/www/templates/cluster.html | 50 ++++++++++++++++ data/www/templates/diagnostics.html | 11 ++++ data/www/templates/guide.html | 32 ++++++++++ data/www/templates/index.html | 20 +++++++ data/www/templates/origin.html | 25 ++++++++ data/www/templates/streams.html | 40 +++++++++++++ data/www/templates/version.html | 20 +++++++ data/www/templates/xmltv.html | 38 ++++++++++++ fHDHR/config/__init__.py | 7 ++- fHDHR/device/cluster.py | 16 +++++ fHDHR/http/__init__.py | 4 +- fHDHR/http/api/channels.py | 1 + fHDHR/http/api/cluster.py | 1 + fHDHR/http/api/debug.py | 1 + fHDHR/http/api/epg.py | 1 + fHDHR/http/api/images.py | 1 + fHDHR/http/api/watch.py | 1 + fHDHR/http/api/xmltv.py | 2 +- fHDHR/http/pages/__init__.py | 24 +++----- fHDHR/http/pages/cluster_html.py | 78 +++++++------------------ fHDHR/http/pages/diagnostics_html.py | 26 +-------- fHDHR/http/pages/guide_html.py | 57 +++++------------- fHDHR/http/pages/htmlerror.py | 13 ----- fHDHR/http/pages/index_html.py | 50 ++++------------ fHDHR/http/pages/origin_html.py | 54 ++--------------- fHDHR/http/pages/page_elements.py | 87 ---------------------------- fHDHR/http/pages/streams_html.py | 67 ++++----------------- fHDHR/http/pages/version_html.py | 49 ++++------------ fHDHR/http/pages/xmltv_html.py | 53 ++--------------- 30 files changed, 408 insertions(+), 475 deletions(-) create mode 100644 data/www/templates/base.html create mode 100644 data/www/templates/cluster.html create mode 100644 data/www/templates/diagnostics.html create mode 100644 data/www/templates/guide.html create mode 100644 data/www/templates/index.html create mode 100644 data/www/templates/origin.html create mode 100644 data/www/templates/streams.html create mode 100644 data/www/templates/version.html create mode 100644 data/www/templates/xmltv.html delete mode 100644 fHDHR/http/pages/htmlerror.py delete mode 100644 fHDHR/http/pages/page_elements.py diff --git a/data/www/templates/base.html b/data/www/templates/base.html new file mode 100644 index 0000000..ec3dab1 --- /dev/null +++ b/data/www/templates/base.html @@ -0,0 +1,54 @@ + + + {{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} + + + + + +

+ {{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} + + fHDHR Logo +

+

+
+ + + + + + + + + + + xmltv + m3u + +
+
+ + {% set locations = fhdhr.device.cluster.get_cluster_dicts_web() %} + {% if locations %} +
+ {% for location in locations %} + + {% endfor %} +
+
+ {% endif %} + + {% set retmessage = request.args.get('retmessage', default=None) %} + {% if retmessage %} +

{{ retmessage }}

+ {% endif %} + + {% block content %}{% endblock %} + + + diff --git a/data/www/templates/cluster.html b/data/www/templates/cluster.html new file mode 100644 index 0000000..caa41ac --- /dev/null +++ b/data/www/templates/cluster.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} + +{% block content %} + +

Cluster

+ {% if not fhdhr.config.dict["fhdhr"]["discovery_address"] %} +

Discovery Address must be set for SSDP/Cluster

+ {% else %} + +
+ + +
+
+ + + + + + + + + + {% for location in locations_list %} + + + + + + + + {% endfor %} + + {% endif %} + +{% endblock %} diff --git a/data/www/templates/diagnostics.html b/data/www/templates/diagnostics.html new file mode 100644 index 0000000..ff6f38f --- /dev/null +++ b/data/www/templates/diagnostics.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block content %} + + {% for button_item in button_list %} +
+

+
+ {% endfor %} + +{% endblock %} diff --git a/data/www/templates/guide.html b/data/www/templates/guide.html new file mode 100644 index 0000000..d63cd10 --- /dev/null +++ b/data/www/templates/guide.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block content %} + +

What's On {{ fhdhr.config.dict["fhdhr"]["friendlyname"] }}

+ +
NameLocationJoinedOptions
{{ location["name"] }}{{ location["location"] }}{{ location["joined"] }} +
+ + {% if location["joined"] in ["True", "False"] %} + + {% endif %} + + {% if location["joined"] == "True" %} + + {% elif location["joined"] == "False" %} + + {% endif %} + +
+
+ + + + + + + + + + + + {% for chan_dict in chan_guide_list %} + + + + + + + + {% endfor %} + +{% endblock %} diff --git a/data/www/templates/index.html b/data/www/templates/index.html new file mode 100644 index 0000000..f5bea44 --- /dev/null +++ b/data/www/templates/index.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block content %} + +

fHDHR Status

+ +
PlayChannel NameChannel NumberChannel ThumbnailContent TitleContent ThumbnailContent DescriptionContent Remaining Time
Play + {{ chan_dict["name"] }}{{ chan_dict["number"] }}{{ chan_dict[ + {{ chan_dict["listing_title"] }}{{ chan_dict[ + {{ chan_dict["listing_description"] }}{{ chan_dict["remaining_time"] }}
+ + + + + + {% for key in list(fhdhr_status_dict.keys()) %} + + + + + {% endfor %} + +{% endblock %} diff --git a/data/www/templates/origin.html b/data/www/templates/origin.html new file mode 100644 index 0000000..1b55965 --- /dev/null +++ b/data/www/templates/origin.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block content %} + +

{{ fhdhr.config.dict["main"]["servicename"] }} Status

+ +
+ +
+
+ +
{{ key }}{{ fhdhr_status_dict[key] }}
+ + + + + + {% for key in list(origin_status_dict.keys()) %} + + + + + {% endfor %} + +{% endblock %} diff --git a/data/www/templates/streams.html b/data/www/templates/streams.html new file mode 100644 index 0000000..ff80693 --- /dev/null +++ b/data/www/templates/streams.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} + +{% block content %} + +

fHDHR Streams

+ +
{{ key }}{{ origin_status_dict[key] }}
+ + + + + + + + + + {% for tuner_dict in tuner_list %} + + + + {% if tuner_dict["status"] == "Active" %} + + + + {% else %} + + + + {% endif %} + + + {% endfor %} + +{% endblock %} diff --git a/data/www/templates/version.html b/data/www/templates/version.html new file mode 100644 index 0000000..249e35b --- /dev/null +++ b/data/www/templates/version.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block content %} + +

fHDHR Version Information

+ +
TunerStatusChannelMethodTime ActiveOptions
{{ tuner_dict["number"] }}{{ tuner_dict["status"] }}{{ tuner_dict["channel_number"] }}{{ tuner_dict["method"] }}{{ tuner_dict["play_duration"] }}N/AN/AN/A +
+ {% if tuner_dict["status"] in ["Active", "Acquired"] %} + + {% endif %} +
+
+ + + + + + {% for key in list(version_dict.keys()) %} + + + + + {% endfor %} + +{% endblock %} diff --git a/data/www/templates/xmltv.html b/data/www/templates/xmltv.html new file mode 100644 index 0000000..66a4835 --- /dev/null +++ b/data/www/templates/xmltv.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% block content %} + +

xmltv

+ +
{{ key }}{{ version_dict[key] }}
+ + + + + + + + {% for epg_method in fhdhr.config.dict["main"]["valid_epg_methods"] %} + {% if epg_method not in [None, "None"] %} + {% set epg_method_name = epg_method %} + {% if epg_method == "origin" %} + {% set epg_method_name = fhdhr.config.dict["main"]["dictpopname"] %} + {% endif %} + + + + + + + + + + {% endif %} + {% endfor %} + +{% endblock %} diff --git a/fHDHR/config/__init__.py b/fHDHR/config/__init__.py index 2e04a7a..eb1ffe6 100644 --- a/fHDHR/config/__init__.py +++ b/fHDHR/config/__init__.py @@ -28,7 +28,6 @@ class Config(): data_dir = pathlib.Path(script_dir).joinpath('data') www_dir = pathlib.Path(data_dir).joinpath('www') - www_images_dir = pathlib.Path(www_dir).joinpath('images') self.dict["filedir"] = { "script_dir": script_dir, @@ -37,7 +36,8 @@ class Config(): "cache_dir": pathlib.Path(data_dir).joinpath('cache'), "internal_config": pathlib.Path(data_dir).joinpath('internal_config'), "www_dir": www_dir, - "www_images_dir": www_images_dir, + "www_images_dir": pathlib.Path(www_dir).joinpath('images'), + "www_templates_dir": pathlib.Path(www_dir).joinpath('templates'), "font": pathlib.Path(data_dir).joinpath('garamond.ttf'), "favicon": pathlib.Path(data_dir).joinpath('favicon.ico'), "epg_cache": {}, @@ -45,7 +45,8 @@ class Config(): for conffile in os.listdir(self.dict["filedir"]["internal_config"]): conffilepath = os.path.join(self.dict["filedir"]["internal_config"], conffile) - self.read_config(conffilepath) + if str(conffilepath).endswith(".ini"): + self.read_config(conffilepath) def read_config(self, conffilepath): config_handler = configparser.ConfigParser() diff --git a/fHDHR/device/cluster.py b/fHDHR/device/cluster.py index 5f67700..4c1b824 100644 --- a/fHDHR/device/cluster.py +++ b/fHDHR/device/cluster.py @@ -22,6 +22,22 @@ class fHDHR_Cluster(): def cluster(self): return self.fhdhr.db.get_fhdhr_value("cluster", "dict") or self.default_cluster() + def get_cluster_dicts_web(self): + fhdhr_list = self.cluster() + locations = [] + for location in list(fhdhr_list.keys()): + item_dict = { + "base_url": fhdhr_list[location]["base_url"], + "name": fhdhr_list[location]["name"] + } + if item_dict["base_url"] != self.location: + locations.append(item_dict) + if len(locations): + locations = sorted(locations, key=lambda i: i['name']) + return locations + else: + return None + def get_list(self): cluster = self.fhdhr.db.get_fhdhr_value("cluster", "dict") or self.default_cluster() return_dict = {} diff --git a/fHDHR/http/__init__.py b/fHDHR/http/__init__.py index 3d81d6c..9bf1f2f 100644 --- a/fHDHR/http/__init__.py +++ b/fHDHR/http/__init__.py @@ -13,7 +13,9 @@ class fHDHR_HTTP_Server(): def __init__(self, fhdhr): self.fhdhr = fhdhr - self.app = Flask("fHDHR") + self.template_folder = fhdhr.config.dict["filedir"]["www_templates_dir"] + + self.app = Flask("fHDHR", template_folder=self.template_folder) self.pages = fHDHR_Pages(fhdhr) self.add_endpoints(self.pages, "pages") diff --git a/fHDHR/http/api/channels.py b/fHDHR/http/api/channels.py index 6e11b6d..04ebb64 100644 --- a/fHDHR/http/api/channels.py +++ b/fHDHR/http/api/channels.py @@ -5,6 +5,7 @@ import urllib.parse class Channels(): endpoints = ["/api/channels"] endpoint_name = "api_channels" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/cluster.py b/fHDHR/http/api/cluster.py index f9dad9f..a748319 100644 --- a/fHDHR/http/api/cluster.py +++ b/fHDHR/http/api/cluster.py @@ -6,6 +6,7 @@ import json class Cluster(): endpoints = ["/api/cluster"] endpoint_name = "api_cluster" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/debug.py b/fHDHR/http/api/debug.py index 53a081c..ff24cb8 100644 --- a/fHDHR/http/api/debug.py +++ b/fHDHR/http/api/debug.py @@ -5,6 +5,7 @@ import json class Debug_JSON(): endpoints = ["/api/debug"] endpoint_name = "api_debug" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/epg.py b/fHDHR/http/api/epg.py index 1f9b7fa..26a8040 100644 --- a/fHDHR/http/api/epg.py +++ b/fHDHR/http/api/epg.py @@ -7,6 +7,7 @@ class EPG(): """Methods to create xmltv.xml""" endpoints = ["/api/epg"] endpoint_name = "api_epg" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/images.py b/fHDHR/http/api/images.py index bcc1988..351ff3f 100644 --- a/fHDHR/http/api/images.py +++ b/fHDHR/http/api/images.py @@ -4,6 +4,7 @@ from flask import request, Response, abort class Images(): endpoints = ["/api/images"] endpoint_name = "api_images" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/watch.py b/fHDHR/http/api/watch.py index de47557..d036a16 100644 --- a/fHDHR/http/api/watch.py +++ b/fHDHR/http/api/watch.py @@ -8,6 +8,7 @@ class Watch(): """Methods to create xmltv.xml""" endpoints = ["/api/watch"] endpoint_name = "api_watch" + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/api/xmltv.py b/fHDHR/http/api/xmltv.py index b9672e4..3191c2e 100644 --- a/fHDHR/http/api/xmltv.py +++ b/fHDHR/http/api/xmltv.py @@ -10,7 +10,7 @@ class xmlTV(): """Methods to create xmltv.xml""" endpoints = ["/api/xmltv", "/xmltv.xml"] endpoint_name = "api_xmltv" - xmltv_xml = None + endpoint_methods = ["GET", "POST"] def __init__(self, fhdhr): self.fhdhr = fhdhr diff --git a/fHDHR/http/pages/__init__.py b/fHDHR/http/pages/__init__.py index 8e1c4b8..10d8f3a 100644 --- a/fHDHR/http/pages/__init__.py +++ b/fHDHR/http/pages/__init__.py @@ -1,7 +1,5 @@ -from .htmlerror import HTMLerror -from .page_elements import fHDHR_Page_Elements from .index_html import Index_HTML from .origin_html import Origin_HTML from .cluster_html import Cluster_HTML @@ -17,17 +15,11 @@ class fHDHR_Pages(): def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = fHDHR_Page_Elements(fhdhr) - - self.index = Index_HTML(fhdhr, self.page_elements) - - self.htmlerror = HTMLerror(fhdhr) - - self.index = Index_HTML(fhdhr, self.page_elements) - self.origin = Origin_HTML(fhdhr, self.page_elements) - self.cluster = Cluster_HTML(fhdhr, self.page_elements) - self.diagnostics = Diagnostics_HTML(fhdhr, self.page_elements) - self.version = Version_HTML(fhdhr, self.page_elements) - self.guide = Guide_HTML(fhdhr, self.page_elements) - self.streams = Streams_HTML(fhdhr, self.page_elements) - self.xmltv = xmlTV_HTML(fhdhr, self.page_elements) + self.index = Index_HTML(fhdhr) + self.origin = Origin_HTML(fhdhr) + self.cluster = Cluster_HTML(fhdhr) + self.diagnostics = Diagnostics_HTML(fhdhr) + self.version = Version_HTML(fhdhr) + self.guide = Guide_HTML(fhdhr) + self.streams = Streams_HTML(fhdhr) + self.xmltv = xmlTV_HTML(fhdhr) diff --git a/fHDHR/http/pages/cluster_html.py b/fHDHR/http/pages/cluster_html.py index 1e17782..19bd80c 100644 --- a/fHDHR/http/pages/cluster_html.py +++ b/fHDHR/http/pages/cluster_html.py @@ -1,5 +1,4 @@ -from flask import request -from io import StringIO +from flask import request, render_template import urllib.parse @@ -7,82 +6,45 @@ class Cluster_HTML(): endpoints = ["/cluster", "/cluster.html"] endpoint_name = "cluster" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements + self.location_dict = { + "name": self.fhdhr.config.dict["fhdhr"]["friendlyname"], + "location": self.fhdhr.device.cluster.location, + "joined": "N/A", + "url_query": self.fhdhr.device.cluster.location_url + } def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

Cluster

") - fakefile.write("\n") + locations_list = [] if self.fhdhr.config.dict["fhdhr"]["discovery_address"]: - fakefile.write("
\n") - fakefile.write(" \n" % ("/api/cluster?method=scan&redirect=%2Fcluster", "Force Scan")) - fakefile.write(" \n" % ("/api/cluster?method=disconnect&redirect=%2Fcluster", "Disconnect")) - fakefile.write("

\n") - - fakefile.write("
VersionXMLTV LinkEPG LinkOptions
{{ epg_method_name }}{{ epg_method_name }}{{ epg_method_name }} +
+ + +
+
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") + locations_list.append(self.location_dict) fhdhr_list = self.fhdhr.device.cluster.get_list() for location in list(fhdhr_list.keys()): - fakefile.write(" \n") if location in list(self.fhdhr.device.cluster.cluster().keys()): location_name = self.fhdhr.device.cluster.cluster()[location]["name"] else: try: location_info_url = location + "/discover.json" - locatation_info_req = self.fhdhr.web.session.get(location_info_url) - location_info = locatation_info_req.json() + location_info_req = self.fhdhr.web.session.get(location_info_url) + location_info = location_info_req.json() location_name = location_info["FriendlyName"] except self.fhdhr.web.exceptions.ConnectionError: self.fhdhr.logger.error("Unreachable: " + location) - fakefile.write(" \n" % (str(location_name))) + location_dict = { + "name": location_name, + "location": location, + "joined": str(fhdhr_list[location]["Joined"]), + "url_query": urllib.parse.quote(location) + } + locations_list.append(location_dict) - fakefile.write(" \n" % (str(location))) - - fakefile.write(" \n" % (str(fhdhr_list[location]["Joined"]))) - - fakefile.write(" \n") - - fakefile.write(" \n") - else: - fakefile.write("

Discovery Address must be set for SSDP/Cluster

\n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + return render_template('cluster.html', request=request, fhdhr=self.fhdhr, locations_list=locations_list) diff --git a/fHDHR/http/pages/diagnostics_html.py b/fHDHR/http/pages/diagnostics_html.py index 22d73dd..bdb8ce9 100644 --- a/fHDHR/http/pages/diagnostics_html.py +++ b/fHDHR/http/pages/diagnostics_html.py @@ -1,27 +1,18 @@ -from flask import request -from io import StringIO +from flask import request, render_template class Diagnostics_HTML(): endpoints = ["/diagnostics", "/diagnostics.html"] endpoint_name = "diagnostics" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.diagnostics_html = None - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - # a list of 2 part lists containing button information button_list = [ ["debug.json", "/api/debug"], @@ -33,15 +24,4 @@ class Diagnostics_HTML(): ["cluster.json", "/api/cluster?method=get"] ] - for button_item in button_list: - button_label = button_item[0] - button_path = button_item[1] - fakefile.write("
\n") - fakefile.write("

\n" % (button_path, button_label)) - fakefile.write("
\n") - fakefile.write("\n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + return render_template('diagnostics.html', request=request, fhdhr=self.fhdhr, button_list=button_list) diff --git a/fHDHR/http/pages/guide_html.py b/fHDHR/http/pages/guide_html.py index 6e02813..306b30f 100644 --- a/fHDHR/http/pages/guide_html.py +++ b/fHDHR/http/pages/guide_html.py @@ -1,5 +1,4 @@ -from flask import request -from io import StringIO +from flask import request, render_template import datetime from fHDHR.tools import humanized_time @@ -9,59 +8,33 @@ class Guide_HTML(): endpoints = ["/guide", "/guide.html"] endpoint_name = "guide" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - friendlyname = self.fhdhr.config.dict["fhdhr"]["friendlyname"] - nowtime = datetime.datetime.utcnow() - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

What's On %s

\n" % friendlyname) - fakefile.write("\n") - - fakefile.write("
NameLocationJoinedOptions
%s%s%s\n") - fakefile.write("
\n") - location_url_query = urllib.parse.quote(location) - fakefile.write( - " \n" % - (location, "Visit")) - if not fhdhr_list[location]["Joined"]: - fakefile.write( - " \n" % - ("/api/cluster?method=add&location=" + location_url_query + "&redirect=%2Fcluster", "Add")) - else: - fakefile.write( - " \n" % - ("/api/cluster?method=del&location=" + location_url_query + "&redirect=%2Fcluster", "Remove")) - fakefile.write("
\n") - fakefile.write("
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") + chan_guide_list = [] for channel in self.fhdhr.device.epg.whats_on_allchans(): end_time = datetime.datetime.strptime(channel["listing"][0]["time_end"], '%Y%m%d%H%M%S +0000') remaining_time = humanized_time(int((end_time - nowtime).total_seconds())) play_url = ("/api/m3u?method=get&channel=%s\n" % (channel["number"])) - fakefile.write(" \n") - fakefile.write(" \n" % (channel["name"])) - fakefile.write(" \n" % (channel["number"])) - fakefile.write(" \n" % (channel["listing"][0]["title"])) - fakefile.write(" \n" % (channel["listing"][0]["description"])) - fakefile.write(" \n" % (str(remaining_time))) - fakefile.write(" \n") + chan_dict = { + "play_url": play_url, + "name": channel["name"], + "number": channel["number"], + "chan_thumbnail": channel["thumbnail"], + "listing_title": channel["listing"][0]["title"], + "listing_thumbnail": channel["listing"][0]["thumbnail"], + "listing_description": channel["listing"][0]["description"], + "remaining_time": str(remaining_time) + } + chan_guide_list.append(chan_dict) - for line in page_elements["end"]: - fakefile.write(line + "\n") - - channel_guide_html = fakefile.getvalue() - - return channel_guide_html + return render_template('guide.html', request=request, fhdhr=self.fhdhr, chan_guide_list=chan_guide_list) diff --git a/fHDHR/http/pages/htmlerror.py b/fHDHR/http/pages/htmlerror.py deleted file mode 100644 index ac27a2b..0000000 --- a/fHDHR/http/pages/htmlerror.py +++ /dev/null @@ -1,13 +0,0 @@ - -class HTMLerror(): - def __init__(self, fhdhr): - self.fhdhr = fhdhr - - def get_html_error(self, message): - htmlerror = """ - - -

{}

- - """ - return htmlerror.format(message) diff --git a/fHDHR/http/pages/index_html.py b/fHDHR/http/pages/index_html.py index f55d7aa..97c7b55 100644 --- a/fHDHR/http/pages/index_html.py +++ b/fHDHR/http/pages/index_html.py @@ -1,55 +1,27 @@ -from flask import request -from io import StringIO +from flask import request, render_template class Index_HTML(): - endpoints = ["/", "/index.html"] + endpoints = ["/", "/index", "/index.html"] endpoint_name = "root" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

fHDHR Status

") - fakefile.write("\n") - - fakefile.write("
PlayChannel NameChannel NumberChannel ThumbnailContent TitleContent ThumbnailContent DescriptionContent Remaining Time
%s\n" % (play_url, "Play")) - fakefile.write(" %s%s\"%s\"\n" % (channel["thumbnail"], channel["name"])) - fakefile.write(" %s\"%s\"\n" % (channel["listing"][0]["thumbnail"], channel["listing"][0]["title"])) - fakefile.write(" %s%s
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - - total_channels = self.fhdhr.device.channels.get_station_total() - tuners_in_use = self.fhdhr.device.tuners.inuse_tuner_count() max_tuners = self.fhdhr.device.tuners.max_tuners - tableguts = [ - ["Script Directory", str(self.fhdhr.config.dict["filedir"]["script_dir"])], - ["Config File", str(self.fhdhr.config.config_file)], - ["Cache Path", str(self.fhdhr.config.dict["filedir"]["cache_dir"])], - ["Total Channels", str(total_channels)], - ["Tuner Usage", "%s/%s" % (str(tuners_in_use), str(max_tuners))] - ] + fhdhr_status_dict = { + "Script Directory": str(self.fhdhr.config.dict["filedir"]["script_dir"]), + "Config File": str(self.fhdhr.config.config_file), + "Cache Path": str(self.fhdhr.config.dict["filedir"]["cache_dir"]), + "Total Channels": str(self.fhdhr.device.channels.get_station_total()), + "Tuner Usage": ("%s/%s" % (str(tuners_in_use), str(max_tuners))), + } - for guts in tableguts: - fakefile.write(" \n") - fakefile.write(" \n" % (guts[0])) - fakefile.write(" \n" % (guts[1])) - fakefile.write(" \n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + return render_template('index.html', request=request, fhdhr=self.fhdhr, fhdhr_status_dict=fhdhr_status_dict, list=list) diff --git a/fHDHR/http/pages/origin_html.py b/fHDHR/http/pages/origin_html.py index 6ecbbd6..6a40aad 100644 --- a/fHDHR/http/pages/origin_html.py +++ b/fHDHR/http/pages/origin_html.py @@ -1,64 +1,18 @@ -from flask import request -from io import StringIO +from flask import request, render_template class Origin_HTML(): endpoints = ["/origin", "/origin.html"] endpoint_name = "origin" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - servicename = str(self.fhdhr.config.dict["main"]["servicename"]) - - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

%s Status

" % (servicename)) - fakefile.write("\n") - - # a list of 2 part lists containing button information - button_list = [ - ["Force Channel Update", "/api/channels?method=scan&redirect=%2Forigin"], - ] - - fakefile.write("
\n") - for button_item in button_list: - button_label = button_item[0] - button_path = button_item[1] - fakefile.write("

\n" % (button_path, button_label)) - fakefile.write("
\n") - fakefile.write("\n") - - fakefile.write("
%s%s
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - origin_status_dict = self.fhdhr.device.channels.get_origin_status() - for key in list(origin_status_dict.keys()): - fakefile.write(" \n") - fakefile.write(" \n" % (str(key))) - fakefile.write(" \n" % (str(origin_status_dict[key]))) - fakefile.write(" \n") - - total_channels = self.fhdhr.device.channels.get_station_total() - fakefile.write(" \n") - fakefile.write(" \n" % ("Total Channels")) - fakefile.write(" \n" % (str(total_channels))) - fakefile.write(" \n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + origin_status_dict["Total Channels"] = str(self.fhdhr.device.channels.get_station_total()) + return render_template('origin.html', request=request, fhdhr=self.fhdhr, origin_status_dict=origin_status_dict, list=list) diff --git a/fHDHR/http/pages/page_elements.py b/fHDHR/http/pages/page_elements.py deleted file mode 100644 index 923a80b..0000000 --- a/fHDHR/http/pages/page_elements.py +++ /dev/null @@ -1,87 +0,0 @@ - - -class fHDHR_Page_Elements(): - - def __init__(self, fhdhr): - self.fhdhr = fhdhr - self.location = self.fhdhr.device.cluster.location - - def get(self, request): - return {"top": self.pagetop(request), "end": self.pageend(request)} - - def pagetop(self, request): - friendlyname = self.fhdhr.config.dict["fhdhr"]["friendlyname"] - servicename = str(self.fhdhr.config.dict["main"]["servicename"]) - - upper_part = [ - "", - "", - - "", - "%s" % friendlyname, - "", - "", - "", - "", - "

", - "%s" % friendlyname, - "", - "\"%s\"\n" % ("/favicon.ico", "fHDHR Logo"), - "

" - "

", - "

" - "
", - - "" % ("/", "fHDHR"), - "" % ("/origin", servicename), - "" % ("/guide", "Guide"), - "" % ("/cluster", "Cluster"), - "" % ("/streams", "Streams"), - "" % ("/xmltv", "xmltv"), - "" % ("/version", "Version"), - "" % ("/diagnostics", "Diagnostics"), - - "%s" % ("/api/xmltv?method=get&source=" + self.fhdhr.device.epg.def_method, "xmltv"), - "%s" % ("/api/m3u?method=get&channel=all", "m3u"), - - "
", - "
" - ] - fhdhr_list = self.fhdhr.device.cluster.cluster() - locations = [] - for location in list(fhdhr_list.keys()): - item_dict = { - "base_url": fhdhr_list[location]["base_url"], - "name": fhdhr_list[location]["name"] - } - if item_dict["base_url"] != self.location: - locations.append(item_dict) - if len(locations): - upper_part.append("
") - locations = sorted(locations, key=lambda i: i['name']) - for location in locations: - upper_part.append("" % (location["base_url"], location["name"])) - upper_part.append("
") - upper_part.append("
") - - retmessage = request.args.get('retmessage', default=None, type=str) - if retmessage: - upper_part.append("

%s

" % retmessage) - - return upper_part - - def pageend(self, request): - return [ - "", - "", - - "" - ] diff --git a/fHDHR/http/pages/streams_html.py b/fHDHR/http/pages/streams_html.py index b74d211..af82885 100644 --- a/fHDHR/http/pages/streams_html.py +++ b/fHDHR/http/pages/streams_html.py @@ -1,73 +1,30 @@ -from flask import request -from io import StringIO +from flask import request, render_template class Streams_HTML(): endpoints = ["/streams", "/streams.html"] endpoint_name = "streams" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

fHDHR Streams

") - fakefile.write("\n") - - fakefile.write("
%s%s
%s%s
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - + tuner_list = [] tuner_status = self.fhdhr.device.tuners.status() for tuner in list(tuner_status.keys()): - fakefile.write(" \n") - fakefile.write(" \n" % (str(tuner))) - fakefile.write(" \n" % (str(tuner_status[tuner]["status"]))) + tuner_dict = { + "number": str(tuner), + "status": str(tuner_status[tuner]["status"]), + } if tuner_status[tuner]["status"] == "Active": - try: - channel_name = tuner_status[tuner]["epg"]["name"] - channel_number = tuner_status[tuner]["epg"]["number"] - channel_thumbnail = tuner_status[tuner]["epg"]["thumbnail"] - fakefile.write(" \n" % ( - channel_name, channel_thumbnail, channel_name, str(channel_number))) - except TypeError: - fakefile.write(" \n" % (str(tuner_status[tuner]["channel"]))) - fakefile.write(" \n" % (str(tuner_status[tuner]["method"]))) - fakefile.write(" \n" % (str(tuner_status[tuner]["Play Time"]))) - else: - fakefile.write(" \n" % "N/A") - fakefile.write(" \n" % "N/A") - fakefile.write(" \n" % "N/A") + tuner_dict["channel_number"] = tuner_status[tuner]["channel"] + tuner_dict["method"] = tuner_status[tuner]["method"] + tuner_dict["play_duration"] = str(tuner_status[tuner]["Play Time"]) - fakefile.write(" \n") - - fakefile.write(" \n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + return render_template('streams.html', request=request, fhdhr=self.fhdhr, tuner_list=tuner_list) diff --git a/fHDHR/http/pages/version_html.py b/fHDHR/http/pages/version_html.py index 3b4ee1b..e5fce4e 100644 --- a/fHDHR/http/pages/version_html.py +++ b/fHDHR/http/pages/version_html.py @@ -1,52 +1,25 @@ import sys -from flask import request -from io import StringIO +from flask import request, render_template class Version_HTML(): endpoints = ["/version", "/version.html"] endpoint_name = "version" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

fHDHR Version Information

") - fakefile.write("\n") - - fakefile.write("
TunerStatusChannelMethodTime ActiveOptions
%s%s%s\"%s\"%s%s%s%s%s%s%s\n") - fakefile.write("
\n") + tuner_list.append(tuner_dict) - if tuner_status[tuner]["status"] in ["Active", "Acquired"]: - fakefile.write( - " \n" % - ("/api/watch?method=close&tuner=" + str(tuner) + "&redirect=%2Fstreams", "Close")) - fakefile.write("
\n") - fakefile.write("
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - - table_guts = [ - ["fHDHR", self.fhdhr.version], - ["Python", sys.version], - ["Operating System", self.fhdhr.config.dict["main"]["opersystem"]], - ["Using Docker", self.fhdhr.config.dict["main"]["isdocker"]], - ["ffmpeg", self.fhdhr.config.dict["ffmpeg"]["version"]], - ["vlc", self.fhdhr.config.dict["vlc"]["version"]] - ] - - for item in table_guts: - fakefile.write(" \n") - fakefile.write(" \n" % (str(item[0]))) - fakefile.write(" \n" % (str(item[1]))) - fakefile.write(" \n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + version_dict = { + "fHDHR": self.fhdhr.version, + "Python": sys.version, + "Operating System": self.fhdhr.config.dict["main"]["opersystem"], + "Using Docker": self.fhdhr.config.dict["main"]["isdocker"], + "ffmpeg": self.fhdhr.config.dict["ffmpeg"]["version"], + "vlc": self.fhdhr.config.dict["vlc"]["version"], + } + return render_template('version.html', request=request, fhdhr=self.fhdhr, version_dict=version_dict, list=list) diff --git a/fHDHR/http/pages/xmltv_html.py b/fHDHR/http/pages/xmltv_html.py index 447356b..82747fa 100644 --- a/fHDHR/http/pages/xmltv_html.py +++ b/fHDHR/http/pages/xmltv_html.py @@ -1,61 +1,16 @@ -from flask import request -from io import StringIO +from flask import request, render_template class xmlTV_HTML(): - endpoints = ["/xmltv"] + endpoints = ["/xmltv", "/xmltv.html"] endpoint_name = "xmltv" - def __init__(self, fhdhr, page_elements): + def __init__(self, fhdhr): self.fhdhr = fhdhr - self.page_elements = page_elements def __call__(self, *args): return self.get(*args) def get(self, *args): - fakefile = StringIO() - page_elements = self.page_elements.get(request) - - for line in page_elements["top"]: - fakefile.write(line + "\n") - - fakefile.write("

fHDHR xmltv Options

") - fakefile.write("\n") - - fakefile.write("
%s%s
\n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" \n") - - for epg_method in self.fhdhr.config.dict["main"]["valid_epg_methods"]: - if epg_method not in [None, "None"]: - epg_method_name = epg_method - if epg_method == "origin": - epg_method_name = self.fhdhr.config.dict["main"]["dictpopname"] - fakefile.write(" \n") - fakefile.write(" \n" % (epg_method_name)) - fakefile.write(" \n") - - fakefile.write(" \n") - - for line in page_elements["end"]: - fakefile.write(line + "\n") - - return fakefile.getvalue() + return render_template('xmltv.html', request=request, fhdhr=self.fhdhr)
VersionXMLTV LinkEPG LinkOptions
%s%s\n" % ("/api/xmltv?method=get&source=" + epg_method, epg_method_name)) - fakefile.write(" %s\n" % ("/api/epg?method=get&source=" + epg_method, epg_method_name)) - - fakefile.write(" \n") - fakefile.write("
\n") - fakefile.write( - " \n" % - ("/api/xmltv?method=update&source=" + epg_method + "&redirect=%2Fxmltv", "Update")) - fakefile.write( - " \n" % - ("/api/xmltv?method=clearcache&source=" + epg_method + "&redirect=%2Fxmltv", "Clear Cache")) - fakefile.write("
\n") - fakefile.write("