diff --git a/main/eparser/__constants.py b/main/eparser/__constants.py index 35539df9..c716150b 100644 --- a/main/eparser/__constants.py +++ b/main/eparser/__constants.py @@ -22,6 +22,6 @@ SYSTEM = {"0": "DVB-S", "1": "DVB-S2"} MODULATION = {"0": "Auto", "1": "QPSK", "2": "8PSK", "3": "16APSK", "5": "32APSK"} -SERVICE_TYPE = {-2: "Unknown", 1: "TV", 2: "Radio", 3: "Data", - 10: "Radio", 12: "Data", 22: "TV", 25: "TV (HD)", - 136: "Data", 139: "Data"} +SERVICE_TYPE = {"-2": "Unknown", "1": "TV", "2": "Radio", "3": "Data", + "10": "Radio", "12": "Data", "22": "TV", "25": "TV (HD)", + "136": "Data", "139": "Data"} diff --git a/main/eparser/__init__.py b/main/eparser/__init__.py index 4708c7a7..dc1ac452 100644 --- a/main/eparser/__init__.py +++ b/main/eparser/__init__.py @@ -1,4 +1,4 @@ -from .lamedb import get_channels, write_channels +from .lamedb import get_channels, write_channels, Channel from .bouquets import get_bouquets, write_bouquets, Bouquet, Bouquets from .satxml import get_satellites, write_satellites, Satellite, Transponder diff --git a/main/eparser/lamedb.py b/main/eparser/lamedb.py index b619dd0f..91688405 100644 --- a/main/eparser/lamedb.py +++ b/main/eparser/lamedb.py @@ -11,9 +11,9 @@ _HEADER = "eDVB services /4/" _FILE_PATH = "../data/lamedb" _SEP = ":" # separator -Channel = namedtuple("Channel", ["service", "package", "service_type", +Channel = namedtuple("Channel", ["flags_cas", "transponder_type", "service", "package", "service_type", "ssid", "freq", "rate", "pol", "fec", - "system", "pos", "data_id", "fav_id"]) + "system", "pos", "data_id", "fav_id", "transponder"]) def get_channels(path): @@ -21,7 +21,29 @@ def get_channels(path): def write_channels(path, channels): - print(channels) + lines = [_HEADER, "\ntransponders\n"] + tr_lines = [] + services_lines = ["end\nservices\n"] + tr_set = set() + + for ch in channels: + data_id = str(ch.data_id).split(_SEP) + tr_id = "{}:{}:{}".format(data_id[1], data_id[2], data_id[3]) + if tr_id not in tr_set: + transponder = "{}\n\t{}\n/\n".format(tr_id, ch.transponder) + tr_lines.append(transponder) + tr_set.add(tr_id) + # Services + flags = "," + ch.flags_cas if ch.flags_cas else "" + services_lines.append("{}\n{}\np:{}{}".format(ch.data_id, ch.service, ch.package, flags)) + + tr_lines.sort() + lines.extend(tr_lines) + lines.extend(services_lines) + lines.append("\nend\nFile was created in DemonEditor.\n....Enjoy watching!....\n") + + with open(path + "lamedb", "w") as file: + file.writelines(lines) def parse(path): @@ -61,14 +83,32 @@ def parse_channels(*args): # For comparison in bouquets. Needed in upper case!!! fav_id = "{}:{}:{}:{}".format(str(data[0]).lstrip(sp), str(data[2]).lstrip(sp), str(data[3]).lstrip(sp), str(data[1]).lstrip(sp)) - pack = str(ch[2]) - transponder = transponders.get(str(data[1] + _SEP + data[2] + _SEP + data[3]), None) + + package, sp, cas = str(ch[2]).partition(",") + _, sp, package = package.partition(_SEP) + + transponder_id = "{}:{}:{}".format(data[1], data[2], data[3]) + transponder = transponders.get(transponder_id, None) + if transponder is not None: - tr = str(transponder)[2:].split(_SEP) # Removing type of DVB transponders (s , t, c) and split - pack = pack[2:] if pack.find(",") < 0 else pack[2:pack.find(",")] - channels.append(Channel(ch[1], pack, SERVICE_TYPE.get(int(data[4]), SERVICE_TYPE[-2]), data[0], tr[0], - tr[1], POLARIZATION[tr[2]], FEC[tr[3]], SYSTEM[tr[6]], - "{}{}.{}".format(*list(tr[4])), ch[0], fav_id.upper())) + tr_type, sp, tr = str(transponder).partition(" ") + tr = tr.split(_SEP) + service_type = SERVICE_TYPE.get(data[4], SERVICE_TYPE["-2"]) + channels.append(Channel(flags_cas=cas, + transponder_type=tr_type, + service=ch[1], + package=package, + service_type=service_type, + ssid=data[0], + freq=tr[0], + rate=tr[1], + pol=POLARIZATION[tr[2]], + fec=FEC[tr[3]], + system=SYSTEM[tr[6]], + pos="{}{}.{}".format(*list(tr[4])), + data_id=ch[0], + fav_id=fav_id.upper(), + transponder=transponder)) return channels diff --git a/main/eparser/satxml.py b/main/eparser/satxml.py index d45ca42d..12bedf78 100644 --- a/main/eparser/satxml.py +++ b/main/eparser/satxml.py @@ -14,6 +14,7 @@ pls_code: 0 - 262142 """ from collections import namedtuple from xml.dom.minidom import parse, Document + from main.eparser.__constants import POLARIZATION, FEC, SYSTEM, MODULATION, PLS_MODE __FILE_NAME = "satellites.xml" diff --git a/main/ui/main_app_window.py b/main/ui/main_app_window.py index 7e0d10ad..5d7297e0 100644 --- a/main/ui/main_app_window.py +++ b/main/ui/main_app_window.py @@ -1,7 +1,7 @@ from contextlib import suppress from main.commons import run_task -from main.eparser import get_channels, get_bouquets, write_bouquets, write_channels, Bouquets, Bouquet +from main.eparser import get_channels, get_bouquets, write_bouquets, write_channels, Bouquets, Bouquet, Channel from main.ftp import download_data, upload_data from main.properties import get_config, write_config from . import Gtk, Gdk @@ -320,7 +320,7 @@ def on_data_save(*args): write_bouquets(path + "tmp/", bouquets, __bouquets) # Getting services services_model.foreach(lambda model, s_path, itr: - services.append(model.get(itr, *[item for item in range(s_n_columns)]))) + services.append(Channel(*model.get(itr, *[item for item in range(s_n_columns)])))) write_channels(path + "tmp/", services) diff --git a/main/ui/main_window.glade b/main/ui/main_window.glade index b28d0376..4665def0 100644 --- a/main/ui/main_window.glade +++ b/main/ui/main_window.glade @@ -114,6 +114,10 @@ + + + + @@ -138,6 +142,8 @@ + + @@ -646,7 +652,7 @@ True True services_list_store - 0 + 2 True both True @@ -659,6 +665,32 @@ multiple + + + False + autosize + CAS + + + + 0 + + + + + + + False + autosize + Type + + + + 1 + + + + True @@ -666,11 +698,11 @@ Service True True - 0 + 2 - 0 + 2 @@ -682,11 +714,11 @@ Package True True - 1 + 3 - 1 + 3 @@ -697,13 +729,13 @@ Type True True - 2 + 4 - + 0.51999998092651367 - 2 + 4 @@ -715,13 +747,13 @@ Ssid True True - 3 + 5 0.50999999046325684 - 3 + 5 @@ -733,13 +765,13 @@ Freq True True - 4 + 6 0.50999999046325684 - 4 + 6 @@ -751,13 +783,13 @@ Rate True True - 5 + 7 0.50999999046325684 - 5 + 7 @@ -769,13 +801,13 @@ Pol True True - 6 + 8 0.50999999046325684 - 6 + 8 @@ -787,13 +819,13 @@ FEC True True - 7 + 9 0.50999999046325684 - 7 + 9 @@ -805,13 +837,13 @@ System True True - 8 + 10 0.50999999046325684 - 8 + 10 @@ -821,13 +853,13 @@ True Pos True - 9 + 11 0.50999999046325684 - 9 + 11 @@ -840,7 +872,7 @@ - 10 + 12 @@ -853,7 +885,20 @@ - 11 + 13 + + + + + + + False + autosize + transponder + + + + 14 @@ -923,7 +968,7 @@ - + Type True @@ -955,7 +1000,7 @@ False fav_id - + 4