Example #1
0
    def __FetchTextures(self):
        texturesToRetrieve = TextureHandler.Instance().NumberOfMissingTextures()

        if texturesToRetrieve > 0:
            w = None
            try:
                # show a blocking or background progress bar
                if texturesToRetrieve > 4:
                    w = XbmcDialogProgressWrapper(
                        "%s: %s" % (Config.appName, LanguageHelper.GetLocalizedString(LanguageHelper.InitChannelTitle)),
                        LanguageHelper.GetLocalizedString(LanguageHelper.FetchTexturesTitle),
                        # Config.TextureUrl
                    )
                else:
                    w = XbmcDialogProgressBgWrapper(
                        "%s: %s" % (Config.appName, LanguageHelper.GetLocalizedString(LanguageHelper.FetchTexturesTitle)),
                        Config.TextureUrl
                    )

                bytesTransfered = TextureHandler.Instance().FetchTextures(w.ProgressUpdate)
                if bytesTransfered > 0:
                    Statistics.RegisterCdnBytes(bytesTransfered)
            except:
                Logger.Error("Error fetching textures", exc_info=True)
            finally:
                if w is not None:
                    # always close the progress bar
                    w.Close()
        return
Example #2
0
    def __InitialiseChannelSet(self, channelInfo):
        # type: (ChannelInfo) -> None
        """ Initialises a channelset (.py file)

        WARNING: these actions are done ONCE per python file, not per channel.

        Arguments:
        channelInfo : ChannelInfo - The channelinfo

        Keyword Arguments:
        abortOnNew  : Boolean - If set to true, channel initialisation will not continue if a new channel was found.
                                This will have to be done later.

        Returns True if any operations where executed

        """

        Logger.Info("Initialising channel set at: %s.", channelInfo.path)

        # now import (required for the PerformFirstTimeActions
        sys.path.append(channelInfo.path)

        # make sure a pyo or pyc exists
        # __import__(channelInfo.moduleName)
        # The debugger won't compile if __import__ is used. So let's use this one.
        import py_compile
        py_compile.compile(os.path.join(channelInfo.path, "%s.py" % (channelInfo.moduleName,)))

        # purge the texture cache.
        TextureHandler.Instance().PurgeTextureCache(channelInfo)
        return
Example #3
0
    def GetImageLocation(self, image):
        """returns the path for a specific image name.

        Arguments:
        image : string - the filename of the requested argument.

        Returns:
        The full local path to the requested image.

        """

        # if Config.CdnUrl is None:
        #     return os.path.join(os.path.dirname(sys.modules[self.__module__].__file__), image)
        # return "%s%s" % (Config.CdnUrl, image)

        return TextureHandler.Instance().GetTextureUri(self, image)
Example #4
0
    def __GetImagePath(self, image):
        """ Tries to determine the path of an image

        Arguments:
        image : String - The filename (not path) of the image

        Returns the path of the image. In case of a XBMC skin image it will
        return just the filename, else the full path.

        """

        # if Config.CdnUrl is None:
        #     return os.path.join(self.path, image)
        #
        # return "%s%s" % (Config.CdnUrl, image)
        return TextureHandler.Instance().GetTextureUri(self, image)
Example #5
0
    def InitChannel(self):
        """Initializes the channel and will call some post processing stuff.

        This method is called for each add-on call and can be used to do some
        channel initialisation.

        """

        Logger.Debug("Initializing channel (InitChannel): %s", self)

        # Make sure all images are from the correct absolute location
        # self.icon = self.GetImageLocation(self.icon) -> already in the __init__
        # self.fanart = self.GetImageLocation(self.fanart) -> already in the __init__
        self.noImage = TextureHandler.Instance().GetTextureUri(self, self.noImage)

        # perhaps log on?
        self.loggedOn = self.LogOn(self.userName, self.passWord)

        if not self.loggedOn:
            Logger.Error('Not logged on...exiting')
            return False

        return
Example #6
0
    def __init__(self, channelInfo):
        """Initialisation of the class.

        Arguments:
        channelInfo: ChannelInfo - The channel info object to base this channel on.

        All class variables should be instantiated here and this method should not
        be overridden by any derived classes.

        """

        Logger.Info("Initializing channel (__init__): %s", channelInfo)

        self.mainListItems = []
        self.parentItem = None

        # The proxy to be used for this channel
        self.proxy = AddonSettings.GetProxyForChannel(channelInfo)

        # More and more API's need a specific set of headers. This set is used for the self.mainListUri, and is set to
        # all items generated by the chn_class.py.
        self.httpHeaders = dict()
        self.loggedOn = False

        # Initialize channel stuff from ChannelInfo object
        self.guid = channelInfo.guid

        self.channelName = channelInfo.channelName
        self.safeName = channelInfo.safeName
        self.channelCode = channelInfo.channelCode
        self.channelDescription = channelInfo.channelDescription
        self.moduleName = channelInfo.moduleName
        self.compatiblePlatforms = channelInfo.compatiblePlatforms
        self.sortOrder = channelInfo.sortOrder
        self.category = channelInfo.category
        self.language = channelInfo.language
        self.path = channelInfo.path

        # get the textures from the channelinfo and get their full uri's.
        self.icon = TextureHandler.Instance().GetTextureUri(self, channelInfo.icon)
        self.fanart = TextureHandler.Instance().GetTextureUri(self, channelInfo.fanart)

        # ============== Actual channel setup STARTS here and should be overwritten from derived classes ===============
        self.noImage = ""

        # set context menu items
        self.contextMenuItems = []

        # configure login stuff
        self.passWord = ""
        self.userName = ""
        self.logonUrl = ""
        self.requiresLogon = False

        # setup the urls
        self.mainListUri = ""
        self.baseUrl = ""
        self.swfUrl = ""

        # setup the main parsing data
        # self.dataHandlers = dict()
        # self.updateHandlers = dict()
        self.dataParsers = dict()

        self.episodeItemRegex = ''      # : used for the ParseMainList
        self.episodeItemJson = None     # : used for the ParseMainList
        self.videoItemRegex = ''        # : used for the ParseMainList
        self.videoItemJson = None       # : used for the ParseMainList
        self.folderItemRegex = ''       # : used for the CreateFolderItem
        self.folderItemJson = None      # : used for the CreateFolderItem
        self.mediaUrlRegex = ''         # : used for the UpdateVideoItem
        self.mediaUrlJson = None        # : used for the UpdateVideoItem

        """
            The ProcessPageNavigation method will parse the current data using the pageNavigationRegex. It will
            create a pageItem using the CreatePageItem method. If no CreatePageItem method is in the channel,
            a default one will be created with the number present in the resultset location specified in the
            pageNavigationRegexIndex and the url from the combined resultset. If that url does not contain http://
            the self.baseUrl will be added.
        """
        self.pageNavigationIndicationRegex = ''
        self.pageNavigationRegex = ''
        self.pageNavigationJson = None
        self.pageNavigationRegexIndex = 0
        self.pageNavigationJsonIndex = None

        #===============================================================================================================
        # non standard items

        #===============================================================================================================
        # Test cases:

        # ====================================== Actual channel setup STOPS here =======================================
        return
Example #7
0
    def __init__(self, channelInfo):
        """Initialisation of the class.

        Arguments:
        channelInfo: ChannelInfo - The channel info object to base this channel on.

        All class variables should be instantiated here and this method should not
        be overridden by any derived classes.

        """

        chn_class.Channel.__init__(self, channelInfo)

        # ============== Actual channel setup STARTS here and should be overwritten from derived classes ===============
        self.noImage = "vrtnuimage.png"
        self.mainListUri = "https://www.vrt.be/vrtnu/a-z/"
        self.baseUrl = "https://www.vrt.be"

        episodeRegex = '<a[^>]+href="(?<url>/vrtnu[^"]+)"[^>]*>(?:\W*<div[^>]*>\W*){2}' \
                       '<picture[^>]*>\W+(?:<[^>]+>\W*){3}<source[^>]+srcset="(?<thumburl>[^ ]+)' \
                       '[\w\W]{0,1000}?<h3[^>]+>(?<title>[^<]+)</h3>\W*<hr[^>]*>\W*' \
                       '(?:<div[^>]*>|<div[^>]*><p>)(?<description>[^<]+)(?:<br[^>]*>)?' \
                       '(?<descriptionMore>[^<]*)?(?:</div>|</p></div>)(?:\W*</div>){1}\W+' \
                       '(?:<div class="tile__brand"[^>]+>\W+<svg[^>]+>\W+<title[^<]+</title>\W+' \
                       '<use xlink:href="[^"]*#logo-(?<channel>[^"]+)"><.use>\W+</svg>\W+' \
                       '</div>){0,1}\W+</a>'
        episodeRegex = Regexer.FromExpresso(episodeRegex)
        self._AddDataParser(self.mainListUri, name="Main A-Z listing",
                            preprocessor=self.AddCategories,
                            matchType=ParserData.MatchExact,
                            parser=episodeRegex, creator=self.CreateEpisodeItem)

        self._AddDataParser("#channels", name="Main channel name listing",
                            preprocessor=self.ListChannels)

        self._AddDataParser("https://search.vrt.be/suggest?facets[categories]",
                            name="JSON Show Parser", json=True,
                            parser=(), creator=self.CreateShowItem)

        self._AddDataParser("https://services.vrt.be/videoplayer/r/live.json", json=True,
                            name="Live streams parser",
                            parser=(), creator=self.CreateLiveStream)
        self._AddDataParser("http://live.stream.vrt.be/",
                            name="Live streams updater",
                            updater=self.UpdateLiveVideo)
        self._AddDataParser("https://live-[^/]+\.vrtcdn\.be",
                            matchType=ParserData.MatchRegex,
                            name="Live streams updater",
                            updater=self.UpdateLiveVideo)

        catregex = '<a[^>]+href="(?<url>/vrtnu/categorieen/(?<catid>[^"]+)/)"[^>]*>(?:\W*<div[^>]' \
                   '*>\W*){2}<picture[^>]*>\W+(?:<[^>]+>\W*){3}<source[^>]+srcset="' \
                   '(?<thumburl>[^ ]+)[\w\W]{0,2000}?<h3[^>]+>(?<title>[^<]+)'
        catregex = Regexer.FromExpresso(catregex)
        self._AddDataParser("https://www.vrt.be/vrtnu/categorieen/", name="Category parser",
                            matchType=ParserData.MatchExact,
                            parser=catregex,
                            creator=self.CreateCategory)

        folderRegex = '<option[^>]+data-href="/(?<url>[^"]+)">(?<title>[^<]+)</option>'
        folderRegex = Regexer.FromExpresso(folderRegex)
        self._AddDataParser("*", name="Folder/Season parser",
                            parser=folderRegex, creator=self.CreateFolderItem)

        videoRegex = '<a[^>]+href="(?<url>/vrtnu[^"]+)"[^>]*>(?:\W*<div[^>]*>\W*){2}<picture[^>]' \
                     '*>\W+(?:<[^>]+>\W*){3}<source[^>]+srcset="(?<thumburl>[^ ]+)[^>]*>\W*' \
                     '(?:<[^>]+>\W*){3}<img[^>]+>\W*(?:</\w+>\W*)+<div[^>]+>\W*<h3[^>]+>' \
                     '(?<title>[^<]+)</h3>[\w\W]{0,1000}?(?:<span[^>]+class="tile__broadcastdate' \
                     '--mobile[^>]*>(?<day>\d+)/(?<month>\d+)/?(?<year>\d+)?</span><span[^>]+' \
                     'tile__broadcastdate--other[^>]+>(?<subtitle_>[^<]+)</span></div>\W*<div>)?' \
                     '[^<]*<abbr[^>]+title'
        # No need for a subtitle for now as it only includes the textual date
        videoRegex = Regexer.FromExpresso(videoRegex)
        self._AddDataParser("*", name="Video item parser",
                            parser=videoRegex, creator=self.CreateVideoItem)

        # needs to be after the standard video item regex
        singleVideoRegex = '<picture[^>]*>\W+(?:<[^>]+>\W*){3}<source[^>]+srcset="(?<thumburl>' \
                           '[^ ]+)[\w\W]{0,4000}<span[^>]+id="title"[^>]*>(?<title>[^<]+)</span>' \
                           '\W*<span[^>]+>(?<description>[^<]+)'
        singleVideoRegex = Regexer.FromExpresso(singleVideoRegex)
        self._AddDataParser("*", name="Single video item parser",
                            parser=singleVideoRegex, creator=self.CreateVideoItem)

        self._AddDataParser("*", updater=self.UpdateVideoItem, requiresLogon=True)

        # ===============================================================================================================
        # non standard items
        self.__hasAlreadyVideoItems = False
        self.__currentChannel = None
        # The key is the channel live stream key
        self.__channelData = {
            "vualto_mnm": {
                "title": "MNM",
                "metaCode": "mnm",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "mnmfanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "mnmimage.jpg"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "mnmicon.png"),
            },
            "vualto_stubru": {
                "title": "Studio Brussel",
                "metaCode": "stubru",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "stubrufanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "stubruimage.jpg"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "stubruicon.png"),
            },
            "vualto_een": {
                "title": "E&eacute;n",
                "metaCode": "een",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "eenfanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "eenimage.png"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "eenlarge.png")
            },
            "vualto_canvas": {
                "title": "Canvas",
                "metaCode": "canvas",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "canvasfanart.png"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "canvasimage.png"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "canvaslarge.png")
            },
            "vualto_ketnet": {
                "title": "KetNet",
                "metaCode": "ketnet",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "ketnetfanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "ketnetimage.png"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "ketnetlarge.png")
            },
            "vualto_sporza": {  # not in the channel filter maps, so no metaCode
                "title": "Sporza",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "sporzafanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "sporzaimage.png"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "sporzalarge.png")
            },
            "ketnet-jr": {  # Not in the live channels
                "title": "KetNet Junior",
                "metaCode": "ketnet-jr",
                "fanart": TextureHandler.Instance().GetTextureUri(self, "ketnetfanart.jpg"),
                "thumb": TextureHandler.Instance().GetTextureUri(self, "ketnetimage.png"),
                "icon": TextureHandler.Instance().GetTextureUri(self, "ketnetlarge.png")
            }
        }

        # ===============================================================================================================
        # Test cases:

        # ====================================== Actual channel setup STOPS here =======================================
        return