diff --git a/app/tools/picons.py b/app/tools/picons.py index e733d483..e1d3ddc4 100644 --- a/app/tools/picons.py +++ b/app/tools/picons.py @@ -32,6 +32,7 @@ import re import shutil import subprocess from collections import namedtuple +from enum import IntEnum from html.parser import HTMLParser import requests @@ -51,6 +52,12 @@ class PiconsError(Exception): pass +class PiconFormat(IntEnum): + ENIGMA2 = 0 + NEUTRINO = 1 + OSCAM = 3 + + class PiconsCzDownloader: """ The main class for loading picons from the https://picon.cz/ source (by ChocholouĊĦek). """ @@ -509,21 +516,40 @@ def download_picon(src_url, dest_path): @run_task -def convert_to(src_path, dest_path, s_type, done_callback): - """ Converts names format of picons. +def convert_to(src_path, dest_path, p_format, ids=None, done_callback=None): + """ Converts format [names] of picons. Copies resulting files from src to dest and writes state to callback. """ - pattern = "/*_0_0_0.png" if s_type is SettingsType.ENIGMA_2 else "/*.png" + pattern = "/*_0_0_0.png" if p_format is PiconFormat.NEUTRINO else "/*.png" + to_convert = [] for file in glob.glob(src_path + pattern): base_name = os.path.basename(file) + if ids is not None and base_name not in ids: + continue + + to_convert.append((base_name, dest_path, file)) + + if p_format is PiconFormat.NEUTRINO: + convert_to_neutrino(to_convert) + elif p_format is PiconFormat.OSCAM: + convert_to_oscam(to_convert) + + if done_callback: + done_callback() + + +def convert_to_neutrino(files): + for base_name, dest_path, file in files: pic_data = base_name.rstrip(".png").split("_") dest_file = _NEUTRINO_PICON_KEY.format(int(pic_data[4], 16), int(pic_data[5], 16), int(pic_data[3], 16)) - dest = "{}/{}".format(dest_path, dest_file) - log('Converting "{}" to "{}"'.format(base_name, dest_file)) + dest = f"{dest_path}{os.sep}{dest_file}" + log(f'Converting "{base_name}" to "{dest_file}"') shutil.copyfile(file, dest) - done_callback() + +def convert_to_oscam(files): + pass if __name__ == "__main__": diff --git a/app/ui/picons.glade b/app/ui/picons.glade index 46f8b936..c5c29839 100644 --- a/app/ui/picons.glade +++ b/app/ui/picons.glade @@ -610,8 +610,8 @@ Author: Dmitriy Yefremov False - False Filter + False False False False @@ -745,8 +745,8 @@ Author: Dmitriy Yefremov False - False Filter + False False False False @@ -1048,9 +1048,9 @@ Author: Dmitriy Yefremov True - True False 5 + True False @@ -1063,9 +1063,9 @@ Author: Dmitriy Yefremov True False + Filter by current satellite positions 5 5 - Filter by current satellite positions True @@ -1580,110 +1580,24 @@ Author: Dmitriy Yefremov True False - 5 - 5 - 5 - 5 + 10 + 10 + 10 + 10 vertical - 2 + 5 - - - True - False - 10 - 10 - 10 - 5 - 2 - True - - - True - False - select-folder - - - 0 - 1 - - - - - True - False - Path to Enigma2 picons: - - - 0 - 0 - - - - - True - False - Path to save: - - - 0 - 2 - - - - - True - False - select-folder - - - 0 - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - True - 0 - - - - - True + + False False 10 - Enigma2 -> Neutrino-MP + Enigma2 -> Neutrino-MP False True end - 1 + 0 @@ -1697,9 +1611,154 @@ Author: Dmitriy Yefremov False True end + 1 + + + + + True + False + 10 + Enigma2 -> OSCam + + + False + True + end + 1 + + + + + True + False + center + 10 + True + expand + + + OSCam + True + True + False + False + converter_nt_button + + + True + True + 1 + + + + + Neutrino-MP + True + True + False + False + converter_sc_button + + + True + True + 2 + + + + + False + True 2 + + + True + False + 5 + 5 + 5 + + + True + False + end + Convert for selected bouquets + + + True + True + 1 + + + + + True + True + + + False + True + 2 + + + + + False + True + 3 + + + + + True + False + Path to Enigma2 picons: + + + False + True + 4 + + + + + True + False + select-folder + + + False + True + 5 + + + + + True + False + Path to save: + + + False + True + 6 + + + + + True + False + select-folder + + + False + True + 7 + + diff --git a/app/ui/picons.py b/app/ui/picons.py index 073ca8d8..a1429deb 100644 --- a/app/ui/picons.py +++ b/app/ui/picons.py @@ -40,7 +40,7 @@ from app.commons import run_idle, run_task, run_with_delay, log from app.connections import upload_data, DownloadType, download_data, remove_picons from app.settings import SettingsType, Settings, SEP, IS_DARWIN from app.tools.picons import (PiconsParser, parse_providers, Provider, convert_to, download_picon, PiconsCzDownloader, - PiconsError) + PiconsError, PiconFormat) from app.tools.satellites import SatellitesParser, SatelliteSource from .dialogs import show_dialog, DialogType, translate, get_builder, get_chooser_dialog from .main_helper import (scroll_to, on_popup_menu, get_base_model, set_picon, get_picon_pixbuf, get_picon_dialog, @@ -153,6 +153,9 @@ class PiconManager(Gtk.Box): self._bouquet_filter_switch = builder.get_object("bouquet_filter_switch") self._providers_header_box = builder.get_object("providers_header_box") self._header_download_box = builder.get_object("header_download_box") + self._converter_sc_button = builder.get_object("converter_sc_button") + self._converter_nt_button = builder.get_object("converter_nt_button") + self._converter_bq_button = builder.get_object("converter_bq_button") # Info. self._dst_count_label = builder.get_object("dst_count_label") self._info_check_button = builder.get_object("info_check_button") @@ -999,10 +1002,22 @@ class PiconManager(Gtk.Box): return self._app.change_action_state("on_logs_show", GLib.Variant.new_boolean(True)) - convert_to(src_path=picons_path, - dest_path=save_path, - s_type=SettingsType.ENIGMA_2, - done_callback=lambda: self.show_info_message(translate("Done!"), Gtk.MessageType.INFO)) + ids = None + p_format = PiconFormat.NEUTRINO if self._converter_nt_button.get_active() else PiconFormat.OSCAM + + if self._converter_bq_button.get_active(): + bq_selected = self._app.check_bouquet_selection() + if not bq_selected: + return + + services = self._app.current_services + ids = {services.get(s).picon_id for s in self._app.current_bouquets.get(bq_selected) if s in services} + + if self._converter_nt_button.get_active(): + convert_to(src_path=picons_path, dest_path=save_path, p_format=p_format, ids=ids, + done_callback=lambda: self.show_info_message(translate("Done!"), Gtk.MessageType.INFO)) + else: + self.show_info_message("Not implemented yet!", Gtk.MessageType.ERROR) @run_idle def update_receive_button_state(self):