diff --git a/app/eparser/__init__.py b/app/eparser/__init__.py index d514d26b..4a688d4a 100644 --- a/app/eparser/__init__.py +++ b/app/eparser/__init__.py @@ -33,9 +33,9 @@ def get_bouquets(path, s_type): @run_task -def write_bouquets(path, bouquets, s_type): +def write_bouquets(path, bouquets, s_type, force_bq_names=False): if s_type is SettingsType.ENIGMA_2: - write_enigma_bouquets(path, bouquets) + write_enigma_bouquets(path, bouquets, force_bq_names) elif s_type is SettingsType.NEUTRINO_MP: write_neutrino_bouquets(path, bouquets) diff --git a/app/eparser/enigma/bouquets.py b/app/eparser/enigma/bouquets.py index 4eccadf8..a8f0bacd 100644 --- a/app/eparser/enigma/bouquets.py +++ b/app/eparser/enigma/bouquets.py @@ -1,4 +1,4 @@ -""" Module for parsing bouquets """ +""" Module for working with Enigma2 bouquets. """ import re from collections import Counter @@ -15,7 +15,12 @@ def get_bouquets(path): BqType.RADIO.value) -def write_bouquets(path, bouquets): +def write_bouquets(path, bouquets, force_bq_names=False): + """ Creating and writing bouquets files. + + If "force_bq_names" then naming the files using the name of the bouquet. + Some images may have problems displaying the favorites list! + """ srv_line = '#SERVICE 1:7:{}:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.{}.{}" ORDER BY bouquet\n' line = [] pattern = re.compile("[^\\w_()]+") @@ -25,12 +30,12 @@ def write_bouquets(path, bouquets): line.clear() line.append("#NAME {}\n".format(bqs.name)) - for bq in bqs.bouquets: + for index, bq in enumerate(bqs.bouquets): bq_name = bq.name if bq_name == "Favourites (TV)" or bq_name == "Favourites (Radio)": bq_name = _DEFAULT_BOUQUET_NAME else: - bq_name = re.sub(pattern, "_", bq.name) + bq_name = re.sub(pattern, "_", bq.name) if force_bq_names else "de{0:02d}".format(index) line.append(srv_line.format(2 if bq.type == BqType.RADIO.value else 1, bq_name, bq.type)) write_bouquet(path + "userbouquet.{}.{}".format(bq_name, bq.type), bq.name, bq.services, current_marker) @@ -62,7 +67,7 @@ def write_bouquet(path, name, services, current_marker): def to_bouquet_id(srv): - """ Creates bouquet channel id """ + """ Creates bouquet channel id. """ data_type = srv.data_id if data_type and len(data_type) > 4: data_type = int(srv.data_id.split(":")[4]) @@ -71,7 +76,7 @@ def to_bouquet_id(srv): def get_bouquet(path, name, bq_type): - """ Parsing services ids from bouquet file """ + """ Parsing services ids from bouquet file. """ with open(path + "userbouquet.{}.{}".format(name, bq_type), encoding="utf-8", errors="replace") as file: chs_list = file.read() services = [] diff --git a/app/settings.py b/app/settings.py index f0f9bf58..fb5f85ff 100644 --- a/app/settings.py +++ b/app/settings.py @@ -23,6 +23,7 @@ class Defaults(Enum): BACKUP_BEFORE_DOWNLOADING = True BACKUP_BEFORE_SAVE = True V5_SUPPORT = False + FORCE_BQ_NAMES = False HTTP_API_SUPPORT = False ENABLE_YT_DL = False ENABLE_SEND_TO = False @@ -497,6 +498,14 @@ class Settings: def v5_support(self, value): self._settings["v5_support"] = value + @property + def force_bq_names(self): + return self._settings.get("force_bq_names", Defaults.FORCE_BQ_NAMES.value) + + @force_bq_names.setter + def force_bq_names(self, value): + self._settings["force_bq_names"] = value + @property def http_api_support(self): return self._settings.get("http_api_support", Defaults.HTTP_API_SUPPORT.value) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 2284d12b..07cc1a01 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -1022,6 +1022,12 @@ class Application(Gtk.Application): if current_profile != self._settings.current_profile: self.init_profiles(self._settings.current_profile) + if data_path != self._settings.data_local_path: + xml_src = data_path + "satellites.xml" + if os.path.isfile(xml_src): + from shutil import copyfile + copyfile(xml_src, self._settings.data_local_path + "satellites.xml") + prf = self._s_type black_list = get_blacklist(data_path) bouquets = get_bouquets(data_path, prf) @@ -1221,7 +1227,7 @@ class Application(Gtk.Application): # Getting bouquets self._bouquets_view.get_model().foreach(parse_bouquets) - write_bouquets(path, bouquets, profile) + write_bouquets(path, bouquets, profile, self._settings.force_bq_names) yield True # Getting services services_model = get_base_model(self._services_view.get_model()) diff --git a/app/ui/settings_dialog.glade b/app/ui/settings_dialog.glade index 3aeb434a..65f3cd10 100644 --- a/app/ui/settings_dialog.glade +++ b/app/ui/settings_dialog.glade @@ -2839,6 +2839,64 @@ Author: Dmitriy Yefremov 0 + + + True + False + Allows you to name bouquet files using their names. + 5 + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + + + True + False + start + True + Enable alternate bouquet file naming + + + 0 + 0 + + + + + True + True + end + + + + 1 + 0 + + + + + + + + + + False + True + 1 + + False @@ -2892,7 +2950,7 @@ Author: Dmitriy Yefremov False True - 1 + 2 @@ -2976,7 +3034,7 @@ Author: Dmitriy Yefremov False True - 2 + 3 @@ -3098,7 +3156,7 @@ Author: Dmitriy Yefremov False True - 3 + 4 diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 28fd4872..aae9b9e4 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -34,6 +34,7 @@ class SettingsDialog: "on_connection_test": self.on_connection_test, "on_info_bar_close": self.on_info_bar_close, "on_set_color_switch": self.on_set_color_switch, + "on_force_bq_name": self.on_force_bq_name, "on_http_mode_switch": self.on_http_mode_switch, "on_yt_dl_switch": self.on_yt_dl_switch, "on_default_path_mode_switch": self.on_default_path_mode_switch, @@ -110,6 +111,7 @@ class SettingsDialog: self._enigma_radio_button = builder.get_object("enigma_radio_button") self._neutrino_radio_button = builder.get_object("neutrino_radio_button") self._support_ver5_switch = builder.get_object("support_ver5_switch") + self._force_bq_name_switch = builder.get_object("force_bq_name_switch") # Streaming header_separator = builder.get_object("header_separator") self._apply_presets_button = builder.get_object("apply_presets_button") @@ -156,6 +158,7 @@ class SettingsDialog: self._click_mode_zap_button.bind_property("sensitive", self._enable_send_to_switch, "sensitive") self._enable_send_to_switch.bind_property("sensitive", builder.get_object("enable_send_to_label"), "sensitive") self._extra_support_grid.bind_property("sensitive", builder.get_object("v5_support_grid"), "sensitive") + self._extra_support_grid.bind_property("sensitive", builder.get_object("bq_naming_grid"), "sensitive") # Profiles self._profile_view = builder.get_object("profile_tree_view") self._profile_add_button = builder.get_object("profile_add_button") @@ -278,6 +281,7 @@ class SettingsDialog: if self._s_type is SettingsType.ENIGMA_2: self._support_ver5_switch.set_active(self._settings.v5_support) + self._force_bq_name_switch.set_active(self._settings.force_bq_names) self._support_http_api_switch.set_active(self._settings.http_api_support) self._enable_y_dl_switch.set_active(self._settings.enable_yt_dl) self._enable_send_to_switch.set_active(self._settings.enable_send_to) @@ -339,7 +343,7 @@ class SettingsDialog: self._ext_settings.activate_transcoding = self._transcoding_switch.get_active() self._ext_settings.active_preset = self._presets_combo_box.get_active_id() - if self._ext_settings.is_darwin or True: + if self._ext_settings.is_darwin: self._ext_settings.is_themes_support = self._themes_support_switch.get_active() self._ext_settings.theme = self._theme_combo_box.get_active_id() self._ext_settings.icon_theme = self._icon_theme_combo_box.get_active_id() @@ -349,6 +353,7 @@ class SettingsDialog: self._ext_settings.new_color = self._new_color_button.get_rgba().to_string() self._ext_settings.extra_color = self._extra_color_button.get_rgba().to_string() self._ext_settings.v5_support = self._support_ver5_switch.get_active() + self._ext_settings.force_bq_names = self._force_bq_name_switch.get_active() self._ext_settings.http_api_support = self._support_http_api_switch.get_active() self._ext_settings.enable_yt_dl = self._enable_y_dl_switch.get_active() self._ext_settings.enable_send_to = self._enable_send_to_switch.get_active() @@ -428,6 +433,16 @@ class SettingsDialog: self._click_mode_zap_and_play_button.get_active())): self._click_mode_disabled_button.set_active(True) + def on_force_bq_name(self, switch, state): + if self._main_stack.get_visible_child_name() != "extra": + return + + if state: + msg = "Some images may have problems displaying the favorites list!" + self.show_info_message(msg, Gtk.MessageType.WARNING) + else: + self.on_info_bar_close() + def on_yt_dl_switch(self, switch, state): self.show_info_message("Not implemented yet!", Gtk.MessageType.WARNING)