diff --git a/app/eparser/__init__.py b/app/eparser/__init__.py index 87682d44..6062f1c6 100644 --- a/app/eparser/__init__.py +++ b/app/eparser/__init__.py @@ -18,9 +18,9 @@ def get_services(data_path, profile, format_version): @run_task -def write_services(path, channels, profile): +def write_services(path, channels, profile, format_version): if profile is Profile.ENIGMA_2: - write_enigma_services(path, channels) + write_enigma_services(path, channels, format_version) elif profile is Profile.NEUTRINO_MP: write_neutrino_services(path, channels) diff --git a/app/eparser/enigma/lamedb.py b/app/eparser/enigma/lamedb.py index bfb2cfbc..2ee4596d 100644 --- a/app/eparser/enigma/lamedb.py +++ b/app/eparser/enigma/lamedb.py @@ -1,4 +1,4 @@ -""" This module used for parsing lamedb file +""" This module used for parsing and write lamedb file Currently implemented only for satellite channels!!! """ @@ -7,17 +7,26 @@ from app.ui.uicommons import CODED_ICON, LOCKED_ICON, HIDE_ICON from .blacklist import get_blacklist from ..ecommons import Service, POLARIZATION, FEC, SERVICE_TYPE, Flag -_HEADER = "eDVB services /4/" +_HEADER = "eDVB services /{}/" _SEP = ":" # separator _FILE_NAME = "lamedb" +_END_LINE = "# File was created in DemonEditor.\n# ....Enjoy watching!....\n" def get_services(path, format_version): return parse(path, format_version) -def write_services(path, services): - lines = [_HEADER, "\ntransponders\n"] +def write_services(path, services, format_version=4): + if format_version == 4: + write_to_lamedb(path, services) + elif format_version == 5: + write_to_lamedb5(path, services) + + +def write_to_lamedb(path, services): + """ Writing lamedb file ver.4 """ + lines = [_HEADER.format(4), "\ntransponders\n"] tr_lines = [] services_lines = ["end\nservices\n"] tr_set = set() @@ -35,12 +44,31 @@ def write_services(path, services): tr_lines.sort() lines.extend(tr_lines) lines.extend(services_lines) - lines.append("end\nFile was created in DemonEditor.\n....Enjoy watching!....\n") - + lines.append("end\n" + _END_LINE) with open(path + _FILE_NAME, "w") as file: file.writelines(lines) +def write_to_lamedb5(path, services): + """ Writing lamedb5 file """ + lines = [_HEADER.format(5) + "\n"] + services_lines = [] + tr_set = set() + + for srv in services: + data_id = str(srv.data_id).split(_SEP) + tr_id = "{}:{}:{}".format(data_id[1], data_id[2], data_id[3]) + tr_set.add("t:{},{}\n".format(tr_id, srv.transponder.replace(" ", ":", 1))) + services_lines.append("s:{},\"{}\",{}".format(srv.data_id, srv.service, srv.flags_cas)) + + lines.extend(sorted(tr_set)) + lines.extend(services_lines) + lines.append(_END_LINE) + + with open(path + "lamedb5", "w") as file: + file.writelines(lines) + + def parse(path, version=4): """ Parsing lamedb """ if version == 4: @@ -80,7 +108,9 @@ def parse_v5(path): trs, srvs = {}, [""] for l in lns: if l.startswith("s:"): - srvs.extend(l.strip("s:").split(",", 2)) + srv_data = l.strip("s:").split(",", 2) + srv_data[1] = srv_data[1].strip("\"") + srvs.extend(srv_data) elif l.startswith("t:"): tr, srv = l.split(",") trs[tr.strip("t:")] = srv.strip().replace(":", " ", 1) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 9cebb3eb..ef490194 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -646,7 +646,7 @@ class MainAppWindow: write_bouquets(path, bouquets, profile) # Getting services services = [Service(*row[:]) for row in services_model] - write_services(path, services, profile) + write_services(path, services, profile, self.get_format_version() if profile is Profile.ENIGMA_2 else 0) # removing bouquet files if profile is Profile.ENIGMA_2: # blacklist