mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-03-05 12:01:45 +01:00
write services for neutrino
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from app.commons import run_task
|
||||
from app.properties import Profile
|
||||
from .ecommons import Service, Satellite, Transponder, Bouquet, Bouquets
|
||||
from .enigma.blacklist import get_blacklist, write_blacklist
|
||||
@@ -16,6 +17,7 @@ def get_services(data_path, profile):
|
||||
return get_neutrino_services(data_path)
|
||||
|
||||
|
||||
@run_task
|
||||
def write_services(path, channels, profile):
|
||||
if profile is Profile.ENIGMA_2:
|
||||
write_enigma_services(path, channels)
|
||||
@@ -30,6 +32,7 @@ def get_bouquets(path, profile):
|
||||
return get_neutrino_bouquets(path)
|
||||
|
||||
|
||||
@run_task
|
||||
def write_bouquets(path, bouquets, profile):
|
||||
if profile is Profile.ENIGMA_2:
|
||||
write_enigma_bouquets(path, bouquets)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from enum import Enum
|
||||
from xml.dom.minidom import parse, Document
|
||||
|
||||
import os
|
||||
|
||||
from ..ecommons import Bouquets, Bouquet, BouquetService, BqServiceType
|
||||
|
||||
_FILE = "bouquets.xml"
|
||||
@@ -20,7 +20,6 @@ def get_bouquets(path):
|
||||
|
||||
|
||||
def parse_bouquets(file, name, bq_type):
|
||||
|
||||
bouquets = Bouquets(name=name, type=bq_type, bouquets=[])
|
||||
if not os.path.exists(file):
|
||||
return bouquets
|
||||
@@ -46,10 +45,14 @@ def parse_bouquets(file, name, bq_type):
|
||||
|
||||
|
||||
def write_bouquets(path, bouquets):
|
||||
if len(bouquets) < 2:
|
||||
for f in path + _FILE, path + _U_FILE:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(f)
|
||||
|
||||
for bq in bouquets:
|
||||
bq_type = BqType(bq.type)
|
||||
# write_bouquet(path + (_FILE if bq_type is BqType.BOUQUET else _U_FILE), bq)
|
||||
write_bouquet(path + "_" + (_FILE if bq_type is BqType.BOUQUET else _U_FILE), bq) # temporary!
|
||||
write_bouquet(path + (_FILE if bq_type is BqType.BOUQUET else _U_FILE), bq)
|
||||
|
||||
|
||||
def write_bouquet(file, bouquet):
|
||||
@@ -62,6 +65,9 @@ def write_bouquet(file, bouquet):
|
||||
for bq in bouquet.bouquets:
|
||||
bq_elem = doc.createElement("Bouquet")
|
||||
bq_elem.setAttribute("name", bq.name)
|
||||
bq_elem.setAttribute("hidden", "0")
|
||||
bq_elem.setAttribute("locked", "0")
|
||||
bq_elem.setAttribute("epg", "0")
|
||||
root.appendChild(bq_elem)
|
||||
|
||||
for srv in bq.services:
|
||||
|
||||
@@ -3,6 +3,8 @@ from xml.dom.minidom import parse, Document
|
||||
from ..ecommons import Service, POLARIZATION, FEC, SYSTEM, SERVICE_TYPE, PROVIDER
|
||||
|
||||
_FILE = "services.xml"
|
||||
_TR_ATTR_NAMES = ("id", "on", "frq", "inv", "sr", "fec", "pol", "mod", "sys") # transponder attributes
|
||||
_SRV_ATTR_NAMES = ("t", "s", "num", "f", "v", "a", "p", "pmt", "tx", "vt") # service attributes
|
||||
|
||||
|
||||
def write_services(path, services):
|
||||
@@ -26,7 +28,7 @@ def write_services(path, services):
|
||||
tr_atr = sat.split(":")
|
||||
sat_elem = doc.createElement("sat")
|
||||
sat_elem.setAttribute("name", tr_atr[0])
|
||||
sat_elem.setAttribute("position", tr_atr[1])
|
||||
sat_elem.setAttribute("position", tr_atr[1].replace(".", ""))
|
||||
sat_elem.setAttribute("diseqc", tr_atr[2])
|
||||
sat_elem.setAttribute("uncommited", tr_atr[3])
|
||||
root.appendChild(sat_elem)
|
||||
@@ -40,25 +42,33 @@ def write_services(path, services):
|
||||
srv_list = [srv]
|
||||
transponers[flag] = srv_list
|
||||
|
||||
tr_atr_names = ("id", "on", "frq", "inv", "sr", "fec", "pol", "mod", "sys") # transponder attributes
|
||||
for tr in transponers:
|
||||
tr_elem = doc.createElement("TS")
|
||||
tr_atr = tr.split(":")
|
||||
for i, value in enumerate(tr_atr):
|
||||
tr_elem.setAttribute(tr_atr_names[i], value)
|
||||
if value == "None":
|
||||
continue
|
||||
tr_elem.setAttribute(_TR_ATTR_NAMES[i], value)
|
||||
sat_elem.appendChild(tr_elem)
|
||||
|
||||
sr_atr_names = ("t", "s", "num", "f")
|
||||
for srv in transponers.get(tr):
|
||||
srv_elem = doc.createElement("S")
|
||||
srv_elem.setAttribute("i", srv[8])
|
||||
srv_elem.setAttribute("n", srv[3])
|
||||
srv_atr = srv[15].split(":")
|
||||
for i, value in enumerate(srv_atr):
|
||||
srv_elem.setAttribute(sr_atr_names[i], value)
|
||||
|
||||
srv_attrs = srv.data_id.split(":")
|
||||
api = srv_attrs.pop(0)
|
||||
|
||||
if api == "3":
|
||||
root.setAttribute("api", "3") # !!!
|
||||
for i, value in enumerate(srv_attrs):
|
||||
if value == "None":
|
||||
continue
|
||||
srv_elem.setAttribute(_SRV_ATTR_NAMES[i], value)
|
||||
|
||||
tr_elem.appendChild(srv_elem)
|
||||
|
||||
doc.writexml(open(path + "_" + _FILE, "w"), addindent=" ", newl="\n", encoding="UTF-8")
|
||||
doc.writexml(open(path + _FILE, "w"), addindent=" ", newl="\n", encoding="UTF-8")
|
||||
doc.unlink()
|
||||
|
||||
|
||||
@@ -79,9 +89,11 @@ def parse_services(path):
|
||||
sat_name = elem.attributes["name"].value
|
||||
sat_pos = elem.attributes["position"].value
|
||||
sat_pos = "{}.{}".format(sat_pos[:-1], sat_pos[-1:])
|
||||
sat = "{}:{}:{}:{}".format(sat_name, sat_pos,
|
||||
elem.attributes["diseqc"].value,
|
||||
elem.attributes["uncommited"].value)
|
||||
diseqc = elem.attributes.get("diseqc")
|
||||
diseqc = diseqc.value if diseqc else diseqc
|
||||
uncommited = elem.attributes.get("uncommited")
|
||||
uncommited = uncommited.value if uncommited else uncommited
|
||||
sat = "{}:{}:{}:{}".format(sat_name, sat_pos, diseqc, uncommited)
|
||||
|
||||
for tr_elem in elem.getElementsByTagName("TS"):
|
||||
if tr_elem.hasAttributes():
|
||||
@@ -111,8 +123,10 @@ def parse_transponder(api, sat, sat_pos, services, tr_elem):
|
||||
name = srv_elem.attributes["n"].value
|
||||
srv_type = srv_elem.attributes["t"].value
|
||||
sys = srv_elem.attributes["s"].value
|
||||
num = srv_elem.attributes["num"].value
|
||||
f = srv_elem.attributes["f"].value
|
||||
num = srv_elem.attributes.get("num")
|
||||
num = num.value if num else num
|
||||
f = srv_elem.attributes.get("f")
|
||||
f = f.value if f else f
|
||||
v, a, p, pmt, tx, vt = [None] * 6
|
||||
|
||||
# For v3 is possible so: '<S i="0001" n="name" t="1" s="0" num="770" f="4"/>' (equals v4 api)
|
||||
|
||||
@@ -5,7 +5,8 @@ from enum import Enum
|
||||
from ftplib import FTP
|
||||
from telnetlib import Telnet
|
||||
|
||||
__DATA_FILES_LIST = ("tv", "radio", "lamedb", "blacklist", "whitelist")
|
||||
__DATA_FILES_LIST = ("tv", "radio", "lamedb", "blacklist", "whitelist", # enigma 2
|
||||
"services.xml", "myservices.xml", "bouquets.xml", "ubouquets.xml") # neutrino
|
||||
|
||||
|
||||
class DownloadDataType(Enum):
|
||||
|
||||
@@ -267,9 +267,11 @@ class MainAppWindow:
|
||||
""" Deleting bouquet """
|
||||
self.__bouquets.pop(bouquet)
|
||||
self.__fav_model.clear()
|
||||
bouquet_file_name = "{}userbouquet.{}.{}".format(self.__options.get(self.__profile).get("data_dir_path"),
|
||||
*bouquet.split(":"))
|
||||
self.__bouquets_to_del.append(bouquet_file_name)
|
||||
profile = Profile(self.__profile)
|
||||
if profile is Profile.ENIGMA_2:
|
||||
bouquet_file_name = "{}userbouquet.{}.{}".format(self.__options.get(self.__profile).get("data_dir_path"),
|
||||
*bouquet.split(":"))
|
||||
self.__bouquets_to_del.append(bouquet_file_name)
|
||||
|
||||
def on_new_bouquet(self, view):
|
||||
""" Creates a new item in the bouquets tree """
|
||||
@@ -499,11 +501,6 @@ class MainAppWindow:
|
||||
path = self.__options.get(self.__profile).get("data_dir_path")
|
||||
bouquets = []
|
||||
services_model = self.__services_view.get_model()
|
||||
# removing bouquet files
|
||||
for bqf in self.__bouquets_to_del:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(bqf)
|
||||
self.__bouquets_to_del.clear()
|
||||
|
||||
def parse_bouquets(model, b_path, itr):
|
||||
if model.iter_has_child(itr):
|
||||
@@ -519,14 +516,21 @@ class MainAppWindow:
|
||||
bqs = Bouquets(*model.get(itr, 0, 1), bqs)
|
||||
bouquets.append(bqs)
|
||||
|
||||
profile = Profile(self.__profile)
|
||||
# Getting bouquets
|
||||
self.__bouquets_view.get_model().foreach(parse_bouquets)
|
||||
write_bouquets(path, bouquets, Profile(self.__profile))
|
||||
write_bouquets(path, bouquets, profile)
|
||||
# Getting services
|
||||
services = [Service(*row[:]) for row in services_model]
|
||||
write_services(path, services, Profile(self.__profile))
|
||||
# blacklist
|
||||
write_blacklist(path, self.__blacklist)
|
||||
write_services(path, services, profile)
|
||||
# removing bouquet files
|
||||
if profile is profile.ENIGMA_2:
|
||||
for bqf in self.__bouquets_to_del:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(bqf)
|
||||
self.__bouquets_to_del.clear()
|
||||
# blacklist
|
||||
write_blacklist(path, self.__blacklist)
|
||||
|
||||
def on_services_selection(self, model, path, column):
|
||||
self.delete_selection(self.__fav_view)
|
||||
|
||||
Reference in New Issue
Block a user