Пример #1
0
    def AssignChannels(self, **kwargs):
        """
        Sets the TV Logos for the parsed channels

        :param kwargs: argument dic, need to have definitionalias, interface, configname, force
        """
        try:
            uAlias = ReplaceVars(kwargs['definitionalias'])
            uInterfaceName = ReplaceVars(kwargs['interface'])
            uConfigName = ReplaceVars(kwargs['configname'])
            bForce = ReplaceVars(kwargs['force']) != '0'
            oInterFace = Globals.oInterFaces.dInterfaces.get(uInterfaceName)
            oSetting = oInterFace.GetSettingObjectForConfigName(uConfigName)
            uContext = oSetting.uContext
            uSection = Globals.uDefinitionName

            dServices = self.dServices.get(uContext, {})
            aBouquets = dServices.get("Bouquets", [])
            for dBouquetDetail in aBouquets:
                iBouquetNumber = dBouquetDetail["BouquetNum"]
                if iBouquetNumber < 5:
                    uBouquetName = dBouquetDetail["Name"]
                    uVarName = uAlias + "_bouquet_name[" + str(
                        iBouquetNumber) + "]"
                    uVarValue = uBouquetName
                    Globals.oDefinitionConfigParser.set(
                        uSection, uVarName, EscapeUnicode(uVarValue))
                    SetVar(uVarName=uVarName, oVarValue=uVarValue)
                    dChannels = dBouquetDetail.get("Channels", {})
                    for iBouquetChannelNum in dChannels:
                        if iBouquetChannelNum < 30:
                            dChannel = dChannels[iBouquetChannelNum]
                            uVarName = uAlias + "%s[%d][%d]" % (
                                "_tvlogo", iBouquetNumber, iBouquetChannelNum)
                            if Globals.oDefinitionConfigParser.get(
                                    uSection,
                                    uVarName) == "discover" or bForce:
                                uVarValue = self.FindChannelLogo(
                                    dChannel["ChannelName"])
                                Globals.oDefinitionConfigParser.set(
                                    uSection, uVarName,
                                    EscapeUnicode(uVarValue))
                                SetVar(uVarName=uVarName, oVarValue=uVarValue)
                                uVarName = uAlias + "%s[%d][%d]" % (
                                    "_tvchannel", iBouquetNumber,
                                    iBouquetChannelNum)
                                uVarValue = str(dChannel["ChannelNum"])
                                Globals.oDefinitionConfigParser.set(
                                    uSection, uVarName, uVarValue)
                                SetVar(uVarName=uVarName, oVarValue=uVarValue)

            Globals.oDefinitionConfigParser.write()

        except Exception as e:
            self.ShowError("Can''t assign channelnumbers", e)
Пример #2
0
    def AdjustToTargetWiki(self,oWikiDoc:cWikiDoc) -> None:
        iIndex:int
        iPos:int
        uFileName:str
        uLine:str
        uLink:str

        self.uWikiApp = oWikiDoc.uWikiApp
        if oWikiDoc.uWikiApp == "GITWIKI":
            iIndex = -1
            for uLine in self.uContent:
                # replace the git links to files in the git repo
                iIndex += 1
                iPos = uLine.find("[[File:")
                if iPos>=0:
                    uFileName = uLine[iPos+7:uLine.find("|",iPos+1)]
                    oFile = oWikiDoc.dImageFileListBase.get(uFileName)
                    if oFile is not None:
                        uLink = EscapeUnicode(oWikiDoc.uHost+oFile.unixstring[oFile.unixstring.rfind("/src/"):])
                        uLine = uLine[:iPos+2]+uLink+uLine[uLine.find("]]",iPos):]
                    else:
                        LogError(uMsg=u'Wikidoc:unable to find linked filename: [%s] [%s] [%s]' % (uFileName,uLine,self.uPage))
                # adjust syntaxhighlighting to GIT Wiki

                uLine = uLine.replace('<div style="overflow-x: auto;"><syntaxhighlight  lang="xml">', '<div style="overflow-x: auto;">\n```xml')
                uLine = uLine.replace('</syntaxhighlight></div>',"```\n</div>")
                # uLine = uLine.replace('<div style="overflow-x: auto;"><syntaxhighlight  lang="xml">', '----<div style="overflow-x: auto;"><code><nowiki>')
                # uLine = uLine.replace('</syntaxhighlight></div>',"</nowiki></code></div>\r\n----")

                if "syntaxhighlight" in uLine:
                    Logger.warning("Unsupported Syntax Highlight: [%s] [%s] " %(self.uPage,uLine))
                self.uContent[iIndex]=uLine
Пример #3
0
    def CreateSettingsJSONString(self) -> None:
        """ Creates the json string for the settings dialog AND reads/writes the defaults to the config file """

        uSection: str = Globals.uDefinitionName
        uSection = uSection.replace(u' ', u'_')
        uVisSection: str
        oConfig: Config = Globals.oDefinitionConfigParser

        for uDefinitionKey in self:
            oDef = self[uDefinitionKey]
            uVisSection = oDef.uName
            if len(oDef.aDefinitionsSettings) > 0:
                uTitle: str = oDef.uDefPublicTitle
                for aSetting in oDef.aDefinitionsSettings:
                    uType: str = aSetting['type']

                    if uType == "section":
                        uVisSection = aSetting['title']
                        continue
                    if oDef.dDefinitionSettingsJSON.get(uVisSection) is None:
                        oDef.dDefinitionSettingsJSON[
                            uVisSection] = u'[{ "type": "title","title": "' + uTitle + '" }\n'
                        #oDef.dDefinitionSettingsJSON[uVisSection]=u'['

                    aSetting['section'] = uSection
                    uFormatString: str = self.dSettingFormatStrings.get(uType)
                    if uFormatString is None:
                        uFormatString = self.dSettingFormatStrings['default']
                    oDef.dDefinitionSettingsJSON[
                        uVisSection] += uFormatString.format(**aSetting)
                    uVar: str = aSetting['var']
                    uDefault: str = self.dSettingsDefaults[uVar]
                    #uDefault=ReplaceVars(uDefault)
                    #todo temporary hack to bypass configparser unicode bug
                    uDefault = EscapeUnicode(uDefault)
                    #check for cookies
                    uCookie: str = aSetting["cookie"]
                    if uCookie != u"" and uDefault == "":
                        uDefault = Var_Load(uVarName=uCookie,
                                            uDefault="",
                                            uPrefix="")

                    # parse definition settings into vars
                    uValue: str = ReplaceVars(
                        Config_GetDefault_Str(oConfig=oConfig,
                                              uSection=uSection,
                                              uOption=uVar,
                                              vDefaultValue=uDefault))
                    #todo temporary hack to bypass configparser unicode bug
                    uValue = UnEscapeUnicode(uValue)
                    # Logger.debug("Loading Definition Config Setting into var: [%s]=[%s]" %(uVar,uValue))
                    SetVar(uVarName=uVar, oVarValue=uValue)
                    self.aDefinitionSettingVars.append(uVar)
            for uVisSection in oDef.dDefinitionSettingsJSON:
                if len(oDef.dDefinitionSettingsJSON[uVisSection]) > 0:
                    oDef.dDefinitionSettingsJSON[uVisSection] += u']'
        oConfig.write()
        return None
Пример #4
0
    def WriteDoc(self,uPath:cPath) -> None:
        """ writes the Wiki Doc File """

        oFileName:cFileName = cFileName(uPath) + (self.uPage+".mediawiki")
        # oFileName.Delete()
        f = open(oFileName.string, 'w')

        # _Header.md currently not working, so add it static
        if self.uWikiApp == "GITWIKI":
            f.write("[[https://github.com/thica/ORCA-Remote/blob/master/src/wikidoc/images/orca.png]]\r\n")

        for uLine in self.uContent:
            f.write(EscapeUnicode(uLine)+u"\n")
        f.close()
Пример #5
0
    def SaveRepositoryXML(self,uType:str,uDescription:str) -> None:
        """ Saves the main repository directory xml """

        oVal:Element
        uContent:str
        uRoot:str

        oPath:cPath= Globals.oPathTmp + "RepManager"
        oPath.Create()
        oPath=oPath+"repositories"
        oPath.Create()
        oPath=oPath+uType
        oPath.Create()
        oFnXml:cFileName=cFileName(oPath) +'repository.xml'

        oXMLRoot:Element    = Element('repository')
        oVal                = SubElement(oXMLRoot,'version')
        oVal.text           = '1.00'
        oVal                = SubElement(oXMLRoot,'type')
        oVal.text           = uType
        oVal                = SubElement(oXMLRoot,'description')
        oVal.text           = uDescription

        oXMLEntries:Element = SubElement(oXMLRoot,'entries')

        for oEntry in self.aRepManagerEntries:
            Logger.debug ('Saving Repository-Entry [%s]' % oEntry.oFnEntry.string)

            oEntry.oRepEntry.WriteToXMLNode(oXMLNode=oXMLEntries)
            for oSource in oEntry.oRepEntry.aSources:
                bZipParentDir:bool = cPath.CheckIsDir(uCheckName=oSource.uLocal)
                # Create according Zip
                if bZipParentDir:
                    uUpper:str          = os.path.basename(oSource.uSourceFile)
                    uFinalPath:str      = uType
                    oDest:cFileName     = cFileName().ImportFullPath(uFnFullName='%s/RepManager/repositories/%s/%s' % (Globals.oPathTmp.string, uFinalPath, uUpper))
                    uUpper1:str         = os.path.split(os.path.abspath(oSource.uLocal))[0]
                    uRoot           = AdjustPathToOs(uPath=ReplaceVars(uUpper1)+'/')
                    self.aZipFiles.append({'filename':oSource.uLocal,'dstfilename':oDest.string, 'removepath':uRoot, 'skipfiles':ToUnicode(oEntry.oRepEntry.aSkipFileNames)})
                else:
                    uDest:str = AdjustPathToOs(uPath='%s/RepManager/repositories/%s/%s.zip' % (Globals.oPathTmp.string, uType, os.path.splitext(os.path.basename(oSource.uLocal))[0]))
                    uRoot = AdjustPathToOs(uPath=Globals.oPathRoot.string + "/" + oSource.uTargetPath)
                    self.aZipFiles.append({'filename':oSource.uLocal,'dstfilename':uDest, 'removepath':uRoot})

        oFSFile     = open(oFnXml.string, 'w')
        uContent    = XMLPrettify(oElem=oXMLRoot)
        uContent    = ReplaceVars(uContent)
        oFSFile.write(EscapeUnicode(uContent))
        oFSFile.close()
Пример #6
0
    def AdjustToTargetWiki(self, oWikiDoc):
        self.uWikiApp = oWikiDoc.uWikiApp
        if oWikiDoc.uWikiApp == "GITWIKI":
            iIndex = -1
            for uLine in self.uContent:
                # replace the git links to files in the git repo
                iIndex = iIndex + 1
                iPos = uLine.find("[[File:")
                if iPos >= 0:
                    uFileName = uLine[iPos + 7:uLine.find("|", iPos + 1)]
                    oFile = oWikiDoc.dImageFileListBase.get(uFileName)
                    if oFile is not None:
                        uLink = EscapeUnicode(
                            oWikiDoc.uHost +
                            oFile.unixstring[oFile.unixstring.rfind("/src/"):])
                        uLine = uLine[:iPos +
                                      2] + uLink + uLine[uLine.
                                                         find("]]", iPos):]
                    else:
                        LogError(
                            u'Wikidoc:unable to find linked filename: [%s] [%s] [%s]'
                            % (uFileName, uLine, self.uPage))
                # adjust syntaxhighlighting to GIT Wiki

                # uLine = uLine.replace('<div style="overflow-x: auto;"><syntaxhighlight  lang="xml">', "'''xml")
                # uLine = uLine.replace('</syntaxhighlight></div>',"'''")
                uLine = uLine.replace(
                    '<div style="overflow-x: auto;"><syntaxhighlight  lang="xml">',
                    '----<div style="overflow-x: auto;"><code><nowiki>')
                uLine = uLine.replace('</syntaxhighlight></div>',
                                      "</nowiki></code></div>\r\n----")

                if "syntaxhighlight" in uLine:
                    Logger.warning("Unsupported Syntax Highlight: [%s] [%s] " %
                                   (self.uPage, uLine))
                self.uContent[iIndex] = uLine
                ''' https://github.com/thica/ORCA-Remote/blob/master/src/wikidoc/images/widgets/button/widget_button%20round%20framed%20pressed.png '''
Пример #7
0
    def ParseServices(self, **kwargs):
        """
        Needs to done first, Reads all services for a specific Enigma box into the script

        :param kwargs: argument dic, need to have resultvar, interface, configname
        :return: 0
        """
        try:
            uResultVar = kwargs['resultvar']
            # uDstVarName         = args['retvar']
            uInterfaceName = ReplaceVars(kwargs['interface'])
            uConfigName = ReplaceVars(kwargs['configname'])

            oInterFace = Globals.oInterFaces.dInterfaces.get(uInterfaceName)
            oSetting = oInterFace.GetSettingObjectForConfigName(uConfigName)
            uContext = oSetting.uContext

            self.ShowInfo("Parsing Services into " + uContext)

            if self.dServices.get(uContext) is not None:
                return 0

            uXmlContent = GetVar(uResultVar)
            uXmlContent = EscapeUnicode(uXmlContent)

            iBouquetNum = 0  # Order Number of the Channel
            iChannelNum = 0  # Absolute Channel num, through all Bouquets
            if uXmlContent:
                # oET_Root = fromstring(uXmlContent)
                # oXmlBouquets = oET_Root.find("e2bouquet")
                oXmlBouquets = fromstring(uXmlContent)
                dChannels = {}  # Bouquet independent list of all channels
                aBouquets = []  # List of all bouquets as dBouquetDetails
                for oXmlBouquet in oXmlBouquets:
                    if oXmlBouquet.tag == 'e2bouquet':  # we might get services as well
                        dBouquetDetails = {
                        }  # Element to decribe a single bouquet (number , name, containing channels)
                        dBouquetChannels = {
                        }  # Dict of all channels in a single bouquet, index is Bouquechannelnum
                        iBouquetChannelNum = 0
                        uBouquetName = GetXMLTextValue(
                            oXmlBouquet, "e2servicename", False,
                            "NoName" + str(iBouquetNum))
                        iBouquetNum += 1
                        oXmlServices = oXmlBouquet.find("e2servicelist")
                        for oXmlServiceDetails in oXmlServices:
                            dSingleChannel = {}  # details of a channel
                            iChannelNum += 1  # absolute channel num within all bouquets
                            iBouquetChannelNum += 1  # relative channel num in bouquet
                            uReference = GetXMLTextValue(
                                oXmlServiceDetails, "e2servicereference", True,
                                "NoName")
                            uChannelName = GetXMLTextValue(
                                oXmlServiceDetails, "e2servicename", False,
                                "NoName" + str(iChannelNum))
                            dSingleChannel["ChannelName"] = uChannelName
                            dSingleChannel["Reference"] = uReference
                            dSingleChannel["ChannelNum"] = iChannelNum
                            dSingleChannel[
                                "BouquetChannelNum"] = iBouquetChannelNum
                            dBouquetChannels[
                                iBouquetChannelNum] = dSingleChannel
                            dChannels[iChannelNum] = dSingleChannel

                            # print uContext,":",uChannelName,":",iChannelNum

                            # SetVar(uVarName=uDstVarName+"_channelservice["+str(iChannelNum)+"]",uContext=uContext,oVarValue=str(iChannelNum))
                        dBouquetDetails["Channels"] = dBouquetChannels
                        dBouquetDetails["Name"] = uBouquetName
                        dBouquetDetails["BouquetNum"] = iBouquetNum
                        aBouquets.append(dBouquetDetails)

                self.dServices[uContext] = {}
                self.dServices[uContext]["Bouquets"] = aBouquets
                self.dServices[uContext]["Channels"] = dChannels
                return 1
            else:
                self.ShowError("No Services Data in Source Var:" + uResultVar)
        except Exception as e:
            self.ShowError("Can''t parse services, invalid xml", e)
        return 0
Пример #8
0
 def set_value(self, section, key, value):
     value=EscapeUnicode(value)
     return super().set_value(section, key, value)
Пример #9
0
 def set_value(self, section, key, value):
     value = EscapeUnicode(value)
     return super(SettingPicture, self).set_value(section, key, value)
Пример #10
0
    def ExecuteActionGetSaveOrcaSetting(self, oAction: cAction) -> eReturnCode:
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-GetSaveOrcaSetting
        WikiDoc:TOCTitle:getsaveorcasetting
        = getsaveorcasetting =
        Reads or write a parameter from or into the definition.ini file or the ORCA ini file

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |getsaveorcasetting
        |-
        |configtype
        |type of the config: "ORCA" to read/write the ORCA ini file, otherwise the definition ini file will be used
        |-
        |varname
        |The value to write, if we do not read
        |-
        |retvar
        |The varname, where the ini file value should be read into. If retvar is empty, we just write a value without reading it.
        |-
        |nowrite
        |Doesn't write the setting immediatly. Helpful for bulk operations
        |}</div>
        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="" string="getsaveorcasetting" configtype="$var(DEFINITIONNAME)" varname="$dvar(definition_alias_enigma2)_GETCURRENTVOL" varvalue="1" />
        </syntaxhighlight></div>
        WikiDoc:End
        """

        self.oEventDispatcher.LogAction(uTxt=u'GetSaveOrcaSetting',
                                        oAction=oAction)
        uConfigType: str = ReplaceVars(
            oAction.dActionPars.get("configtype", ""))
        uVarName: str = ReplaceVars(oAction.dActionPars.get("varname", ""))
        uVarValue: str = oAction.dActionPars.get("varvalue", "")
        uRetVar: str = ReplaceVars(oAction.dActionPars.get("retvar", ""))
        bNoWrite: bool = ToBool(
            ReplaceVars(oAction.dActionPars.get("nowrite", "")))
        uSection: str

        if uVarValue != u'':
            if not "$lvar(" in uVarValue:
                uVarValue = ReplaceVars(uVarValue)
            else:
                uVarValue = uVarValue
        else:
            uVarValue = GetVar(uVarName=uVarName)

        # if uRetVar = "", we want to write
        if uRetVar == "":
            if uConfigType == "ORCA":
                Globals.oOrcaConfigParser.set(uConfigType, uVarName, uVarValue)
                if not bNoWrite:
                    Globals.oOrcaConfigParser.write()
            else:
                uSection = uConfigType
                uSection = uSection.replace(u' ', u'_')

                #todo: temporary hack to bypass configparser unicode error
                uVarValue = EscapeUnicode(uVarValue)

                Globals.oDefinitionConfigParser.set(uSection, uVarName,
                                                    uVarValue)
                Logger.debug("Writing Config Var [%s]:[%s] into [%s] " %
                             (uVarName, uVarValue, uConfigType))
                if not bNoWrite:
                    Globals.oDefinitionConfigParser.write()
            SetVar(uVarName=uVarName, oVarValue=uVarValue)
            return eReturnCode.Nothing

        # otherwise we want to read
        try:
            if uConfigType == "ORCA":
                uVarValue = Globals.oOrcaConfigParser.get(u'ORCA', uVarName)
            else:
                uSection = uConfigType
                uSection = uSection.replace(u' ', u'_')
                try:
                    uVarValue = Globals.oDefinitionConfigParser.get(
                        uSection, uVarName)
                except Exception:
                    Logger.warning(
                        "getsaveorcasetting: not var to read: [%s] from [%s] into Var [%s], returning empty value"
                        % (uVarName, uConfigType, uRetVar))

            #todo: temporary hack to bypass configparser unicode error
            uVarValue = UnEscapeUnicode(uVarValue)
            SetVar(uVarName=uRetVar, oVarValue=uVarValue)
            SetVar(uVarName=uRetVar, oVarValue=uVarValue, uContext=uConfigType)
            Logger.debug(
                "Pulled Config Var [%s]:[%s] from [%s] into Var [%s]" %
                (uVarName, uVarValue, uConfigType, uRetVar))
        except Exception as e:
            LogError(uMsg=u'Action: GetSaveOrcaSetting', oException=e)
            SetVar(uVarName=uRetVar, oVarValue=u'')
        return eReturnCode.Nothing
Пример #11
0
    def ParseMovieList(self, **kwargs) -> Dict:
        """
        Parses all movies

        :param kwargs: argument dic, need to have resultvar, interface, configname
        :return: Dict ret: 0 or 1 : 1=success
        """
        try:
            uResultVar: str = kwargs['resultvar']
            uInterfaceName: str = ReplaceVars(kwargs['interface'])
            uConfigName: str = ReplaceVars(kwargs['configname'])
            uReturnVar: str = kwargs['retvar']

            oInterFace: cBaseInterFace = Globals.oInterFaces.GetInterface(
                uInterfaceName)
            oSetting: cBaseInterFaceSettings = oInterFace.GetSettingObjectForConfigName(
                uConfigName=uConfigName)
            uContext: str = oSetting.uContext
            uXmlContent: str
            iMovieNum: int
            uMovieReference: str

            self.ShowInfo(uMsg="Parsing movies into " + uContext)

            # cache disabled
            # if self.dMovies.get(uContext) is not None:
            #     return {"ret":1}

            uXmlContent = GetVar(uResultVar)
            uXmlContent = EscapeUnicode(uXmlContent)

            iMovieNum = 0  # Order Number of the Channel
            if uXmlContent:
                oXmlMovies: Element = LoadXMLString(uXML=uXmlContent)
                self.dMovies[uContext] = {}
                dMovies: typeMovies = {}

                Var_DelArray("%s_%s[]" % (uReturnVar, 'reference'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'title'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'description'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'descriptionex'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'servicename'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'url_reference'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'time'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'date'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'date_time'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'length'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'filename'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'url_filename'))
                Var_DelArray("%s_%s[]" % (uReturnVar, 'index'))

                for oXmlMovie in oXmlMovies:
                    if oXmlMovie.tag == 'e2movie':  # we might get services as well
                        dMovieDetails: typeMoviedetails = {
                        }  # Element to describe a single movie (number , name, containing channels)
                        iMovieNum += 1  # absolute channel num within all bouquets
                        uMovieReference = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2servicereference",
                            bMandatory=True,
                            vDefault="N/A")
                        dMovieDetails["reference"] = uMovieReference
                        # noinspection Mypy
                        dMovieDetails["url_reference"] = urllib.parse.quote(
                            uMovieReference)
                        dMovieDetails["title"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2title",
                            bMandatory=False,
                            vDefault="No Title")
                        dMovieDetails["description"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2description",
                            bMandatory=False,
                            vDefault="")
                        dMovieDetails["descriptionex"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2descriptionextended",
                            bMandatory=False,
                            vDefault="")
                        dMovieDetails["servicename"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2servicename",
                            bMandatory=False,
                            vDefault="")
                        dMovieDetails["time"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2time",
                            bMandatory=False,
                            vDefault="")
                        dMovieDetails["length"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2length",
                            bMandatory=False,
                            vDefault="0:00")
                        dMovieDetails["filename"] = GetXMLTextValue(
                            oXMLNode=oXmlMovie,
                            uTag="e2filename",
                            bMandatory=False,
                            vDefault="")
                        # noinspection Mypy
                        dMovieDetails["url_filename"] = urllib.parse.quote(
                            dMovieDetails["filename"])
                        dMovieDetails["index"] = ("000" + str(iMovieNum))[-3]

                        iTime: int = ToInt(dMovieDetails["time"])
                        oTime: struct_time = datetime.fromtimestamp(
                            iTime, timezone.utc).timetuple()
                        sTime: str = Globals.oLanguage.GetLocalizedTime(
                            bWithSeconds=False, oTime=oTime)
                        sDate: str = Globals.oLanguage.GetLocalizedDate(
                            bLongDate=False,
                            bLongDay=False,
                            bLongMonth=False,
                            oTime=oTime)

                        dMovieDetails["time"] = sTime
                        dMovieDetails["date"] = sDate
                        dMovieDetails["date_time"] = sDate + " " + sTime

                        for uKey in dMovieDetails:
                            uTag = "%s_%s[%s]" % (uReturnVar, uKey, iMovieNum)
                            SetVar(uTag, dMovieDetails[uKey])
                            self.ShowDebug(uMsg="Got MovieDetail:" + uTag +
                                           ":" + dMovieDetails[uKey])

                        dMovies[uMovieReference] = dMovieDetails

                self.dMovies[uContext] = dMovies
                return {"ret": 1}
            else:
                self.ShowError(uMsg="No Movies Data in Source Var:" +
                               uResultVar)
        except Exception as e:
            self.ShowError(uMsg="Can''t parse movies, invalid xml",
                           uParConfigName=self.uConfigName,
                           oException=e)
        return {"ret": 0}
Пример #12
0
    def ParseServices(self, **kwargs) -> Dict:
        """
        Needs to done first, Reads all services for a specific Enigma box into the script

        :param kwargs: argument dic, need to have resultvar, interface, configname
        :return: Dict ret: 0 or 1 : 1=success
        """
        try:
            uResultVar: str = kwargs['resultvar']
            uInterfaceName: str = ReplaceVars(kwargs['interface'])
            uConfigName: str = ReplaceVars(kwargs['configname'])

            oInterFace: cBaseInterFace = Globals.oInterFaces.GetInterface(
                uInterfaceName)
            oSetting: cBaseInterFaceSettings = oInterFace.GetSettingObjectForConfigName(
                uConfigName=uConfigName)
            uContext: str = oSetting.uContext
            oXmlBouquet: Element

            self.ShowInfo(uMsg="Parsing Services into " + uContext)

            if self.dServices.get(uContext) is not None:
                return {"ret": 1}

            uXmlContent: str = GetVar(uResultVar)
            uXmlContent = EscapeUnicode(uXmlContent)

            iBouquetNum: int = 0  # Order Number of the Channel
            iBouquetChannelNum: int
            uBouquetName: str
            iChannelNum: int = 0  # Absolute Channel num, through all Bouquets
            uReference: str
            uChannelName: str
            oXmlServices: Element

            if uXmlContent:
                # oET_Root = fromstring(uXmlContent)
                # oXmlBouquets = oET_Root.find("e2bouquet")
                oXmlBouquets: Element = LoadXMLString(uXML=uXmlContent)
                dChannels: typeChannels = {
                }  # Bouquet independent list of all channels
                aBouquets: typeBouquetsList = [
                ]  # List of all bouquets as dBouquetDetails
                for oXmlBouquet in oXmlBouquets:
                    if oXmlBouquet.tag == 'e2bouquet':  # we might get services as well
                        dBouquetDetails: typeBouquetDetails = {
                        }  # Element to decribe a single bouquet (number , name, containing channels)
                        dBouquetChannels: typeBouquetChannels = {
                        }  # Dict of all channels in a single bouquet, index is Bouquechannelnum
                        iBouquetChannelNum = 0
                        uBouquetName = GetXMLTextValue(oXMLNode=oXmlBouquet,
                                                       uTag="e2servicename",
                                                       bMandatory=False,
                                                       vDefault="NoName" +
                                                       str(iBouquetNum))
                        iBouquetNum += 1
                        oXmlServices = cast(Element,
                                            oXmlBouquet.find("e2servicelist"))
                        for oXmlServiceDetails in oXmlServices:
                            dSingleChannel: typeSingleChannel = {
                            }  # details of a channel
                            iChannelNum += 1  # absolute channel num within all bouquets
                            iBouquetChannelNum += 1  # relative channel num in bouquet
                            uReference = GetXMLTextValue(
                                oXMLNode=oXmlServiceDetails,
                                uTag="e2servicereference",
                                bMandatory=True,
                                vDefault="NoName")
                            uChannelName = GetXMLTextValue(
                                oXMLNode=oXmlServiceDetails,
                                uTag="e2servicename",
                                bMandatory=False,
                                vDefault="NoName" + str(iChannelNum))
                            dSingleChannel["ChannelName"] = uChannelName
                            dSingleChannel["Reference"] = uReference
                            dSingleChannel["ChannelNum"] = iChannelNum
                            dSingleChannel[
                                "BouquetChannelNum"] = iBouquetChannelNum
                            dBouquetChannels[
                                iBouquetChannelNum] = dSingleChannel
                            dChannels[iChannelNum] = dSingleChannel
                            # SetVar(uVarName=uDstVarName+"_channelservice["+str(iChannelNum)+"]",uContext=uContext,oVarValue=str(iChannelNum))
                        dBouquetDetails["Channels"] = dBouquetChannels
                        dBouquetDetails["Name"] = uBouquetName
                        dBouquetDetails["BouquetNum"] = iBouquetNum
                        aBouquets.append(dBouquetDetails)

                self.dServices[uContext] = {}
                self.dServices[uContext]["Bouquets"] = aBouquets
                self.dServices[uContext]["Channels"] = dChannels
                return {"ret": 1}
            else:
                self.ShowError(uMsg="No Services Data in Source Var:" +
                               uResultVar)
        except Exception as e:
            self.ShowError(uMsg="Can''t parse services, invalid xml",
                           uParConfigName=self.uConfigName,
                           oException=e)
        return {"ret": 0}
Пример #13
0
    def AssignChannels(self, **kwargs) -> None:
        """
        Sets the TV Logos for the parsed channels

        :param kwargs: argument dic, need to have definitionalias, interface, configname, force
        """
        try:
            uAlias: str = ReplaceVars(kwargs['definitionalias'])
            uInterfaceName: str = ReplaceVars(kwargs['interface'])
            uConfigName: str = ReplaceVars(kwargs['configname'])
            uLogoPackFolderName = ReplaceVars(kwargs['logopackfoldername'])
            bForce: bool = ReplaceVars(kwargs['force']) != '0'
            oInterFace: cBaseInterFace = Globals.oInterFaces.GetInterface(
                uInterfaceName)
            oSetting: cBaseInterFaceSettings = oInterFace.GetSettingObjectForConfigName(
                uConfigName=uConfigName)
            uContext: str = oSetting.uContext
            uSection: str = Globals.uDefinitionName

            iMaxBouquets: int = 9
            iMaxChannelsPerBouquets: int = 27

            iBouquetNumber: int
            uBouquetName: str
            dBouquetDetail: Dict
            uVarName: str
            uVarValue: str
            dChannels: Dict[int, Dict]

            dServices: Dict[str,
                            Union[Dict,
                                  List]] = self.dServices.get(uContext, {})
            aBouquets: typeBouquetsList = dServices.get("Bouquets", [])

            if uLogoPackFolderName == u'':
                uLogoPackFolderName = self.GetLogoPack()

            for dBouquetDetail in aBouquets:
                iBouquetNumber = dBouquetDetail["BouquetNum"]
                if iBouquetNumber <= iMaxBouquets:
                    uBouquetName = dBouquetDetail["Name"]
                    uVarName = uAlias + "_bouquet_name[" + str(
                        iBouquetNumber) + "]"
                    uVarValue = uBouquetName
                    Globals.oDefinitionConfigParser.set(
                        uSection, uVarName, EscapeUnicode(uVarValue))
                    SetVar(uVarName=uVarName, oVarValue=uVarValue)
                    dChannels = dBouquetDetail.get("Channels", {})
                    for iBouquetChannelNum in dChannels:
                        if iBouquetChannelNum <= iMaxChannelsPerBouquets:
                            dChannel = dChannels[iBouquetChannelNum]
                            uVarName = uAlias + "%s[%d][%d]" % (
                                "_tvlogo", iBouquetNumber, iBouquetChannelNum)
                            if Globals.oDefinitionConfigParser.get(
                                    uSection,
                                    uVarName) == "discover" or bForce:
                                uVarValue = self.FindChannelLogo(
                                    uChannelName=dChannel["ChannelName"],
                                    uReference=dChannel["Reference"],
                                    uLogoPackFolderName=uLogoPackFolderName)
                                Globals.oDefinitionConfigParser.set(
                                    uSection, uVarName,
                                    EscapeUnicode(uVarValue))
                                SetVar(uVarName=uVarName, oVarValue=uVarValue)
                                uVarName = uAlias + "%s[%d][%d]" % (
                                    "_tvchannel", iBouquetNumber,
                                    iBouquetChannelNum)
                                uVarValue = str(dChannel["ChannelNum"])
                                Globals.oDefinitionConfigParser.set(
                                    uSection, uVarName, uVarValue)
                                SetVar(uVarName=uVarName, oVarValue=uVarValue)
            Globals.oDefinitionConfigParser.write()
            return None

        except Exception as e:
            self.ShowError(uMsg="Can''t assign channel numbers",
                           uParConfigName=self.uConfigName,
                           oException=e)
            return None