mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-01-19 22:13:10 +01:00
new algorithm for picons retrieving
This commit is contained in:
@@ -3,13 +3,11 @@ import shutil
|
||||
from collections import namedtuple
|
||||
from html.parser import HTMLParser
|
||||
|
||||
from app.commons import log
|
||||
from app.commons import log, run_task
|
||||
from app.properties import Profile
|
||||
|
||||
|
||||
_ENIGMA2_PICON_NAME = "1_0_{}_{:X}_{:X}_{:X}_{:X}0000_0_0_0.png"
|
||||
_NEUTRINO_PICON_NAME = "{:x}{:04x}{:04x}.png"
|
||||
|
||||
_ENIGMA2_PICON_KEY = "{:X}:{:X}:{:X}0000"
|
||||
_NEUTRINO_PICON_KEY = "{:x}{:04x}{:04x}.png"
|
||||
|
||||
Provider = namedtuple("Provider", ["logo", "name", "pos", "url", "on_id", "selected"])
|
||||
Picon = namedtuple("Picon", ["ref", "ssid", "v_pid"])
|
||||
@@ -73,7 +71,7 @@ class PiconsParser(HTMLParser):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def parse(open_path, picons_path, tmp_path, on_id, pos, profile=Profile.ENIGMA_2):
|
||||
def parse(open_path, picons_path, tmp_path, on_id, pos, picon_ids, profile=Profile.ENIGMA_2):
|
||||
with open(open_path, encoding="utf-8", errors="replace") as f:
|
||||
parser = PiconsParser()
|
||||
parser.reset()
|
||||
@@ -83,19 +81,20 @@ class PiconsParser(HTMLParser):
|
||||
os.makedirs(picons_path, exist_ok=True)
|
||||
for p in picons:
|
||||
try:
|
||||
picon_file_name = picons_path + PiconsParser.format(p.ssid, on_id, p.v_pid, pos, profile)
|
||||
shutil.copyfile(tmp_path + "www.lyngsat.com/" + p.ref.lstrip("."), picon_file_name)
|
||||
name = PiconsParser.format(p.ssid, on_id, p.v_pid, pos, picon_ids, profile)
|
||||
p_name = picons_path + (name if name else os.path.basename(p.ref))
|
||||
shutil.copyfile(tmp_path + "www.lyngsat.com/" + p.ref.lstrip("."), p_name)
|
||||
except (TypeError, ValueError) as e:
|
||||
log("Picons format parse error: {} {} {}".format(p.ref, p.ssid, p.v_pid) + "\n" + str(e))
|
||||
log("Picons format parse error: {}".format(p) + "\n" + str(e))
|
||||
print(e)
|
||||
|
||||
@staticmethod
|
||||
def format(ssid, on_id, v_pid, pos, profile: Profile):
|
||||
def format(ssid, on_id, v_pid, pos, picon_ids, profile: Profile):
|
||||
tr_id = int(ssid[:-2] if len(ssid) < 4 else ssid[:2])
|
||||
if profile is Profile.ENIGMA_2:
|
||||
return _ENIGMA2_PICON_NAME.format(1 if v_pid else 2, int(ssid), tr_id, int(on_id), int(pos))
|
||||
return picon_ids.get(_ENIGMA2_PICON_KEY.format(int(ssid), int(on_id), int(pos)), None)
|
||||
elif profile is Profile.NEUTRINO_MP:
|
||||
return _NEUTRINO_PICON_NAME.format(tr_id, int(on_id), int(ssid))
|
||||
return _NEUTRINO_PICON_KEY.format(tr_id, int(on_id), int(ssid))
|
||||
else:
|
||||
return "{}.png".format(ssid)
|
||||
|
||||
@@ -168,15 +167,16 @@ class ProviderParser(HTMLParser):
|
||||
def error(self, message):
|
||||
pass
|
||||
|
||||
def reset_counter(self):
|
||||
def reset(self):
|
||||
super().reset()
|
||||
self._counter = 0
|
||||
|
||||
|
||||
def parse_providers(open_path):
|
||||
parser = ProviderParser()
|
||||
parser.reset()
|
||||
|
||||
with open(open_path, encoding="utf-8", errors="replace") as f:
|
||||
parser = ProviderParser()
|
||||
parser.reset()
|
||||
parser.reset_counter()
|
||||
parser.feed(f.read())
|
||||
rows = parser.rows
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ class MainAppWindow:
|
||||
self.__profile_label.set_text("Enigma2 v.4" if Profile(self.__profile) is Profile.ENIGMA_2 else "Neutrino-MP")
|
||||
# dynamically active elements depending on the selected view
|
||||
self.__tool_elements = {k: builder.get_object(k) for k in self.__DYNAMIC_ELEMENTS}
|
||||
self.__picons_download_tool_button = builder.get_object("picons_download_tool_button")
|
||||
self.__cas_label = builder.get_object("cas_label")
|
||||
self.__fav_count_label = builder.get_object("fav_count_label")
|
||||
self.__bouquets_count_label = builder.get_object("bouquets_count_label")
|
||||
@@ -499,6 +500,7 @@ class MainAppWindow:
|
||||
self.append_services(data_path)
|
||||
self.update_services_counts(len(self.__services_model))
|
||||
self.update_picons()
|
||||
self.__picons_download_tool_button.set_sensitive(len(self.__services_model))
|
||||
except FileNotFoundError as e:
|
||||
show_dialog(DialogType.ERROR, self.__main_window, getattr(e, "message", str(e)) +
|
||||
"\n\nPlease, download files from receiver or setup your path for read data!")
|
||||
@@ -664,6 +666,7 @@ class MainAppWindow:
|
||||
self.__profile = profile
|
||||
self.clear_current_data()
|
||||
self.update_services_counts()
|
||||
self.__picons_download_tool_button.set_sensitive(len(self.__services_model))
|
||||
|
||||
def on_tree_view_key_release(self, view, event):
|
||||
""" Handling keystrokes """
|
||||
@@ -836,8 +839,15 @@ class MainAppWindow:
|
||||
def on_locate_in_services(self, view):
|
||||
locate_in_services(view, self.__services_view, self.__main_window)
|
||||
|
||||
@run_idle
|
||||
def on_picons_loader_show(self, item):
|
||||
dialog = PiconsDialog(self.__main_window, self.__options.get(self.__profile), Profile(self.__profile))
|
||||
ids = {}
|
||||
if Profile(self.__profile) is Profile.ENIGMA_2:
|
||||
for r in self.__services_model:
|
||||
data = r[9].split("_")
|
||||
ids["{}:{}:{}".format(data[3], data[5], data[6])] = r[9]
|
||||
|
||||
dialog = PiconsDialog(self.__main_window, self.__options.get(self.__profile), ids, Profile(self.__profile))
|
||||
dialog.show()
|
||||
self.update_picons()
|
||||
|
||||
|
||||
@@ -446,7 +446,7 @@
|
||||
<object class="GtkImage" id="send_recive_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">mail-send-receive</property>
|
||||
<property name="icon_name">network-transmit-receive</property>
|
||||
</object>
|
||||
<object class="GtkListStore" id="services_list_store">
|
||||
<columns>
|
||||
@@ -743,7 +743,7 @@
|
||||
<property name="tooltip_text" translatable="yes">FTP-transfer</property>
|
||||
<property name="label" translatable="yes">Download</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="icon_name">mail-send-receive</property>
|
||||
<property name="icon_name">network-transmit-receive</property>
|
||||
<signal name="clicked" handler="on_download" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -1090,6 +1090,7 @@
|
||||
<child>
|
||||
<object class="GtkToolButton" id="picons_download_tool_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Picons</property>
|
||||
<property name="label" translatable="yes">Picons loader</property>
|
||||
|
||||
@@ -416,6 +416,7 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="pos_column">
|
||||
<property name="sizing">autosize</property>
|
||||
<property name="title" translatable="yes">Position</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="pos_cellrenderertext1">
|
||||
|
||||
@@ -15,7 +15,8 @@ from .main_helper import update_entry_data
|
||||
|
||||
|
||||
class PiconsDialog:
|
||||
def __init__(self, transient, options, profile=Profile.ENIGMA_2):
|
||||
def __init__(self, transient, options, picon_ids, profile=Profile.ENIGMA_2):
|
||||
self._picon_ids = picon_ids
|
||||
self._TMP_DIR = tempfile.gettempdir() + "/"
|
||||
self._BASE_URL = "www.lyngsat.com/packages/"
|
||||
self._PATTERN = re.compile("^https://www\.lyngsat\.com/[\w-]+\.html$")
|
||||
@@ -130,7 +131,8 @@ class PiconsDialog:
|
||||
self._current_process.wait()
|
||||
path = self._TMP_DIR + self._BASE_URL + url[url.rfind("/") + 1:]
|
||||
pos = "".join(c for c in prv.pos if c.isdigit())
|
||||
PiconsParser.parse(path, self._picons_path, self._TMP_DIR, prv.on_id, pos, self.get_picons_format())
|
||||
PiconsParser.parse(path, self._picons_path, self._TMP_DIR, prv.on_id, pos,
|
||||
self._picon_ids, self.get_picons_format())
|
||||
self.resize(self._picons_path)
|
||||
self.show_info_message("Done", Gtk.MessageType.INFO)
|
||||
|
||||
@@ -225,7 +227,7 @@ class PiconsDialog:
|
||||
|
||||
def get_selected_providers(self):
|
||||
""" returns selected providers """
|
||||
return [r for r in self._providers_tree_view.get_model() if r[4]]
|
||||
return [r for r in self._providers_tree_view.get_model() if r[5]]
|
||||
|
||||
@run_idle
|
||||
def show_dialog(self, message, dialog_type):
|
||||
|
||||
Reference in New Issue
Block a user