Skip to content

Commit

Permalink
Resolve DVB-T region and epg.dat location for two different server boxes
Browse files Browse the repository at this point in the history
Previously the EPG was also taken from the box where you tried to
retrieve the DVB-T region from, but this is not always the main server
box where you should take the EPG from.

There are only on two locations one setting retrieved from a server box.
Therefore I do not lead the complete settings anymore, but parse them
and return the value when it is found. I know I parse now when DVB-T and
epg is on the same box two times the same file but it keeps the code
more compact and readable
  • Loading branch information
Littlesat committed Jul 26, 2024
1 parent 6834f1e commit 8c4a772
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions lib/python/Components/ImportChannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,23 @@ def getUrl(self, url, timeout=5):
result = {}
return result

def getTerrestrialUrl(self):
url = config.usage.remote_fallback_dvb_t.value
return url[:url.rfind(":")] if url else self.url

def getFallbackSettings(self):
result = self.getUrl("%s/api/settings" % self.getTerrestrialUrl())
def getFallbackSettingsValue(self, url, e2settingname):
result = self.getUrl("%s/api/settings" % url)
if result:
result = loads(result.decode('utf-8'))
if 'result' in result and result['result'] == True:
return {result['settings'][i][0]: result['settings'][i][1] for i in range(0, len(result['settings']))}
return {}

def getFallbackSettingsValue(self, settings, e2settingname):
# complete key lookup
if e2settingname in settings:
return settings[e2settingname]
# partial key lookup
for e2setting in settings:
if e2settingname in e2setting:
return settings[e2setting]
for key, value in result['settings']:
if key.endswith(e2settingname): #use the config key when the endp art but also the whole part matches
return value
return ""

def getTerrestrialRegion(self, settings):
def getTerrestrialUrl(self):
url = config.usage.remote_fallback_dvb_t.value
return url[:url.rfind(":")] if url else self.url

def getTerrestrialRegion(self):
descr = self.getFallbackSettingsValue(self.getTerrestrialUrl(), ".terrestrial")
description = ""
descr = self.getFallbackSettingsValue(settings, ".terrestrial")
if "Europe" in descr:
description = "fallback DVB-T/T2 Europe"
if "Australia" in descr:
Expand Down Expand Up @@ -121,10 +113,8 @@ def ImportGetFilelist(self, remote=False, *files):
return result

def threaded_function(self):
settings = self.getFallbackSettings()
self.getTerrestrialRegion(settings)
self.getTerrestrialRegion()
self.tmp_dir = tempfile.mkdtemp(prefix="ImportChannels_")

if "epg" in self.remote_fallback_import:
print("[Import Channels] Writing epg.dat file on server box")
try:
Expand All @@ -137,7 +127,7 @@ def threaded_function(self):
return
print("[Import Channels] Get EPG Location")
try:
epgdatfile = self.getFallbackSettingsValue(settings, "config.misc.epgcache_filename") or "/media/hdd/epg.dat"
epgdatfile = self.getFallbackSettingsValue(self.url, "config.misc.epgcache_filename") or "/media/hdd/epg.dat"
try:
files = [file for file in loads(self.getUrl("%s/file?dir=%s" % (self.url, os.path.dirname(epgdatfile))))["files"] if os.path.basename(file).startswith(os.path.basename(epgdatfile))]
except:
Expand Down

0 comments on commit 8c4a772

Please sign in to comment.