mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 07:36:59 -05:00
Improve Internal API System
This commit is contained in:
parent
e9e0e40d78
commit
8a475f154a
@ -28,6 +28,34 @@ class fHDHR_API_URLs():
|
||||
self.discovery_address = self.config.dict["fhdhr"]["discovery_address"]
|
||||
self.port = self.config.dict["fhdhr"]["port"]
|
||||
|
||||
def get(self, url, *args):
|
||||
|
||||
req_method = type(self.client).__name__
|
||||
|
||||
if not url.startswith("http"):
|
||||
if not url.startswith("/"):
|
||||
url = "/%s" % url
|
||||
url = "%s%s" % (self.base, url)
|
||||
|
||||
if req_method == "FlaskClient":
|
||||
self.client.get(url, headers=self.headers, *args)
|
||||
else:
|
||||
self.client.get(url, headers=self.headers, *args)
|
||||
|
||||
def post(self, url, *args):
|
||||
|
||||
req_method = type(self.client).__name__
|
||||
|
||||
if not url.startswith("http"):
|
||||
if not url.startswith("/"):
|
||||
url = "/%s" % url
|
||||
url = "%s%s" % (self.base, url)
|
||||
|
||||
if req_method == "FlaskClient":
|
||||
self.client.post(url, headers=self.headers, *args)
|
||||
else:
|
||||
self.client.post(url, headers=self.headers, *args)
|
||||
|
||||
@property
|
||||
def base(self):
|
||||
if self.discovery_address:
|
||||
|
||||
@ -55,7 +55,7 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
|
||||
# Perform some actions now that HTTP Server is running
|
||||
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
|
||||
time.sleep(3)
|
||||
fhdhr.api.client.get("/api/startup_tasks", headers=fhdhr.api.headers)
|
||||
fhdhr.api.get("/api/startup_tasks")
|
||||
|
||||
# wait forever
|
||||
while True:
|
||||
|
||||
@ -37,7 +37,7 @@ class EPG():
|
||||
if epg_method not in list(self.sleeptime.keys()):
|
||||
self.sleeptime[epg_method] = self.fhdhr.config.dict["epg"]["update_frequency"]
|
||||
|
||||
self.epg_update_url = "%s/api/epg?method=update" % (self.fhdhr.api.base)
|
||||
self.epg_update_url = "/api/epg?method=update"
|
||||
|
||||
def clear_epg_cache(self, method=None):
|
||||
|
||||
@ -301,12 +301,7 @@ class EPG():
|
||||
elif time.time() >= (last_update_time + self.sleeptime[epg_method]):
|
||||
updatetheepg = True
|
||||
if updatetheepg:
|
||||
try:
|
||||
self.fhdhr.web.session.get("%s&source=%s" % (self.epg_update_url, epg_method), timeout=0.0000000001)
|
||||
except self.fhdhr.web.exceptions.ReadTimeout:
|
||||
pass
|
||||
except self.fhdhr.web.exceptions.ConnectionError as e:
|
||||
self.fhdhr.logger.error("Error updating %s EPG cache: %s" % (epg_method, e))
|
||||
self.fhdhr.api.get("%s&source=%s" % (self.epg_update_url, epg_method), timeout=0.0000000001)
|
||||
time.sleep(1800)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
@ -17,8 +17,8 @@ class Tuner():
|
||||
self.tuner_lock = threading.Lock()
|
||||
self.set_off_status()
|
||||
|
||||
self.chanscan_url = "%s/api/channels?method=scan" % (self.fhdhr.api.base)
|
||||
self.close_url = "%s/api/tuners?method=close&tuner=%s" % (self.fhdhr.api.base, str(self.number))
|
||||
self.chanscan_url = "%s/api/channels?method=scan"
|
||||
self.close_url = "/api/tuners?method=close&tuner=%s" % str(self.number)
|
||||
|
||||
def channel_scan(self, grabbed=False):
|
||||
if self.tuner_lock.locked() and not grabbed:
|
||||
@ -38,10 +38,10 @@ class Tuner():
|
||||
chanscan.start()
|
||||
|
||||
def runscan(self):
|
||||
self.fhdhr.api.client.get(self.chanscan_url)
|
||||
self.fhdhr.api.get(self.chanscan_url)
|
||||
self.fhdhr.logger.info("Requested Channel Scan Complete.")
|
||||
self.close()
|
||||
self.fhdhr.api.client.get(self.close_url)
|
||||
self.fhdhr.api.get(self.close_url)
|
||||
|
||||
def add_downloaded_size(self, bytes_count):
|
||||
if "downloaded" in list(self.status.keys()):
|
||||
|
||||
@ -8,8 +8,8 @@ class Startup_Tasks():
|
||||
def __init__(self, fhdhr):
|
||||
self.fhdhr = fhdhr
|
||||
|
||||
self.epg_update_url = "%s/api/epg?method=update" % (self.fhdhr.api.base)
|
||||
self.channel_update_url = "%s/api/channels?method=scan" % (self.fhdhr.api.base)
|
||||
self.epg_update_url = "/api/epg?method=update"
|
||||
self.channel_update_url = "/api/channels?method=scan"
|
||||
|
||||
def __call__(self, *args):
|
||||
return self.get(*args)
|
||||
@ -25,10 +25,10 @@ class Startup_Tasks():
|
||||
updatechannels = True
|
||||
|
||||
if updatechannels:
|
||||
self.fhdhr.api.client.get(self.channel_update_url, headers=self.fhdhr.api.headers)
|
||||
self.fhdhr.api.get(self.channel_update_url)
|
||||
|
||||
# Hit EPG Update API
|
||||
for epg_method in self.fhdhr.device.epg.epg_methods:
|
||||
self.fhdhr.api.client.get("%s&source=%s" % (self.epg_update_url, epg_method), headers=self.fhdhr.api.headers)
|
||||
self.fhdhr.api.get("%s&source=%s" % (self.epg_update_url, epg_method))
|
||||
|
||||
return "Success"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user