From 639f6f2efd6490e0e0b17bf40df7db2a140bd560 Mon Sep 17 00:00:00 2001 From: Dimitar Tsenev Date: Thu, 5 Sep 2024 11:52:38 +0300 Subject: [PATCH] =?UTF-8?q?[Updated]=20Sync=20some=20of=20the=20code=20bet?= =?UTF-8?q?ween=20distros=20to=20allow=20cross=20plugin=E2=80=A6=20(#4062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Updated] Sync some of the code between distros to allow cross plugin usage * [Fixed] Compile issue --- lib/dvb/db.cpp | 10 + lib/dvb/metaparser.h | 2 +- .../Components/Converter/PliExtraInfo.py | 219 +++++++++--------- .../Components/Sources/CurrentService.py | 2 +- lib/python/Components/Sources/EventInfo.py | 45 ++-- lib/python/Tools/Directories.py | 17 +- lib/service/iservice.h | 1 + lib/service/service.cpp | 35 ++- lib/service/servicedvb.cpp | 8 + 9 files changed, 212 insertions(+), 127 deletions(-) diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 59c09690392..6ae262e67d9 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -219,6 +219,16 @@ RESULT eDVBService::getName(const eServiceReference &ref, std::string &name) name = m_service_name; else name = "(...)"; + + std::string res_name = ""; + std::string res_provider = ""; + eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); + name = res_name; + + if (!res_provider.empty() && m_provider_name.empty()) { + m_provider_name = res_provider; + } + return 0; } diff --git a/lib/dvb/metaparser.h b/lib/dvb/metaparser.h index 2b23b4b6bfd..76d13781061 100644 --- a/lib/dvb/metaparser.h +++ b/lib/dvb/metaparser.h @@ -15,7 +15,7 @@ class eDVBMetaParser eServiceReferenceDVB m_ref; int m_data_ok, m_time_create, m_packet_size, m_scrambled; - std::string m_name, m_description, m_tags, m_service_data; + std::string m_name, m_description, m_tags, m_service_data, m_prov; long long m_filesize, m_length; }; diff --git a/lib/python/Components/Converter/PliExtraInfo.py b/lib/python/Components/Converter/PliExtraInfo.py index 573cfbe5b82..b8174413239 100644 --- a/lib/python/Components/Converter/PliExtraInfo.py +++ b/lib/python/Components/Converter/PliExtraInfo.py @@ -360,110 +360,113 @@ def getText(self): if not info: return "" - if self.type == "CryptoInfo": - self.getCryptoInfo(info) - if config.usage.show_cryptoinfo.value: - return addspace(self.createCryptoBar(info)) + self.createCryptoSpecial(info) + try: + if self.type == "CryptoInfo": + self.getCryptoInfo(info) + if config.usage.show_cryptoinfo.value: + return addspace(self.createCryptoBar(info)) + self.createCryptoSpecial(info) + else: + return addspace(self.createCryptoBar(info)) + addspace(self.current_source) + self.createCryptoSpecial(info) + + if self.type == "CurrentCrypto": + self.getCryptoInfo(info) + return self.createCurrentCaidLabel(info) + + if self.type == "CryptoBar": + self.getCryptoInfo(info) + return self.createCryptoBar(info) + + if self.type == "CryptoSpecial": + self.getCryptoInfo(info) + return self.createCryptoSpecial(info) + + if self.type == "Resolution": + return self.createResolution(info) + + if self.type == "ResolutionString": + return addspace(self.createResolution(info)) + self.createGamma(info) + + if self.type == "VideoCodec": + return self.createVideoCodec(info) + + if self.type == "Gamma": + return self.createGamma(info) + + if self.updateFEdata: + feinfo = service.frontendInfo() + if feinfo: + self.feraw = feinfo.getAll(config.usage.infobar_frontend_source.value == "settings") + if self.feraw: + self.fedata = ConvertToHumanReadable(self.feraw) + + feraw = self.feraw + if not feraw: + feraw = info.getInfoObject(iServiceInformation.sTransponderData) + fedata = ConvertToHumanReadable(feraw) else: - return addspace(self.createCryptoBar(info)) + addspace(self.current_source) + self.createCryptoSpecial(info) - - if self.type == "CurrentCrypto": - self.getCryptoInfo(info) - return self.createCurrentCaidLabel(info) - - if self.type == "CryptoBar": - self.getCryptoInfo(info) - return self.createCryptoBar(info) - - if self.type == "CryptoSpecial": - self.getCryptoInfo(info) - return self.createCryptoSpecial(info) - - if self.type == "Resolution": - return self.createResolution(info) + fedata = self.fedata - if self.type == "ResolutionString": - return addspace(self.createResolution(info)) + self.createGamma(info) + if self.type == "All": + self.getCryptoInfo(info) + if config.usage.show_cryptoinfo.value: + return addspace(self.createProviderName(info)) + self.createTransponderInfo(fedata, feraw, info) + "\n" \ + + addspace(self.createCryptoBar(info)) + addspace(self.createCryptoSpecial(info)) + "\n" \ + + addspace(self.createPIDInfo(info)) + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) + else: + return addspace(self.createProviderName(info)) + self.createTransponderInfo(fedata, feraw, info) + "\n" \ + + addspace(self.createCryptoBar(info)) + self.current_source + "\n" \ + + addspace(self.createCryptoSpecial(info)) + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) - if self.type == "VideoCodec": - return self.createVideoCodec(info) + if self.type == "PIDInfo": + return self.createPIDInfo(info) - if self.type == "Gamma": - return self.createGamma(info) - - if self.updateFEdata: - feinfo = service.frontendInfo() - if feinfo: - self.feraw = feinfo.getAll(config.usage.infobar_frontend_source.value == "settings") - if self.feraw: - self.fedata = ConvertToHumanReadable(self.feraw) - - feraw = self.feraw - if not feraw: - feraw = info.getInfoObject(iServiceInformation.sTransponderData) - fedata = ConvertToHumanReadable(feraw) - else: - fedata = self.fedata - - if self.type == "All": - self.getCryptoInfo(info) - if config.usage.show_cryptoinfo.value: - return addspace(self.createProviderName(info)) + self.createTransponderInfo(fedata, feraw, info) + "\n" \ - + addspace(self.createCryptoBar(info)) + addspace(self.createCryptoSpecial(info)) + "\n" \ - + addspace(self.createPIDInfo(info)) + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) - else: - return addspace(self.createProviderName(info)) + self.createTransponderInfo(fedata, feraw, info) + "\n" \ - + addspace(self.createCryptoBar(info)) + self.current_source + "\n" \ - + addspace(self.createCryptoSpecial(info)) + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) - - if self.type == "PIDInfo": - return self.createPIDInfo(info) - - if not feraw: - return "" + if not feraw: + return "" - if self.type == "ServiceInfo": - return addspace(self.createProviderName(info)) + addspace(self.createTunerSystem(fedata)) + addspace(self.createFrequency(feraw)) + addspace(self.createPolarization(fedata)) \ - + addspace(self.createSymbolRate(fedata, feraw)) + addspace(self.createFEC(fedata, feraw)) + addspace(self.createModulation(fedata)) + addspace(self.createOrbPos(feraw)) \ - + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) + if self.type == "ServiceInfo": + return addspace(self.createProviderName(info)) + addspace(self.createTunerSystem(fedata)) + addspace(self.createFrequency(feraw)) + addspace(self.createPolarization(fedata)) \ + + addspace(self.createSymbolRate(fedata, feraw)) + addspace(self.createFEC(fedata, feraw)) + addspace(self.createModulation(fedata)) + addspace(self.createOrbPos(feraw)) \ + + addspace(self.createVideoCodec(info)) + addspace(self.createResolution(info)) + self.createGamma(info) - if self.type == "TransponderInfo": - return self.createTransponderInfo(fedata, feraw, info) + if self.type == "TransponderInfo": + return self.createTransponderInfo(fedata, feraw, info) - if self.type == "TransponderFrequency": - return self.createFrequency(feraw) + if self.type == "TransponderFrequency": + return self.createFrequency(feraw) - if self.type == "TransponderSymbolRate": - return self.createSymbolRate(fedata, feraw) + if self.type == "TransponderSymbolRate": + return self.createSymbolRate(fedata, feraw) - if self.type == "TransponderPolarization": - return self.createPolarization(fedata) + if self.type == "TransponderPolarization": + return self.createPolarization(fedata) - if self.type == "TransponderFEC": - return self.createFEC(fedata, feraw) + if self.type == "TransponderFEC": + return self.createFEC(fedata, feraw) - if self.type == "TransponderModulation": - return self.createModulation(fedata) + if self.type == "TransponderModulation": + return self.createModulation(fedata) - if self.type == "OrbitalPosition": - return self.createOrbPos(feraw) + if self.type == "OrbitalPosition": + return self.createOrbPos(feraw) - if self.type == "TunerType": - return self.createTunerType(feraw) + if self.type == "TunerType": + return self.createTunerType(feraw) - if self.type == "TunerSystem": - return self.createTunerSystem(fedata) + if self.type == "TunerSystem": + return self.createTunerSystem(fedata) - if self.type == "OrbitalPositionOrTunerSystem": - return self.createOrbPosOrTunerSystem(fedata, feraw) + if self.type == "OrbitalPositionOrTunerSystem": + return self.createOrbPosOrTunerSystem(fedata, feraw) - if self.type == "TerrestrialChannelNumber": - return self.createChannelNumber(fedata, feraw) + if self.type == "TerrestrialChannelNumber": + return self.createChannelNumber(fedata, feraw) - if self.type == "TransponderInfoMisPls": - return self.createMisPls(fedata) + if self.type == "TransponderInfoMisPls": + return self.createMisPls(fedata) - return _("invalid type") + return _("invalid type") + except: + return "FTA" text = property(getText) @@ -484,33 +487,35 @@ def getBool(self): if request_caid is None: return False + try: + if info.getInfo(iServiceInformation.sIsCrypted) != 1: + return False - if info.getInfo(iServiceInformation.sIsCrypted) != 1: - return False + data = self.ecmdata.getEcmData() - data = self.ecmdata.getEcmData() + if data is None: + return False - if data is None: - return False + current_caid = data[1] - current_caid = data[1] + available_caids = info.getInfoObject(iServiceInformation.sCAIDs) - available_caids = info.getInfoObject(iServiceInformation.sCAIDs) + for caid_entry in caid_data: + if caid_entry[3] == request_caid: + if request_selected: + if int(caid_entry[0], 16) <= int(current_caid, 16) <= int(caid_entry[1], 16): + return True + else: # request available + try: + for caid in available_caids: + if int(caid_entry[0], 16) <= caid <= int(caid_entry[1], 16): + return True + except: + pass - for caid_entry in caid_data: - if caid_entry[3] == request_caid: - if request_selected: - if int(caid_entry[0], 16) <= int(current_caid, 16) <= int(caid_entry[1], 16): - return True - else: # request available - try: - for caid in available_caids: - if int(caid_entry[0], 16) <= caid <= int(caid_entry[1], 16): - return True - except: - pass - - return False + return False + except: + return False boolean = property(getBool) diff --git a/lib/python/Components/Sources/CurrentService.py b/lib/python/Components/Sources/CurrentService.py index 17157b6256d..26d3b4cbdb2 100644 --- a/lib/python/Components/Sources/CurrentService.py +++ b/lib/python/Components/Sources/CurrentService.py @@ -1,5 +1,5 @@ from Components.PerServiceDisplay import PerServiceBase -from enigma import iPlayableService, iPlayableService +from enigma import iPlayableService, iPlayableService, eServiceCenter from Components.Sources.Source import Source from Components.Element import cached import NavigationInstance diff --git a/lib/python/Components/Sources/EventInfo.py b/lib/python/Components/Sources/EventInfo.py index cd780917583..a1b9d77f35b 100644 --- a/lib/python/Components/Sources/EventInfo.py +++ b/lib/python/Components/Sources/EventInfo.py @@ -2,7 +2,7 @@ from Components.PerServiceDisplay import PerServiceBase from Components.Element import cached -from enigma import iPlayableService, iServiceInformation, eServiceReference, eEPGCache +from enigma import iPlayableService, iServiceInformation, eServiceReference, eEPGCache, eServiceCenter from Components.Sources.Source import Source @@ -21,9 +21,9 @@ def __init__(self, info, now_or_next, service): self.m_ExtendedDescriptionNow = "" self.m_ExtendedDescriptionNext = "" self.m_Duration = 0 - self.m_Begin = int(time()) - - sTagTitle = info.getInfoString(iServiceInformation.sTagTitle) + self.m_Begin = time() + isPtr = not isinstance(service, eServiceReference) + sTagTitle = info.getInfoString(iServiceInformation.sTagTitle) if isPtr else info.getInfoString(service, iServiceInformation.sTagTitle) if sTagTitle: sTagTitleList = sTagTitle.split(" - ") element1 = sTagTitleList[0] if len(sTagTitleList) >= 1 else "" @@ -36,29 +36,29 @@ def __init__(self, info, now_or_next, service): self.m_EventNameNow = element1 + " - " + element2 self.m_EventNameNext = element3 - sTagGenre = info.getInfoString(iServiceInformation.sTagGenre) + sTagGenre = info.getInfoString(iServiceInformation.sTagGenre) if isPtr else info.getInfoString(service, iServiceInformation.sTagGenre) if sTagGenre: element4 = sTagGenre self.m_ShortDescriptionNow = element4 - sTagOrganization = info.getInfoString(iServiceInformation.sTagOrganization) + sTagOrganization = info.getInfoString(iServiceInformation.sTagOrganization) if isPtr else info.getInfoString(service, iServiceInformation.sTagOrganization) if sTagOrganization: element5 = sTagOrganization self.m_ExtendedDescriptionNow = element5 - sTagLocation = info.getInfoString(iServiceInformation.sTagLocation) + sTagLocation = info.getInfoString(iServiceInformation.sTagLocation) if isPtr else info.getInfoString(service, iServiceInformation.sTagLocation) if sTagLocation: element6 = sTagLocation self.m_ExtendedDescriptionNow += "\n\n" + element6 - seek = service and service.seek() + seek = service and isPtr and service.seek() if seek: length = seek.getLength() if length[0] == 0: - self.m_Duration = length[1] // 90000 + self.m_Duration = length[1] / 90000 position = seek.getPlayPosition() if position[0] == 0: - self.m_Begin = int(time()) - position[1] // 90000 + self.m_Begin = time() - position[1] / 90000 def getEventName(self): return self.m_EventNameNow if self.now_or_next == self.NOW else self.m_EventNameNext @@ -127,17 +127,23 @@ def __init__(self, navcore, now_or_next): }, with_event=True) self.now_or_next = now_or_next self.epgQuery = eEPGCache.getInstance().lookupEventTime + self.__service = None @cached def getEvent(self): - service = self.navcore.getCurrentService() - info = service and service.info() - ret = info and info.getEvent(self.now_or_next) + isPtr = not isinstance(self.__service, eServiceReference) + service = self.navcore.getCurrentService() if isPtr else self.__service + if isPtr: + info = service and service.info() + ret = info and info.getEvent(self.now_or_next) + else: + info = eServiceCenter.getInstance().info(self.__service) + ret = info and info.getEvent(self.__service, self.now_or_next) if info: if not ret or ret.getEventName() == "": - refstr = info.getInfoString(iServiceInformation.sServiceref) + refstr = info.getInfoString(iServiceInformation.sServiceref) if isPtr else self.__service.toString() ret = self.epgQuery(eServiceReference(refstr), -1, self.now_or_next and 1 or 0) - if not ret and refstr.split(':')[0] in ['4097', '5001', '5002', '5003']: # No EPG Try to get Meta + if not ret and refstr.split(':')[0] in ['4097', '5001', '5002', '5003']: # No EPG Try to get Meta ev = pServiceEvent(info, self.now_or_next, service) if ev.getEventName: return ev @@ -151,6 +157,15 @@ def gotEvent(self, what): else: self.changed((self.CHANGED_ALL,)) + def updateSource(self, ref): + if not ref: + self.__service = None + self.changed((self.CHANGED_CLEAR,)) + return + self.__service = ref + self.changed((self.CHANGED_ALL,)) + + def destroy(self): PerServiceBase.destroy(self) Source.destroy(self) diff --git a/lib/python/Tools/Directories.py b/lib/python/Tools/Directories.py index bb3ba7cc612..f598a5cc6c1 100644 --- a/lib/python/Tools/Directories.py +++ b/lib/python/Tools/Directories.py @@ -11,7 +11,11 @@ from xml.etree.ElementTree import Element, fromstring, parse -pathExists = os.path.exists + +from os.path import exists as pathExists, isdir as pathIsdir, isfile as pathIsfile, join as pathJoin + +from os import listdir + SCOPE_HOME = 0 # DEBUG: Not currently used in Enigma2. SCOPE_LANGUAGE = 1 @@ -560,6 +564,17 @@ def mediafilesInUse(session): def shellquote(s): return "'%s'" % s.replace("'", "'\\''") +def isPluginInstalled(pluginname, pluginfile="plugin", pluginType=None): + path = resolveFilename(SCOPE_PLUGINS) + pluginfolders = [name for name in listdir(path) if pathIsdir(pathJoin(path, name)) and name not in ["__pycache__"]] + if pluginType is None or pluginType in pluginfolders: + plugintypes = pluginType and [pluginType] or pluginfolders + for fileext in [".pyc", ".py"]: + for plugintype in plugintypes: + if pathIsfile(pathJoin(path, plugintype, pluginname, pluginfile + fileext)): + return True + return False + def sanitizeFilename(filename, maxlen=255): # 255 is max length in bytes in ext4 (and most other file systems) """Return a fairly safe version of the filename. diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 7af764044b6..411b3b94e04 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -49,6 +49,7 @@ class eServiceReference int flags; // flags will NOT be compared. inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); } + static RESULT parseNameAndProviderFromName(std::string &sourceName, std::string& name, std::string& prov); #ifndef SWIG int data[8]; diff --git a/lib/service/service.cpp b/lib/service/service.cpp index d4fd122ecf0..9c6e71fa325 100644 --- a/lib/service/service.cpp +++ b/lib/service/service.cpp @@ -25,6 +25,18 @@ static std::string encode(const std::string s) return res; } +RESULT eServiceReference::parseNameAndProviderFromName(std::string &sourceName, std::string& name, std::string& prov) { + prov = ""; + if (!sourceName.empty()) { + std::vector name_split = split(sourceName, "•"); + name = name_split[0]; + if (name_split.size() > 1) { + prov = name_split[1]; + } + } + return 0; +} + eServiceReference::eServiceReference(const std::string &string) { const char *c = string.c_str(); @@ -58,6 +70,13 @@ eServiceReference::eServiceReference(const std::string &string) path = string; name = string; } + + std::string res_name = ""; + std::string res_provider = ""; + eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); + name = res_name; + prov = res_provider; + eDebug("[eServiceReference] URL=%s name=%s", path.c_str(), name.c_str()); return; } @@ -112,6 +131,12 @@ eServiceReference::eServiceReference(const std::string &string) path = urlDecode(path); name = urlDecode(name); + + std::string res_name = ""; + std::string res_provider = ""; + eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); + name = res_name; + prov = res_provider; } std::string eServiceReference::toString() const @@ -134,8 +159,14 @@ std::string eServiceReference::toString() const ret += ':'; ret += encode(name); } - if (!prov.empty()) { - ret += "•" + prov; + + std::string fullName = ret; + std::string provPart = "•"; + if (!prov.empty()) + { + provPart += prov; + if (fullName.find(provPart) == std::string::npos) + fullName += provPart; } return ret; } diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index 5d13c565ac7..9f4b77d4ec8 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -382,6 +382,14 @@ RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, st } m_parser.m_name = name; } + + std::string res_name = ""; + std::string res_provider = ""; + eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); + name = res_name; + m_parser.m_name = name; + if (m_parser.m_prov.empty() && !ref.prov.empty()) m_parser.m_prov = ref.prov; + return 0; }