Skip to content

Commit

Permalink
PEP
Browse files Browse the repository at this point in the history
  • Loading branch information
Huevos committed Nov 17, 2024
1 parent ec25ebd commit 7f99e76
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 74 deletions.
7 changes: 5 additions & 2 deletions SatScanLcn/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# -*- coding: utf-8 -*-
from Components.Language import language
from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
import os, gettext
from Tools.Directories import resolveFilename, SCOPE_PLUGINS
import gettext

PluginLanguageDomain = "SatScanLcn"
PluginLanguagePath = "SystemPlugins/SatScanLcn/locale"


def localeInit():
gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))


def _(txt):
if gettext.dgettext(PluginLanguageDomain, txt):
return gettext.dgettext(PluginLanguageDomain, txt)
else:
print("[" + PluginLanguageDomain + "] fallback to default translation for " + txt)
return gettext.gettext(txt)


language.addCallback(localeInit())
5 changes: 3 additions & 2 deletions SatScanLcn/src/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

from Screens.Screen import Screen


class SatScanLcn_About(Screen):
def __init__(self, session):
Screen.__init__(self, session)
self.setTitle(_("Grab LCN bouquets from the DVB stream."))

self.skinName = ["SatScanLcn_About", "Setup" ]
self.skinName = ["SatScanLcn_About", "Setup"]

self["actions"] = ActionMap(["WizardActions", "ColorActions"],
{
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, session):
_("Only one instance of each channel appears in the bouquet. If any channel is found to have multiple LCNs the lowest LCN numerically will be selected.") + '\n\n',
_("To grab multiple bouquets just run the application multiple times.") + '\n\n',
]

self["config"] = ScrollLabel(''.join(credits))

def pageUp(self):
Expand Down
26 changes: 14 additions & 12 deletions SatScanLcn/src/downloadbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

from enigma import getDesktop


def insertValues(xml, values):
# The skin template is designed for a HD screen so the scaling factor is 720.
# double negative to round up not round down
return xml % tuple([-(x*getDesktop(0).size().height()/(-720)) for x in values])
return xml % tuple([-(x*getDesktop(0).size().height() / (-720)) for x in values])


def downloadBar():
fontSize = 22
Expand All @@ -34,7 +36,7 @@ def downloadBar():
tunerLetterLeftAlign = 955
tunerLetterWidth = fontSize
snrBoxLeftAlign = 980
snrBoxWidth = 87 # up to 7 chars, e.g. "16.2 dB"
snrBoxWidth = 87 # up to 7 chars, e.g. "16.2 dB"
progressTextBoxLeftAlign = 1080
progressTextBoxWidth = 87
progressPercentLeftAlign = 1187
Expand Down Expand Up @@ -63,14 +65,14 @@ def downloadBar():
</widget>
</screen>"""
downloadBarValues = [
getDesktop(0).size().width(), downloadBarHeight, # downloadBarXML line 1, "screen" element
actionBoxLeftAlign, textBoxTopMargin, actionBoxWidth, textBoxHeight, fontSize, # downloadBarXML line 2, "action" widget
statusBoxLeftAlign, textBoxTopMargin, statusBoxWidth, textBoxHeight, fontSize, # downloadBarXML line 3, "status" widget
lockImageLeftAlign, lockImageTopMargin, lockImageWidth, lockImageHeight, # downloadBarXML, "lock_on" widget
lockImageLeftAlign, lockImageTopMargin, lockImageWidth, lockImageHeight, # downloadBarXML, "lock_off" widget
tunerLetterLeftAlign, textBoxTopMargin, tunerLetterWidth, textBoxHeight, fontSize, # downloadBarXML, "tuner letter" widget
snrBoxLeftAlign, textBoxTopMargin, snrBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "SNR" widget
progressTextBoxLeftAlign, textBoxTopMargin, progressTextBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "progress text" widget
progressPercentLeftAlign, textBoxTopMargin, progressPercentBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "progress percent" widget
getDesktop(0).size().width(), downloadBarHeight, # downloadBarXML line 1, "screen" element
actionBoxLeftAlign, textBoxTopMargin, actionBoxWidth, textBoxHeight, fontSize, # downloadBarXML line 2, "action" widget
statusBoxLeftAlign, textBoxTopMargin, statusBoxWidth, textBoxHeight, fontSize, # downloadBarXML line 3, "status" widget
lockImageLeftAlign, lockImageTopMargin, lockImageWidth, lockImageHeight, # downloadBarXML, "lock_on" widget
lockImageLeftAlign, lockImageTopMargin, lockImageWidth, lockImageHeight, # downloadBarXML, "lock_off" widget
tunerLetterLeftAlign, textBoxTopMargin, tunerLetterWidth, textBoxHeight, fontSize, # downloadBarXML, "tuner letter" widget
snrBoxLeftAlign, textBoxTopMargin, snrBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "SNR" widget
progressTextBoxLeftAlign, textBoxTopMargin, progressTextBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "progress text" widget
progressPercentLeftAlign, textBoxTopMargin, progressPercentBoxWidth, textBoxHeight, fontSize, # downloadBarXML, "progress percent" widget
]
return insertValues(downloadBarXML, downloadBarValues)
return insertValues(downloadBarXML, downloadBarValues)
42 changes: 21 additions & 21 deletions SatScanLcn/src/lamedbreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import division
import re


class LamedbReader():
def readLamedb(self, path):
print("[SatScanLcn-LamedbReader] Reading lamedb...")
Expand All @@ -10,7 +11,7 @@ def readLamedb(self, path):

try:
lamedb = open(path + "/lamedb", "r")
except Exception as e:
except Exception:
return transponders

content = lamedb.read()
Expand All @@ -23,7 +24,7 @@ def readLamedb(self, path):
print("[SatScanLcn-LamedbReader] lamedb ver", lamedb_ver)
if lamedb_ver == 4:
transponders = self.parseLamedbV4Content(content)
elif lamedb_ver == 5:
elif lamedb_ver == 5:
transponders = self.parseLamedbV5Content(content)
return transponders

Expand All @@ -36,7 +37,7 @@ def parseLamedbV4Content(self, content):
tp_stop = content.find("end\n")

tp_blocks = content[tp_start + 13:tp_stop].strip().split("/")
content = content[tp_stop+4:]
content = content[tp_stop + 4:]

for block in tp_blocks:
rows = block.strip().split("\n")
Expand All @@ -53,9 +54,9 @@ def parseLamedbV4Content(self, content):
transponder["transport_stream_id"] = int(first_row[1], 16)
transponder["original_network_id"] = int(first_row[2], 16)

#print. "%x:%x:%x" % (namespace, transport_stream_id, original_network_id)
# print. "%x:%x:%x" % (namespace, transport_stream_id, original_network_id)
second_row = rows[1].strip()
transponder["dvb_type"] = 'dvb'+second_row[0]
transponder["dvb_type"] = 'dvb' + second_row[0]
if transponder["dvb_type"] not in ["dvbs", "dvbt", "dvbc"]:
continue

Expand All @@ -81,18 +82,18 @@ def parseLamedbV4Content(self, content):

transponder["inversion"] = int(second_row[5])
transponder["flags"] = int(second_row[6])
if len(second_row) == 7: # DVB-S
if len(second_row) == 7: # DVB-S
transponder["system"] = 0
else: # DVB-S2
else: # DVB-S2
transponder["system"] = int(second_row[7])
transponder["modulation"] = int(second_row[8])
transponder["roll_off"] = int(second_row[9])
transponder["pilot"] = int(second_row[10])
if len(second_row) > 13: # Multistream
if len(second_row) > 13: # Multistream
transponder["is_id"] = int(second_row[11])
transponder["pls_code"] = int(second_row[12])
transponder["pls_mode"] = int(second_row[13])
if len(second_row) > 15: # T2MI
if len(second_row) > 15: # T2MI
transponder["t2mi_plp_id"] = int(second_row[14])
transponder["t2mi_pid"] = int(second_row[15])
elif transponder["dvb_type"] == "dvbt":
Expand Down Expand Up @@ -121,16 +122,15 @@ def parseLamedbV4Content(self, content):
transponders[key] = transponder
transponders_count += 1


srv_start = content.find("services\n")
srv_stop = content.rfind("end\n")

srv_blocks = content[srv_start + 9:srv_stop].strip().split("\n")

for i in range(0, len(srv_blocks)//3):
service_reference = srv_blocks[i*3].strip()
service_name = srv_blocks[(i*3)+1].strip()
service_provider = srv_blocks[(i*3)+2].strip()
for i in range(0, len(srv_blocks) // 3):
service_reference = srv_blocks[i * 3].strip()
service_name = srv_blocks[(i * 3) + 1].strip()
service_provider = srv_blocks[(i * 3) + 2].strip()
service_reference = service_reference.split(":")

if len(service_reference) not in (6, 7):
Expand All @@ -154,7 +154,7 @@ def parseLamedbV4Content(self, content):

# The original (correct) code
# transponders[key]["services"][service["service_id"]] = service

# Dirty hack to work around the (well known) service type bug in lamedb/enigma2
transponders[key]["services"]["%x:%x" % (service["service_type"], service["service_id"])] = service

Expand Down Expand Up @@ -182,7 +182,7 @@ def parseLamedbV5Content(self, content):
transponder["original_network_id"] = int(first_part[2], 16)

second_part = line.strip().split(",")[1]
transponder["dvb_type"] = 'dvb'+second_part[0]
transponder["dvb_type"] = 'dvb' + second_part[0]
if transponder["dvb_type"] not in ["dvbs", "dvbt", "dvbc"]:
continue

Expand All @@ -208,14 +208,14 @@ def parseLamedbV5Content(self, content):

transponder["inversion"] = int(second_part[5])
transponder["flags"] = int(second_part[6])
if len(second_part) == 7: # DVB-S
if len(second_part) == 7: # DVB-S
transponder["system"] = 0
else: # DVB-S2
else: # DVB-S2
transponder["system"] = int(second_part[7])
transponder["modulation"] = int(second_part[8])
transponder["roll_off"] = int(second_part[9])
transponder["pilot"] = int(second_part[10])
for part in line.strip().split(",")[2:]: # Multistream/T2MI
for part in line.strip().split(",")[2:]: # Multistream/T2MI
if part.startswith("MIS/PLS:") and len(part[8:].split(":")) == 3:
transponder["is_id"] = int(part[8:].split(":")[0])
transponder["pls_code"] = int(part[8:].split(":")[1])
Expand Down Expand Up @@ -277,10 +277,10 @@ def parseLamedbV5Content(self, content):

# The original (correct) code
# transponders[key]["services"][service["service_id"]] = service

# Dirty hack to work around the (well known) service type bug in lamedb/enigma2
transponders[key]["services"]["%x:%x" % (service["service_type"], service["service_id"])] = service

services_count += 1

print("[SatScanLcn-LamedbReader] Read %d transponders and %d services" % (transponders_count, services_count))
Expand Down
32 changes: 17 additions & 15 deletions SatScanLcn/src/lamedbwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from __future__ import print_function
import six

import os, codecs, re
import codecs
import re

from enigma import eDVBFrontendParametersSatellite


class LamedbWriter():

def writeLamedb(self, path, transponders, filename="lamedb"):
Expand Down Expand Up @@ -33,7 +35,7 @@ def writeLamedb(self, path, transponders, filename="lamedb"):
else:
orbital_position = transponder["orbital_position"]

if transponder["system"] == 0: # DVB-S
if transponder["system"] == 0: # DVB-S
lamedblist.append("\ts %d:%d:%d:%d:%d:%d:%d\n" %
(transponder["frequency"],
transponder["symbol_rate"],
Expand All @@ -42,7 +44,7 @@ def writeLamedb(self, path, transponders, filename="lamedb"):
orbital_position,
transponder["inversion"],
transponder["flags"]))
else: # DVB-S2
else: # DVB-S2
multistream = ''
t2mi = ''
if "t2mi_plp_id" in transponder and "t2mi_pid" in transponder:
Expand All @@ -54,14 +56,14 @@ def writeLamedb(self, path, transponders, filename="lamedb"):
transponder["is_id"],
transponder["pls_code"],
transponder["pls_mode"])
if t2mi and not multistream: # this is to pad t2mi values if necessary.
try: # some images are still not multistream aware after all this time
if t2mi and not multistream: # this is to pad t2mi values if necessary.
try: # some images are still not multistream aware after all this time
multistream = ':%d:%d:%d' % (
eDVBFrontendParametersSatellite.No_Stream_Id_Filter,
eDVBFrontendParametersSatellite.PLS_Gold,
eDVBFrontendParametersSatellite.PLS_Default_Gold_Code)
except AttributeError as err:
print("[ABM-BouquetsWriter] some images are still not multistream aware after all this time", err)
print("[ABM-BouquetsWriter] some images are still not multistream aware after all this time", err)
lamedblist.append("\ts %d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d%s%s\n" %
(transponder["frequency"],
transponder["symbol_rate"],
Expand Down Expand Up @@ -120,7 +122,7 @@ def writeLamedb(self, path, transponders, filename="lamedb"):
service["flags"],
":%x" % service["ATSC_source_id"] if "ATSC_source_id" in service else ""))

control_chars = ''.join(map(chr, list(range(0,32)) + list(range(127,160))))
control_chars = ''.join(map(chr, list(range(0, 32)) + list(range(127, 160))))
control_char_re = re.compile('[%s]' % re.escape(control_chars))
if 'provider_name' in list(service.keys()):
if six.PY2:
Expand Down Expand Up @@ -189,7 +191,7 @@ def writeLamedb5(self, path, transponders, filename="lamedb5"):
else:
orbital_position = transponder["orbital_position"]

if transponder["system"] == 0: # DVB-S
if transponder["system"] == 0: # DVB-S
lamedblist.append("s:%d:%d:%d:%d:%d:%d:%d\n" %
(transponder["frequency"],
transponder["symbol_rate"],
Expand All @@ -198,11 +200,11 @@ def writeLamedb5(self, path, transponders, filename="lamedb5"):
orbital_position,
transponder["inversion"],
transponder["flags"]))
else: # DVB-S2
else: # DVB-S2
multistream = ''
t2mi = ''
if "is_id" in transponder and "pls_code" in transponder and "pls_mode" in transponder:
try: # some images are still not multistream aware after all this time
try: # some images are still not multistream aware after all this time
# don't write default values
if not (transponder["is_id"] == eDVBFrontendParametersSatellite.No_Stream_Id_Filter and transponder["pls_code"] == eDVBFrontendParametersSatellite.PLS_Gold and transponder["pls_mode"] == eDVBFrontendParametersSatellite.PLS_Default_Gold_Code):
multistream = ',MIS/PLS:%d:%d:%d' % (
Expand All @@ -213,8 +215,8 @@ def writeLamedb5(self, path, transponders, filename="lamedb5"):
print("[-BouquetsWriter] some images are still not multistream aware after all this time", err)
if "t2mi_plp_id" in transponder and "t2mi_pid" in transponder:
t2mi = ',T2MI:%d:%d' % (
transponder["t2mi_plp_id"],
transponder["t2mi_pid"])
transponder["t2mi_plp_id"],
transponder["t2mi_pid"])
lamedblist.append("s:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d%s%s\n" %
(transponder["frequency"],
transponder["symbol_rate"],
Expand Down Expand Up @@ -271,7 +273,7 @@ def writeLamedb5(self, path, transponders, filename="lamedb5"):
service["flags"],
":%x" % service["ATSC_source_id"] if "ATSC_source_id" in service else ":0"))

control_chars = ''.join(map(chr, list(range(0,32)) + list(range(127,160))))
control_chars = ''.join(map(chr, list(range(0, 32)) + list(range(127, 160))))
control_char_re = re.compile('[%s]' % re.escape(control_chars))
if 'provider_name' in list(service.keys()):
if six.PY2:
Expand All @@ -293,15 +295,15 @@ def writeLamedb5(self, path, transponders, filename="lamedb5"):
if "service_flags" in list(service.keys()) and service["service_flags"] > 0:
service_flags = ",f:%x" % service["service_flags"]

if 'service_line' in list(service.keys()): # from lamedb
if 'service_line' in list(service.keys()): # from lamedb
if len(service["service_line"]):
if six.PY2:
lamedblist.append(",%s\n" % self.utf8_convert(service["service_line"]))
else:
lamedblist.append(",%s\n" % (service["service_line"]))
else:
lamedblist.append("\n")
else: # from scanner
else: # from scanner
lamedblist.append(",p:%s%s%s\n" % (provider_name, service_ca, service_flags))
services_count += 1

Expand Down
16 changes: 8 additions & 8 deletions SatScanLcn/src/plugin.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# for localized messages
from . import _

description = _("Scans for services and creates a bouquet")

from Components.config import config, ConfigSubsection, ConfigYesNo, ConfigSelection, ConfigNumber, NoSave, ConfigClock, ConfigEnableDisable, ConfigSubDict
from Components.config import config, ConfigSubsection, ConfigYesNo, ConfigSelection
from Components.NimManager import nimmanager
from Plugins.Plugin import PluginDescriptor
from Tools.BoundFunction import boundFunction

from .satscanlcn import SatScanLcn, SatScanLcn_Setup, getConfiguredSats
from .providers import PROVIDERS

description = _("Scans for services and creates a bouquet")

configured_sats = getConfiguredSats()

config.plugins.satscanlcn = ConfigSubsection()
config.plugins.satscanlcn.provider = ConfigSelection(choices = [(x, PROVIDERS[x]["name"]) for x in sorted(PROVIDERS.keys(), key=lambda k: k.lower()) if PROVIDERS[x]["transponder"]["orbital_position"] in configured_sats])
config.plugins.satscanlcn.extensions = ConfigYesNo(default = False)
config.plugins.satscanlcn.hd_only = ConfigYesNo(default = False)
config.plugins.satscanlcn.fta_only = ConfigYesNo(default = False)
config.plugins.satscanlcn.provider = ConfigSelection(choices=[(x, PROVIDERS[x]["name"]) for x in sorted(PROVIDERS.keys(), key=lambda k: k.lower()) if PROVIDERS[x]["transponder"]["orbital_position"] in configured_sats])
config.plugins.satscanlcn.extensions = ConfigYesNo(default=False)
config.plugins.satscanlcn.hd_only = ConfigYesNo(default=False)
config.plugins.satscanlcn.fta_only = ConfigYesNo(default=False)

for x in PROVIDERS.keys(): # if any provider has a regions list write it to a ConfigSelection
for x in PROVIDERS.keys(): # if any provider has a regions list write it to a ConfigSelection
if "bat" in PROVIDERS[x] and "bat_regions" in PROVIDERS[x]["bat"]:
setattr(config.plugins.satscanlcn, "bat-regions-" + x, ConfigSelection(choices=[(a, a) for a in sorted(PROVIDERS[x]["bat"]["bat_regions"].keys())]))
if "nit" in PROVIDERS[x] and "BouquetIDs" in PROVIDERS[x]["nit"]:
Expand Down
Loading

0 comments on commit 7f99e76

Please sign in to comment.