Skip to content

Commit

Permalink
[TerrestrialBouquet] use eDVBDV.getLcnDBData
Browse files Browse the repository at this point in the history
  • Loading branch information
Huevos committed Aug 7, 2024
1 parent 572b037 commit 8a88c39
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions lib/python/Plugins/SystemPlugins/TerrestrialBouquet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TerrestrialBouquet:
def __init__(self):
self.config = config.plugins.terrestrialbouquet
self.path = "/etc/enigma2"
self.lcndb = self.path + "/lcndb"
self.bouquetsIndexFilename = "bouquets.tv"
self.bouquetFilename = "userbouquet.TerrestrialBouquet.tv"
self.bouquetName = _('Terrestrial')
Expand All @@ -38,33 +37,29 @@ def getTerrestrials(self, mode):
if service.getUnsignedData(4) >> 16 == 0xeeee: # filter (only terrestrial)
stype, sid, tsid, onid, ns = [int(x, 16) for x in service.toString().split(":", 7)[2:7]]
name = ServiceReference.getServiceName(service)
terrestrials["%04x:%04x:%04x" % (onid, tsid, sid)] = {"name": name, "namespace": ns, "onid": onid, "tsid": tsid, "sid": sid, "type": stype}
terrestrials["%08x:%04x:%04x:%04x" % (ns, onid, tsid, sid)] = {"name": name, "namespace": ns, "onid": onid, "tsid": tsid, "sid": sid, "type": stype}
return terrestrials

def getAllowedTypes(self, mode):
return self.VIDEO_ALLOWED_TYPES if mode == MODE_TV else self.AUDIO_ALLOWED_TYPES # tv (live and NVOD) and radio allowed service types

def readLcnDb(self):
try: # may not exist
f = open(self.lcndb)
except Exception as e: # noqa: F841
return {}
LCNs = {}
for line in f:
line = line and line.strip().lower()
if line and len(line) == 38 and line.startswith("eeee"):
lcn, signal = tuple([int(x) for x in line[24:].split(":", 1)])
key = line[9:23]
LCNs[key] = {"lcn": lcn, "signal": signal}
return {k: v for k, v in sorted(list(LCNs.items()), key=lambda x: (x[1]["lcn"], abs(x[1]["signal"] - 65535)))}
if LCNData := eDVBDB.getInstance().getLcnDBData():
for service in LCNData:
ns, onid, tsid, sid, lcn, signal = service
if ns >> 16 == 0xeeee: # filter (only terrestrial)
LCNs["%08x:%04x:%04x:%04x" % (ns, onid, tsid, sid)] = {"lcn": lcn, "signal": signal}
LCNs = {k: v for k, v in sorted(list(LCNs.items()), key=lambda x: (x[1]["lcn"], abs(x[1]["signal"] - 65535)))} if LCNs else LCNs
return LCNs

def rebuild(self):
if not self.config.enabled.value:
return _("Terrestrial Bouquet plugin is not enabled.")
msg = _("Try running a manual scan of terrestrial frequencies. If this fails maybe there is no lcn data available in your area.")
self.services.clear()
if not (LCNs := self.readLcnDb()):
return (_("%s is empty or missing.") % self.lcndb) + " " + msg
return (_("There is currently no LCN data stored.")) + " " + msg
for mode in (MODE_TV, MODE_RADIO):
terrestrials = self.getTerrestrials(mode)
for k in terrestrials:
Expand Down

0 comments on commit 8a88c39

Please sign in to comment.