From 9a24cae6263adcfd4a7fec17f311c707f1fe25ad Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 18 Aug 2021 19:46:47 +0300 Subject: [PATCH] added displaying sub bouquets support --- app/eparser/ecommons.py | 1 + app/eparser/enigma/blacklist.py | 32 ++++++++++++++++++++++++++-- app/eparser/enigma/bouquets.py | 30 ++++++++++++++++++++++---- app/eparser/enigma/lamedb.py | 32 ++++++++++++++++++++++++++-- app/ui/main.glade | 37 ++++++++++++++++++++++++++------- app/ui/main.py | 17 ++++++++------- 6 files changed, 126 insertions(+), 23 deletions(-) diff --git a/app/eparser/ecommons.py b/app/eparser/ecommons.py index 557aa4a0..1ddaa7a0 100644 --- a/app/eparser/ecommons.py +++ b/app/eparser/ecommons.py @@ -15,6 +15,7 @@ class BqServiceType(Enum): MARKER = "MARKER" # 64 SPACE = "SPACE" # 832 [hidden marker] ALT = "ALT" # Service with alternatives + BOUQUET = "BOUQUET" # Sub bouquet. Bouquet = namedtuple("Bouquet", ["name", "type", "services", "locked", "hidden", "file"]) diff --git a/app/eparser/enigma/blacklist.py b/app/eparser/enigma/blacklist.py index 19535c6c..040b8211 100644 --- a/app/eparser/enigma/blacklist.py +++ b/app/eparser/enigma/blacklist.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 Dmitriy Yefremov +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Dmitriy Yefremov +# + + """ This module used for parsing blacklist file Parent Lock/Unlock @@ -9,14 +37,14 @@ __FILE_NAME = "blacklist" def get_blacklist(path): with suppress(FileNotFoundError): - with open(path + __FILE_NAME, "r") as file: + with open(path + __FILE_NAME, "r", encoding="utf-8") as file: # filter empty values and "\n" return {*list(filter(None, (x.strip() for x in file.readlines())))} return {} def write_blacklist(path, channels): - with open(path + __FILE_NAME, "w") as file: + with open(path + __FILE_NAME, "w", encoding="utf-8") as file: if channels: file.writelines("\n".join(channels)) diff --git a/app/eparser/enigma/bouquets.py b/app/eparser/enigma/bouquets.py index 46704eb9..da33b41b 100644 --- a/app/eparser/enigma/bouquets.py +++ b/app/eparser/enigma/bouquets.py @@ -29,6 +29,7 @@ """ Module for working with Enigma2 bouquets. """ import re from collections import Counter +from enum import Enum from pathlib import Path from app.commons import log @@ -127,10 +128,24 @@ class BouquetsWriter: file.writelines(bouquet) +class ServiceType(Enum): + SERVICE = "0" + BOUQUET = "7" # Sub bouquet. + MARKER = "64" + SPACE = "832" # Hidden marker. + ALT = "134" # Alternatives. + + @classmethod + def _missing_(cls, value): + log("Error. No matching service type [{} {}] was found.".format(cls.__name__, value)) + return cls.SERVICE + + class BouquetsReader: """ Class for reading and parsing bouquets. """ _ALT_PAT = re.compile(".*alternatives\\.+(.*)\\.([tv|radio]+).*") _BQ_PAT = re.compile(".*userbouquet\\.+(.*)\\.+[tv|radio].*") + _SUB_BQ_PAT = re.compile(".*subbouquet\\.+(.*)\\.([tv|radio]+).*") _STREAM_TYPES = {"4097", "5001", "5002", "8193", "8739"} __slots__ = ["_path"] @@ -199,19 +214,26 @@ class BouquetsReader: log("The bouquet [{}] service [{}] has the wrong data format: [{}]".format(bq_name, num, srv)) continue - s_type = srv_data[1] - if s_type == "64": + s_type = ServiceType(srv_data[1]) + if s_type is ServiceType.MARKER: m_data, sep, desc = srv.partition("#DESCRIPTION") services.append(BouquetService(desc.strip() if desc else "", BqServiceType.MARKER, srv, num)) - elif s_type == "832": + elif s_type is ServiceType.SPACE: m_data, sep, desc = srv.partition("#DESCRIPTION") services.append(BouquetService(desc.strip() if desc else "", BqServiceType.SPACE, srv, num)) - elif s_type == "134": + elif s_type is ServiceType.ALT: alt = re.match(BouquetsReader._ALT_PAT, srv) if alt: alt_name, alt_type = alt.group(1), alt.group(2) alt_bq_name, alt_srvs = BouquetsReader.get_bouquet(path, alt_name, alt_type, "alternatives") services.append(BouquetService(alt_bq_name, BqServiceType.ALT, alt_name, tuple(alt_srvs))) + elif s_type is ServiceType.BOUQUET: + sub = re.match(BouquetsReader._SUB_BQ_PAT, srv) + if sub: + sub_name, sub_type = sub.group(1), sub.group(2) + sub_bq_name, sub_srvs = BouquetsReader.get_bouquet(path, sub_name, sub_type, "subbouquet") + bq = Bouquet(sub_bq_name, sub_type, tuple(sub_srvs), None, None, sub_name) + services.append(BouquetService(sub_bq_name, BqServiceType.BOUQUET, bq, num)) elif srv_data[0].strip() in BouquetsReader._STREAM_TYPES or srv_data[10].startswith(("http", "rtsp")): stream_data, sep, desc = srv.partition("#DESCRIPTION") desc = desc.lstrip(":").strip() if desc else srv_data[-1].strip() diff --git a/app/eparser/enigma/lamedb.py b/app/eparser/enigma/lamedb.py index e0ff943d..f3d573a7 100644 --- a/app/eparser/enigma/lamedb.py +++ b/app/eparser/enigma/lamedb.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 Dmitriy Yefremov +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Dmitriy Yefremov +# + + """ This module used for parsing and write lamedb file """ import re @@ -283,7 +311,7 @@ class LameDbWriter: def write(self): if self._fmt == 4: # Writing lamedb file ver.4 - with open(self._path + _FILE_NAME, "w") as file: + with open(self._path + _FILE_NAME, "w", encoding="utf-8") as file: file.writelines(LameDbReader.get_services_lines(self._services)) elif self._fmt == 5: self.write_to_lamedb5() @@ -308,7 +336,7 @@ class LameDbWriter: lines.extend(services_lines) lines.append(_END_LINE) - with open(self._path + "lamedb5", "w") as file: + with open(self._path + "lamedb5", "w", encoding="utf-8") as file: file.writelines(lines) diff --git a/app/ui/main.glade b/app/ui/main.glade index 8e3174bc..8db0dadc 100644 --- a/app/ui/main.glade +++ b/app/ui/main.glade @@ -1,5 +1,5 @@ -