This commit is contained in:
deathbybandaid 2021-01-22 15:43:24 -05:00
parent bbb7fae542
commit 28f4ef205b
19 changed files with 128 additions and 80 deletions

View File

@ -15,11 +15,6 @@
"config_file": true,
"config_web": true
},
"valid_epg_methods":{
"value": "None,blocks",
"config_file": false,
"config_web": false
},
"reverse_days": {
"value": -1,
"config_file": true,

View File

@ -26,12 +26,12 @@ class fHDHR_INT_OBJ():
class fHDHR_OBJ():
def __init__(self, settings, logger, db, origin, alternative_epg):
def __init__(self, settings, logger, db, plugins):
self.fhdhr = fHDHR_INT_OBJ(settings, logger, db)
self.originwrapper = OriginServiceWrapper(self.fhdhr, origin)
self.originwrapper = OriginServiceWrapper(self.fhdhr, plugins.origin)
self.device = fHDHR_Device(self.fhdhr, self.originwrapper, alternative_epg)
self.device = fHDHR_Device(self.fhdhr, self.originwrapper, plugins)
def __getattr__(self, name):
''' will only get called for undefined attributes '''

View File

@ -25,15 +25,15 @@ def build_args_parser():
return parser.parse_args()
def get_configuration(args, script_dir, origin, fHDHR_web):
def get_configuration(args, script_dir, plugins, fHDHR_web):
if not os.path.isfile(args.cfg):
raise fHDHR.exceptions.ConfigurationNotFound(filename=args.cfg)
return fHDHR.config.Config(args.cfg, script_dir, origin, fHDHR_web)
return fHDHR.config.Config(args.cfg, script_dir, plugins, fHDHR_web)
def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
def run(settings, logger, db, script_dir, fHDHR_web, plugins):
fhdhr = fHDHR_OBJ(settings, logger, db, origin, alternative_epg)
fhdhr = fHDHR_OBJ(settings, logger, db, plugins)
fhdhrweb = fHDHR_web.fHDHR_HTTP_Server(fhdhr)
try:
@ -64,11 +64,11 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
return ERR_CODE
def start(args, script_dir, fHDHR_web, origin, alternative_epg):
def start(args, script_dir, fHDHR_web, plugins):
"""Get Configuration for fHDHR and start"""
try:
settings = get_configuration(args, script_dir, origin, fHDHR_web)
settings = get_configuration(args, script_dir, plugins, fHDHR_web)
except fHDHR.exceptions.ConfigurationError as e:
print(e)
return ERR_CODE_NO_RESTART
@ -77,20 +77,19 @@ def start(args, script_dir, fHDHR_web, origin, alternative_epg):
db = fHDHRdb(settings)
return run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg)
return run(settings, logger, db, script_dir, fHDHR_web, plugins)
def main(script_dir, fHDHR_web, origin, alternative_epg):
def main(script_dir, fHDHR_web, plugins):
"""fHDHR run script entry point"""
print("Loading fHDHR %s" % fHDHR_VERSION)
print("Loading fHDHR_web %s" % fHDHR_web.fHDHR_web_VERSION)
print("Loading Origin Service: %s %s" % (origin.ORIGIN_NAME, origin.ORIGIN_VERSION))
try:
args = build_args_parser()
while True:
returned_code = start(args, script_dir, fHDHR_web, origin, alternative_epg)
returned_code = start(args, script_dir, fHDHR_web, plugins)
if returned_code not in ["restart"]:
return returned_code
except KeyboardInterrupt:

View File

@ -14,8 +14,8 @@ from fHDHR.tools import isint, isfloat, is_arithmetic, is_docker
class Config():
def __init__(self, filename, script_dir, origin, fHDHR_web):
self.origin = origin
def __init__(self, filename, script_dir, plugins, fHDHR_web):
self.plugins = plugins
self.fHDHR_web = fHDHR_web
self.internal = {}
@ -31,12 +31,11 @@ class Config():
data_dir = pathlib.Path(script_dir).joinpath('data')
fHDHR_web_dir = pathlib.Path(script_dir).joinpath('fHDHR_web')
www_dir = pathlib.Path(fHDHR_web_dir).joinpath('www_dir')
origin_dir = pathlib.Path(script_dir).joinpath('origin')
origin_dir = [self.plugins.plugin_dict[x]["PATH"] for x in list(self.plugins.plugin_dict.keys()) if self.plugins.plugin_dict[x]["TYPE"] == "origin"][0]
self.internal["paths"] = {
"script_dir": script_dir,
"data_dir": data_dir,
"alternative_epg": pathlib.Path(script_dir).joinpath('alternative_epg'),
"origin": origin_dir,
"origin_web": pathlib.Path(origin_dir).joinpath('origin_web'),
"cache_dir": pathlib.Path(data_dir).joinpath('cache'),
@ -57,18 +56,25 @@ class Config():
if str(file_item_path).endswith("_conf.json"):
self.read_json_config(file_item_path)
for dir_type in ["alternative_epg", "origin"]:
for dir_type in ["alt_epg", "origin"]:
for file_item in os.listdir(self.internal["paths"][dir_type]):
file_item_path = pathlib.Path(self.internal["paths"][dir_type]).joinpath(file_item)
if file_item_path.is_dir():
for sub_file_item in os.listdir(file_item_path):
sub_file_item_path = pathlib.Path(file_item_path).joinpath(sub_file_item)
if str(sub_file_item_path).endswith("_conf.json"):
self.read_json_config(sub_file_item_path)
else:
if str(file_item_path).endswith("_conf.json"):
self.read_json_config(file_item_path)
if dir_type == "origin":
dir_tops = [self.internal["paths"]["origin"]]
elif dir_type == "alt_epg":
dir_tops = [self.plugins.plugin_dict[x]["PATH"] for x in list(self.plugins.plugin_dict.keys()) if self.plugins.plugin_dict[x]["TYPE"] == "alt_epg"]
for top_dir in dir_tops:
for file_item in os.listdir(top_dir):
file_item_path = pathlib.Path(top_dir).joinpath(file_item)
if file_item_path.is_dir():
for sub_file_item in os.listdir(file_item_path):
sub_file_item_path = pathlib.Path(file_item_path).joinpath(sub_file_item)
if str(sub_file_item_path).endswith("_conf.json"):
self.read_json_config(sub_file_item_path)
else:
if str(file_item_path).endswith("_conf.json"):
self.read_json_config(file_item_path)
print("Loading Configuration File: %s" % self.config_file)
self.read_ini_config(self.config_file)
@ -83,7 +89,8 @@ class Config():
self.internal["versions"]["fHDHR_web"] = self.fHDHR_web.fHDHR_web_VERSION
self.internal["versions"][self.origin.ORIGIN_NAME] = self.origin.ORIGIN_VERSION
for plugin_item in list(self.plugins.plugin_dict.keys()):
self.internal["versions"][plugin_item] = self.plugins.plugin_dict[plugin_item]["VERSION"]
self.internal["versions"]["Python"] = sys.version
@ -275,8 +282,8 @@ class Config():
self.dict["origin"] = self.dict.pop(self.dict["main"]["dictpopname"])
if isinstance(self.dict["epg"]["valid_epg_methods"], str):
self.dict["epg"]["valid_epg_methods"] = [self.dict["epg"]["valid_epg_methods"]]
self.dict["epg"]["valid_epg_methods"] = [self.plugins.plugin_dict[x]["NAME"] for x in list(self.plugins.plugin_dict.keys()) if self.plugins.plugin_dict[x]["TYPE"] == "alt_epg"]
self.dict["epg"]["valid_epg_methods"].extend(["origin", "blocks", None])
if self.dict["epg"]["method"] and self.dict["epg"]["method"] not in ["None"]:
if isinstance(self.dict["epg"]["method"], str):

View File

@ -8,11 +8,11 @@ from .cluster import fHDHR_Cluster
class fHDHR_Device():
def __init__(self, fhdhr, originwrapper, alternative_epg):
def __init__(self, fhdhr, originwrapper, plugins):
self.channels = Channels(fhdhr, originwrapper)
self.epg = EPG(fhdhr, self.channels, originwrapper, alternative_epg)
self.epg = EPG(fhdhr, self.channels, originwrapper, plugins)
self.tuners = Tuners(fhdhr, self.epg, self.channels)

View File

@ -1,4 +1,3 @@
import os
import time
import datetime
import threading
@ -10,12 +9,12 @@ from .blocks import blocksEPG
class EPG():
def __init__(self, fhdhr, channels, originwrapper, alternative_epg):
def __init__(self, fhdhr, channels, originwrapper, plugins):
self.fhdhr = fhdhr
self.origin = originwrapper
self.channels = channels
self.alternative_epg = alternative_epg
self.plugins = plugins
self.epgdict = {}
@ -154,18 +153,9 @@ class EPG():
return next(item for item in event_list if item["id"] == event_id) or None
def epg_method_selfadd(self):
self.fhdhr.logger.info("Checking for Alternative EPG methods.")
new_epgtype_list = []
for entry in os.scandir(self.fhdhr.config.internal["paths"]["alternative_epg"]):
if entry.is_file():
if entry.name[0] != '_' and entry.name.endswith(".py"):
new_epgtype_list.append(str(entry.name[:-3]))
elif entry.is_dir():
if entry.name[0] != '_':
new_epgtype_list.append(str(entry.name))
new_epgtype_list = [self.plugins.plugin_dict[x]["NAME"] for x in list(self.plugins.plugin_dict.keys()) if self.plugins.plugin_dict[x]["TYPE"] == "alt_epg"]
for method in new_epgtype_list:
self.fhdhr.logger.info("Found %s EPG method." % method)
self.epg_handling[method] = eval("self.alternative_epg.%s.%sEPG(self.fhdhr, self.channels)" % (method, method))
self.epg_handling[method] = eval("self.plugins.%sEPG(self.fhdhr, self.channels)" % method)
def update(self, method=None):

View File

@ -17,19 +17,25 @@ class OriginServiceWrapper():
def setup(self):
try:
self.originservice = self.origin.OriginService(self.fhdhr)
self.setup_success = True
self.fhdhr.logger.info("%s Setup Success" % self.servicename)
except fHDHR.exceptions.OriginSetupError as e:
self.originservice = None
self.fhdhr.logger.error(e)
self.setup_success = False
if self.origin:
if self.setup_success:
self.channels = self.origin.OriginChannels(self.fhdhr, self.originservice)
self.epg = self.origin.OriginEPG(self.fhdhr)
try:
self.originservice = self.origin.OriginService(self.fhdhr)
self.setup_success = True
self.fhdhr.logger.info("%s Setup Success" % self.servicename)
except fHDHR.exceptions.OriginSetupError as e:
self.originservice = None
self.fhdhr.logger.error(e)
self.setup_success = False
if self.setup_success:
self.channels = self.origin.OriginChannels(self.fhdhr, self.originservice)
self.epg = self.origin.OriginEPG(self.fhdhr)
else:
self.channels = OriginChannels_StandIN()
self.epg = OriginEPG_StandIN()
else:
self.originservice = None
self.channels = OriginChannels_StandIN()
self.epg = OriginEPG_StandIN()

17
main.py
View File

@ -8,21 +8,10 @@ import sys
import pathlib
from fHDHR.cli import run
import alternative_epg
try:
import fHDHR_web
except ModuleNotFoundError:
print("Error: fHDHR_web Not Found.")
sys.exit(1)
try:
import origin
except ModuleNotFoundError:
print("Error: Origin Not Found.")
sys.exit(1)
import fHDHR_web
import plugins
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
if __name__ == '__main__':
sys.exit(run.main(SCRIPT_DIR, fHDHR_web, origin, alternative_epg))
sys.exit(run.main(SCRIPT_DIR, fHDHR_web, plugins))

62
plugins/__init__.py Normal file
View File

@ -0,0 +1,62 @@
import os
import sys
import pathlib
plugins_top_dir = os.path.dirname(__file__)
print("Importing Plugins Prior to Script Run.")
plugin_dict = {}
for entry in os.scandir(plugins_top_dir):
if entry.is_dir() and not entry.is_file() and entry.name[0] != '_':
curr_dict = {}
plugin_use = True
# Import
imp_string = "from .%s import *" % entry.name
exec(imp_string)
for plugin_item in ["NAME", "VERSION", "TYPE"]:
plugin_item_eval_string = "%s.PLUGIN_%s" % (entry.name, plugin_item)
try:
curr_dict[plugin_item] = eval(plugin_item_eval_string)
except AttributeError:
curr_dict[plugin_item] = None
if curr_dict["TYPE"] == "origin":
curr_dict["PATH"] = pathlib.Path(os.path.dirname(os.path.abspath(__file__))).joinpath(entry.name).joinpath('origin')
elif curr_dict["TYPE"] == "alt_epg":
curr_dict["PATH"] = pathlib.Path(os.path.dirname(os.path.abspath(__file__))).joinpath(entry.name)
plugin_import_print_string = "Found %s type plugin: %s %s. " % (curr_dict["TYPE"], curr_dict["NAME"], curr_dict["VERSION"])
if not any(curr_dict[plugin_item] for plugin_item in ["NAME", "VERSION", "TYPE"]):
plugin_import_print_string += " ImportWarning: Missing PLUGIN_* Value."
plugin_use = False
elif curr_dict["TYPE"] not in ["origin", "alt_epg"]:
plugin_use = False
plugin_import_print_string += " ImportWarning: Invalid PLUGIN_TYPE."
# Only allow a single origin
elif curr_dict["TYPE"] == "origin" and len([x for x in list(plugin_dict.keys()) if plugin_dict[x]["TYPE"] == "origin"]):
plugin_use = False
plugin_import_print_string += " ImportWarning: Only one Origin Allowed."
if plugin_use:
plugin_import_print_string += " Import Success"
# add to plugin_dict
print(plugin_import_print_string)
if plugin_use and entry.name not in plugin_dict:
plugin_dict[entry.name] = curr_dict
# Import Origin
if curr_dict["TYPE"] == "origin":
imp_string = "from .%s import origin" % entry.name
exec(imp_string)
if curr_dict["TYPE"] == "alt_epg":
imp_string = "from .%s import %sEPG" % (entry.name, curr_dict["NAME"])
exec(imp_string)
if not len([x for x in list(plugin_dict.keys()) if plugin_dict[x]["TYPE"] == "origin"]):
print("No Origin Plugin found.")
sys.exit(1)

View File

@ -0,0 +1,3 @@
PLUGIN_NAME = "LocalNow"
PLUGIN_VERSION = "v0.6.0-beta"
PLUGIN_TYPE = "origin"

View File

@ -3,6 +3,3 @@ from .origin_service import *
from .origin_channels import *
from .origin_epg import *
from .origin_web import *
ORIGIN_NAME = "fHDHR_Locast"
ORIGIN_VERSION = "v0.5.0-beta"