mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 10:16:58 -05:00
Move Origin Web Page and Create API framework
This commit is contained in:
parent
8b870430ad
commit
e00cec1ed6
@ -32,12 +32,14 @@ class Config():
|
|||||||
data_dir = pathlib.Path(script_dir).joinpath('data')
|
data_dir = pathlib.Path(script_dir).joinpath('data')
|
||||||
fHDHR_web_dir = pathlib.Path(script_dir).joinpath('fHDHR_web')
|
fHDHR_web_dir = pathlib.Path(script_dir).joinpath('fHDHR_web')
|
||||||
www_dir = pathlib.Path(fHDHR_web_dir).joinpath('www_dir')
|
www_dir = pathlib.Path(fHDHR_web_dir).joinpath('www_dir')
|
||||||
|
origin_dir = pathlib.Path(script_dir).joinpath('origin')
|
||||||
|
|
||||||
self.internal["paths"] = {
|
self.internal["paths"] = {
|
||||||
"script_dir": script_dir,
|
"script_dir": script_dir,
|
||||||
"data_dir": data_dir,
|
"data_dir": data_dir,
|
||||||
"alternative_epg": pathlib.Path(script_dir).joinpath('alternative_epg'),
|
"alternative_epg": pathlib.Path(script_dir).joinpath('alternative_epg'),
|
||||||
"origin": pathlib.Path(script_dir).joinpath('origin'),
|
"origin": origin_dir,
|
||||||
|
"origin_web": pathlib.Path(origin_dir).joinpath('origin_web'),
|
||||||
"cache_dir": pathlib.Path(data_dir).joinpath('cache'),
|
"cache_dir": pathlib.Path(data_dir).joinpath('cache'),
|
||||||
"internal_config": pathlib.Path(data_dir).joinpath('internal_config'),
|
"internal_config": pathlib.Path(data_dir).joinpath('internal_config'),
|
||||||
"www_dir": www_dir,
|
"www_dir": www_dir,
|
||||||
|
|||||||
@ -67,7 +67,7 @@ class fHDHR_Cluster():
|
|||||||
self.fhdhr.logger.info("Found %s clustered services." % str(len(list(cluster.keys()))))
|
self.fhdhr.logger.info("Found %s clustered services." % str(len(list(cluster.keys()))))
|
||||||
for location in list(cluster.keys()):
|
for location in list(cluster.keys()):
|
||||||
if location != self.fhdhr.api.base:
|
if location != self.fhdhr.api.base:
|
||||||
self.fhdhr.logger.info("Checking Cluster Syncronization information from %s." % location)
|
self.fhdhr.logger.debug("Checking Cluster Syncronization information from %s." % location)
|
||||||
sync_url = location + "/api/cluster?method=get"
|
sync_url = location + "/api/cluster?method=get"
|
||||||
try:
|
try:
|
||||||
sync_open = self.fhdhr.web.session.get(sync_url)
|
sync_open = self.fhdhr.web.session.get(sync_url)
|
||||||
|
|||||||
@ -1,27 +1,9 @@
|
|||||||
|
from .origin_channels_standin import OriginChannels_StandIN
|
||||||
|
from .origin_epg_standin import OriginEPG_StandIN
|
||||||
|
|
||||||
import fHDHR.exceptions
|
import fHDHR.exceptions
|
||||||
|
|
||||||
|
|
||||||
class OriginEPG_StandIN():
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def update_epg(self, channels):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
class OriginChannels_StandIN():
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_channels(self):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_channel_stream(self, chandict):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class OriginServiceWrapper():
|
class OriginServiceWrapper():
|
||||||
|
|
||||||
def __init__(self, fhdhr, origin):
|
def __init__(self, fhdhr, origin):
|
||||||
@ -40,6 +22,7 @@ class OriginServiceWrapper():
|
|||||||
self.setup_success = True
|
self.setup_success = True
|
||||||
self.fhdhr.logger.info("%s Setup Success" % self.servicename)
|
self.fhdhr.logger.info("%s Setup Success" % self.servicename)
|
||||||
except fHDHR.exceptions.OriginSetupError as e:
|
except fHDHR.exceptions.OriginSetupError as e:
|
||||||
|
self.originservice = None
|
||||||
self.fhdhr.logger.error(e)
|
self.fhdhr.logger.error(e)
|
||||||
self.setup_success = False
|
self.setup_success = False
|
||||||
|
|
||||||
@ -59,25 +42,6 @@ class OriginServiceWrapper():
|
|||||||
def update_epg(self, channels):
|
def update_epg(self, channels):
|
||||||
return self.epg.update_epg(channels)
|
return self.epg.update_epg(channels)
|
||||||
|
|
||||||
def get_status_dict(self):
|
|
||||||
|
|
||||||
if self.setup_success:
|
|
||||||
status_dict = {
|
|
||||||
"Setup": "Success",
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
|
||||||
full_status_dict = self.origin.get_status_dict()
|
|
||||||
for status_key in list(full_status_dict.keys()):
|
|
||||||
status_dict[status_key] = full_status_dict[status_key]
|
|
||||||
return status_dict
|
|
||||||
except AttributeError:
|
|
||||||
return status_dict
|
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"Setup": "Failed",
|
|
||||||
}
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
''' will only get called for undefined attributes '''
|
''' will only get called for undefined attributes '''
|
||||||
if hasattr(self.fhdhr, name):
|
if hasattr(self.fhdhr, name):
|
||||||
|
|||||||
11
fHDHR/originwrapper/origin_channels_standin.py
Normal file
11
fHDHR/originwrapper/origin_channels_standin.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class OriginChannels_StandIN():
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_channels(self):
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_channel_stream(self, chandict):
|
||||||
|
return None
|
||||||
8
fHDHR/originwrapper/origin_epg_standin.py
Normal file
8
fHDHR/originwrapper/origin_epg_standin.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class OriginEPG_StandIN():
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def update_epg(self, channels):
|
||||||
|
return {}
|
||||||
@ -43,6 +43,10 @@ class fHDHR_HTTP_Server():
|
|||||||
self.api = fHDHR_API(fhdhr)
|
self.api = fHDHR_API(fhdhr)
|
||||||
self.add_endpoints(self.api, "api")
|
self.add_endpoints(self.api, "api")
|
||||||
|
|
||||||
|
self.fhdhr.logger.info("Loading HTTP Origin Endpoints.")
|
||||||
|
self.origin_endpoints = self.fhdhr.originwrapper.origin.origin_web.fHDHR_Origin_Web(fhdhr)
|
||||||
|
self.add_endpoints(self.origin_endpoints, "origin_endpoints")
|
||||||
|
|
||||||
self.app.before_request(self.before_request)
|
self.app.before_request(self.before_request)
|
||||||
self.app.after_request(self.after_request)
|
self.app.after_request(self.after_request)
|
||||||
self.app.before_first_request(self.before_first_request)
|
self.app.before_first_request(self.before_first_request)
|
||||||
@ -69,7 +73,7 @@ class fHDHR_HTTP_Server():
|
|||||||
endpoint_methods = eval("self." + str(index_name) + "." + str(item) + ".endpoint_methods")
|
endpoint_methods = eval("self." + str(index_name) + "." + str(item) + ".endpoint_methods")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
endpoint_methods = ['GET']
|
endpoint_methods = ['GET']
|
||||||
self.fhdhr.logger.info("Adding endpoint %s available at %s with %s methods." % (endpoint_name, ",".join(endpoints), ",".join(endpoint_methods)))
|
self.fhdhr.logger.debug("Adding endpoint %s available at %s with %s methods." % (endpoint_name, ",".join(endpoints), ",".join(endpoint_methods)))
|
||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
self.add_endpoint(endpoint=endpoint,
|
self.add_endpoint(endpoint=endpoint,
|
||||||
endpoint_name=endpoint_name,
|
endpoint_name=endpoint_name,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
from .index_html import Index_HTML
|
from .index_html import Index_HTML
|
||||||
from .origin_html import Origin_HTML
|
|
||||||
from .channels_html import Channels_HTML
|
from .channels_html import Channels_HTML
|
||||||
from .guide_html import Guide_HTML
|
from .guide_html import Guide_HTML
|
||||||
from .cluster_html import Cluster_HTML
|
from .cluster_html import Cluster_HTML
|
||||||
@ -19,7 +18,6 @@ class fHDHR_Pages():
|
|||||||
self.fhdhr = fhdhr
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
self.index_html = Index_HTML(fhdhr)
|
self.index_html = Index_HTML(fhdhr)
|
||||||
self.origin_html = Origin_HTML(fhdhr)
|
|
||||||
self.channels_html = Channels_HTML(fhdhr)
|
self.channels_html = Channels_HTML(fhdhr)
|
||||||
self.channels_editor = Channels_Editor_HTML(fhdhr)
|
self.channels_editor = Channels_Editor_HTML(fhdhr)
|
||||||
self.guide_html = Guide_HTML(fhdhr)
|
self.guide_html = Guide_HTML(fhdhr)
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
from flask import request, render_template
|
|
||||||
|
|
||||||
|
|
||||||
class Origin_HTML():
|
|
||||||
endpoints = ["/origin", "/origin.html"]
|
|
||||||
endpoint_name = "page_origin_html"
|
|
||||||
|
|
||||||
def __init__(self, fhdhr):
|
|
||||||
self.fhdhr = fhdhr
|
|
||||||
|
|
||||||
def __call__(self, *args):
|
|
||||||
return self.get(*args)
|
|
||||||
|
|
||||||
def get(self, *args):
|
|
||||||
|
|
||||||
origin_status_dict = self.fhdhr.originwrapper.get_status_dict()
|
|
||||||
origin_status_dict["Total Channels"] = len(self.fhdhr.device.channels.list)
|
|
||||||
return render_template('origin.html', request=request, fhdhr=self.fhdhr, origin_status_dict=origin_status_dict, list=list)
|
|
||||||
@ -2,6 +2,7 @@
|
|||||||
from .origin_service import *
|
from .origin_service import *
|
||||||
from .origin_channels import *
|
from .origin_channels import *
|
||||||
from .origin_epg import *
|
from .origin_epg import *
|
||||||
|
from .origin_web import *
|
||||||
|
|
||||||
ORIGIN_NAME = "fHDHR_NextPVR"
|
ORIGIN_NAME = "fHDHR_Locast"
|
||||||
ORIGIN_VERSION = "v0.5.0-beta"
|
ORIGIN_VERSION = "v0.5.0-beta"
|
||||||
|
|||||||
@ -10,6 +10,12 @@ class OriginService():
|
|||||||
def __init__(self, fhdhr):
|
def __init__(self, fhdhr):
|
||||||
self.fhdhr = fhdhr
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
|
self.nextpvr_address = ('%s%s:%s' %
|
||||||
|
("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://",
|
||||||
|
self.fhdhr.config.dict["origin"]["address"],
|
||||||
|
str(self.fhdhr.config.dict["origin"]["port"]),
|
||||||
|
))
|
||||||
|
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
@ -25,11 +31,7 @@ class OriginService():
|
|||||||
if self.fhdhr.config.dict["origin"]["sid"]:
|
if self.fhdhr.config.dict["origin"]["sid"]:
|
||||||
return self.fhdhr.config.dict["origin"]["sid"]
|
return self.fhdhr.config.dict["origin"]["sid"]
|
||||||
|
|
||||||
initiate_url = ('%s%s:%s/service?method=session.initiate&ver=1.0&device=fhdhr' %
|
initiate_url = '%s/service?method=session.initiate&ver=1.0&device=fhdhr' % self.nextpvr_address
|
||||||
("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://",
|
|
||||||
self.fhdhr.config.dict["origin"]["address"],
|
|
||||||
str(self.fhdhr.config.dict["origin"]["port"]),
|
|
||||||
))
|
|
||||||
|
|
||||||
initiate_req = self.fhdhr.web.session.get(initiate_url)
|
initiate_req = self.fhdhr.web.session.get(initiate_url)
|
||||||
initiate_dict = xmltodict.parse(initiate_req.content)
|
initiate_dict = xmltodict.parse(initiate_req.content)
|
||||||
@ -40,13 +42,8 @@ class OriginService():
|
|||||||
string = ':%s:%s' % (md5PIN, salt)
|
string = ':%s:%s' % (md5PIN, salt)
|
||||||
clientKey = hashlib.md5(string.encode('utf-8')).hexdigest()
|
clientKey = hashlib.md5(string.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
login_url = ('%s%s:%s/service?method=session.login&sid=%s&md5=%s' %
|
login_url = ('%s/service?method=session.login&sid=%s&md5=%s' %
|
||||||
("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://",
|
(self.nextpvr_address, sid, clientKey))
|
||||||
self.fhdhr.config.dict["origin"]["address"],
|
|
||||||
str(self.fhdhr.config.dict["origin"]["port"]),
|
|
||||||
sid,
|
|
||||||
clientKey
|
|
||||||
))
|
|
||||||
login_req = self.fhdhr.web.session.get(login_url)
|
login_req = self.fhdhr.web.session.get(login_url)
|
||||||
login_dict = xmltodict.parse(login_req.content)
|
login_dict = xmltodict.parse(login_req.content)
|
||||||
|
|
||||||
@ -56,15 +53,3 @@ class OriginService():
|
|||||||
loginsuccess = sid
|
loginsuccess = sid
|
||||||
|
|
||||||
return loginsuccess
|
return loginsuccess
|
||||||
|
|
||||||
def get_status_dict(self):
|
|
||||||
nextpvr_address = ('%s%s:%s' %
|
|
||||||
("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://",
|
|
||||||
self.fhdhr.config.dict["origin"]["address"],
|
|
||||||
str(self.fhdhr.config.dict["origin"]["port"]),
|
|
||||||
))
|
|
||||||
ret_status_dict = {
|
|
||||||
"Login": "Success",
|
|
||||||
"Address": nextpvr_address,
|
|
||||||
}
|
|
||||||
return ret_status_dict
|
|
||||||
|
|||||||
12
origin/origin_web/__init__.py
Normal file
12
origin/origin_web/__init__.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
from .origin_api import Origin_API
|
||||||
|
from .origin_html import Origin_HTML
|
||||||
|
|
||||||
|
|
||||||
|
class fHDHR_Origin_Web():
|
||||||
|
|
||||||
|
def __init__(self, fhdhr):
|
||||||
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
|
self.origin_api = Origin_API(fhdhr)
|
||||||
|
self.origin_html = Origin_HTML(fhdhr)
|
||||||
16
origin/origin_web/origin_api.py
Normal file
16
origin/origin_web/origin_api.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class Origin_API():
|
||||||
|
endpoints = ["/api/origin"]
|
||||||
|
endpoint_name = "api_origin"
|
||||||
|
endpoint_methods = ["GET", "POST"]
|
||||||
|
|
||||||
|
def __init__(self, fhdhr):
|
||||||
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
return self.get(*args)
|
||||||
|
|
||||||
|
def get(self, *args):
|
||||||
|
|
||||||
|
return "Success"
|
||||||
30
origin/origin_web/origin_html.py
Normal file
30
origin/origin_web/origin_html.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from flask import request, render_template_string
|
||||||
|
import pathlib
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
class Origin_HTML():
|
||||||
|
endpoints = ["/origin", "/origin.html"]
|
||||||
|
endpoint_name = "page_origin_html"
|
||||||
|
|
||||||
|
def __init__(self, fhdhr):
|
||||||
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
|
self.template_file = pathlib.Path(self.fhdhr.config.internal["paths"]["origin_web"]).joinpath('origin.html')
|
||||||
|
self.template = StringIO()
|
||||||
|
self.template.write(open(self.template_file).read())
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
return self.get(*args)
|
||||||
|
|
||||||
|
def get(self, *args):
|
||||||
|
|
||||||
|
if self.fhdhr.originwrapper.setup_success:
|
||||||
|
origin_status_dict = {
|
||||||
|
"Setup": "Success",
|
||||||
|
"Address": self.fhdhr.originwrapper.originservice.nextpvr_address,
|
||||||
|
"Total Channels": len(self.fhdhr.device.channels.list)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
origin_status_dict = {"Setup": "Failed"}
|
||||||
|
return render_template_string(self.template.getvalue(), request=request, fhdhr=self.fhdhr, origin_status_dict=origin_status_dict, list=list)
|
||||||
Loading…
Reference in New Issue
Block a user