From aca4875ee6af3d44d48199bdacd29220c2c91f5e Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 20 Oct 2021 11:46:22 +0300 Subject: [PATCH] fixed data loading with hex flag values (#50) --- app/eparser/ecommons.py | 15 +++++++++++++++ app/eparser/enigma/lamedb.py | 2 +- app/ui/main.py | 2 +- app/ui/service_details_dialog.py | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/eparser/ecommons.py b/app/eparser/ecommons.py index 218616be..10bf936f 100644 --- a/app/eparser/ecommons.py +++ b/app/eparser/ecommons.py @@ -82,6 +82,21 @@ class Flag(Enum): def is_new(value: int): return value & 1 << 5 + @staticmethod + def parse(value: str) -> int: + """ Returns an int representation of the flag value. + + The flag value is usually represented by the number [int], + but can also be appear in hex format. + """ + if len(value) < 3: + return 0 + + value = value[2:] + if value.isdigit(): + return int(value) + return int(value, 16) + class Pids(Enum): VIDEO = "c:00" diff --git a/app/eparser/enigma/lamedb.py b/app/eparser/enigma/lamedb.py index f3d573a7..c493c02c 100644 --- a/app/eparser/enigma/lamedb.py +++ b/app/eparser/enigma/lamedb.py @@ -177,7 +177,7 @@ class LameDbReader: all_flags = srv[2].split(",") coded = CODED_ICON if list(filter(lambda x: x.startswith("C:"), all_flags)) else None flags = list(filter(lambda x: x.startswith("f:"), all_flags)) - hide = HIDE_ICON if flags and Flag.is_hide(int(flags[0][2:])) else None + hide = HIDE_ICON if flags and Flag.is_hide(Flag.parse(flags[0])) else None locked = LOCKED_ICON if s_id in blacklist else None package = list(filter(lambda x: x.startswith("p:"), all_flags)) diff --git a/app/ui/main.py b/app/ui/main.py index 4359b0d1..5f6ec109 100644 --- a/app/ui/main.py +++ b/app/ui/main.py @@ -1853,7 +1853,7 @@ class Application(Gtk.Application): flags = srv.flags_cas if flags: f_flags = list(filter(lambda x: x.startswith("f:"), flags.split(","))) - if f_flags and Flag.is_new(int(f_flags[0][2:])): + if f_flags and Flag.is_new(Flag.parse(f_flags[0])): background = self._NEW_COLOR s = srv._replace(picon=self._picons.get(srv.picon_id, None)) + (tooltip, background) diff --git a/app/ui/service_details_dialog.py b/app/ui/service_details_dialog.py index 3c835516..6015c5bf 100644 --- a/app/ui/service_details_dialog.py +++ b/app/ui/service_details_dialog.py @@ -259,7 +259,7 @@ class ServiceDetailsDialog: def init_enigma2_flags(self, flags): f_flags = list(filter(lambda x: x.startswith("f:"), flags)) if f_flags: - value = int(f_flags[0][2:]) + value = Flag.parse(f_flags[0]) self._keep_check_button.set_active(Flag.is_keep(value)) self._hide_check_button.set_active(Flag.is_hide(value)) self._use_pids_check_button.set_active(Flag.is_pids(value)) @@ -468,7 +468,7 @@ class ServiceDetailsDialog: extra_data = {Column.SRV_TOOLTIP: None, Column.SRV_BACKGROUND: None} if self._s_type is SettingsType.ENIGMA_2 and flags: f_flags = list(filter(lambda x: x.startswith("f:"), flags.split(","))) - if f_flags and Flag.is_new(int(f_flags[0][2:])): + if f_flags and Flag.is_new(Flag.parse(f_flags[0])): extra_data[Column.SRV_BACKGROUND] = self._new_color self._current_model.set(self._current_itr, extra_data)