mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 15:36:59 -05:00
Merge pull request #108 from deathbybandaid/dev
Improve Internal API System
This commit is contained in:
commit
27a8045fc1
@ -28,6 +28,34 @@ class fHDHR_API_URLs():
|
|||||||
self.discovery_address = self.config.dict["fhdhr"]["discovery_address"]
|
self.discovery_address = self.config.dict["fhdhr"]["discovery_address"]
|
||||||
self.port = self.config.dict["fhdhr"]["port"]
|
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
|
@property
|
||||||
def base(self):
|
def base(self):
|
||||||
if self.discovery_address:
|
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
|
# Perform some actions now that HTTP Server is running
|
||||||
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
|
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
fhdhr.api.client.get("/api/startup_tasks", headers=fhdhr.api.headers)
|
fhdhr.api.get("/api/startup_tasks")
|
||||||
|
|
||||||
# wait forever
|
# wait forever
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class EPG():
|
|||||||
if epg_method not in list(self.sleeptime.keys()):
|
if epg_method not in list(self.sleeptime.keys()):
|
||||||
self.sleeptime[epg_method] = self.fhdhr.config.dict["epg"]["update_frequency"]
|
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):
|
def clear_epg_cache(self, method=None):
|
||||||
|
|
||||||
@ -301,12 +301,7 @@ class EPG():
|
|||||||
elif time.time() >= (last_update_time + self.sleeptime[epg_method]):
|
elif time.time() >= (last_update_time + self.sleeptime[epg_method]):
|
||||||
updatetheepg = True
|
updatetheepg = True
|
||||||
if updatetheepg:
|
if updatetheepg:
|
||||||
try:
|
self.fhdhr.api.get("%s&source=%s" % (self.epg_update_url, epg_method), timeout=0.0000000001)
|
||||||
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))
|
|
||||||
time.sleep(1800)
|
time.sleep(1800)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -17,8 +17,8 @@ class Tuner():
|
|||||||
self.tuner_lock = threading.Lock()
|
self.tuner_lock = threading.Lock()
|
||||||
self.set_off_status()
|
self.set_off_status()
|
||||||
|
|
||||||
self.chanscan_url = "%s/api/channels?method=scan" % (self.fhdhr.api.base)
|
self.chanscan_url = "%s/api/channels?method=scan"
|
||||||
self.close_url = "%s/api/tuners?method=close&tuner=%s" % (self.fhdhr.api.base, str(self.number))
|
self.close_url = "/api/tuners?method=close&tuner=%s" % str(self.number)
|
||||||
|
|
||||||
def channel_scan(self, grabbed=False):
|
def channel_scan(self, grabbed=False):
|
||||||
if self.tuner_lock.locked() and not grabbed:
|
if self.tuner_lock.locked() and not grabbed:
|
||||||
@ -38,10 +38,10 @@ class Tuner():
|
|||||||
chanscan.start()
|
chanscan.start()
|
||||||
|
|
||||||
def runscan(self):
|
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.fhdhr.logger.info("Requested Channel Scan Complete.")
|
||||||
self.close()
|
self.close()
|
||||||
self.fhdhr.api.client.get(self.close_url)
|
self.fhdhr.api.get(self.close_url)
|
||||||
|
|
||||||
def add_downloaded_size(self, bytes_count):
|
def add_downloaded_size(self, bytes_count):
|
||||||
if "downloaded" in list(self.status.keys()):
|
if "downloaded" in list(self.status.keys()):
|
||||||
|
|||||||
@ -8,8 +8,8 @@ class Startup_Tasks():
|
|||||||
def __init__(self, fhdhr):
|
def __init__(self, fhdhr):
|
||||||
self.fhdhr = fhdhr
|
self.fhdhr = fhdhr
|
||||||
|
|
||||||
self.epg_update_url = "%s/api/epg?method=update" % (self.fhdhr.api.base)
|
self.epg_update_url = "/api/epg?method=update"
|
||||||
self.channel_update_url = "%s/api/channels?method=scan" % (self.fhdhr.api.base)
|
self.channel_update_url = "/api/channels?method=scan"
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
return self.get(*args)
|
return self.get(*args)
|
||||||
@ -25,10 +25,10 @@ class Startup_Tasks():
|
|||||||
updatechannels = True
|
updatechannels = True
|
||||||
|
|
||||||
if updatechannels:
|
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
|
# Hit EPG Update API
|
||||||
for epg_method in self.fhdhr.device.epg.epg_methods:
|
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"
|
return "Success"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user