Ejemplo n.º 1
0
    def OnActionFromContextMenu(self, action):
        """Peforms the action from a custom contextmenu

        Arguments:
        action : String - The name of the method to call

        """
        Logger.Debug("Performing Custom Contextmenu command: %s", action)

        item = Pickler.DePickleMediaItem(self.params[self.keywordPickle])
        if not item.complete:
            Logger.Debug("The contextmenu action requires a completed item. Updating %s", item)
            item = self.channelObject.ProcessVideoItem(item)

            if not item.complete:
                Logger.Warning("UpdateVideoItem returned an item that had item.complete = False:\n%s", item)

        # invoke
        functionString = "returnItem = self.channelObject.%s(item)" % (action,)
        Logger.Debug("Calling '%s'", functionString)
        try:
            exec functionString
        except:
            Logger.Error("OnActionFromContextMenu :: Cannot execute '%s'.", functionString, exc_info=True)
        return
Ejemplo n.º 2
0
    def RemoveFavourite(self):
        """Removes an item from the favourites"""

        # remove the item
        item = Pickler.DePickleMediaItem(self.params[self.keywordPickle])
        Logger.Debug("Removing favourite: %s", item)
        f = Favourites(Config.favouriteDir)
        f.Remove(self.channelObject, item)

        # refresh the list
        self.ShowFavourites(self.channelObject, replaceExisting=True)
        pass
Ejemplo n.º 3
0
    def AddFavourite(self):
        """Adds an item to the favourites"""

        # remove the item
        item = Pickler.DePickleMediaItem(self.params[self.keywordPickle])
        # no need for dates in the favourites
        # item.ClearDate()
        Logger.Debug("Adding favourite: %s", item)

        f = Favourites(Config.favouriteDir)
        if item.IsPlayable():
            action = self.actionPlayVideo
        else:
            action = self.actionListFolder

        # add the favourite
        f.Add(self.channelObject,
              item,
              self.__CreateActionUrl(self.channelObject, action, item))

        # we are finished, so just return
        return self.ShowFavourites(self.channelObject)
Ejemplo n.º 4
0
    def List(self, channel=None):
        """ Lists favourites. If a channel was specified it will limit them to that.

        @param channel: The channel to limit the favourites to.


        Returns a list of tupples (actionUrl, pickle)

        """

        favs = []

        if channel:
            pathMask = os.path.join(self.FavouriteFolder, "%s-*.xotfav" % (channel.guid,))
        else:
            pathMask = os.path.join(self.FavouriteFolder, "*.xotfav")

        Logger.Debug("Fetching favourites for mask: %s", pathMask)
        for fav in glob.glob(pathMask):
            Logger.Trace("Fetching %s", fav)

            fileHandle = None
            try:
                fileHandle = open(fav)
                channelName = fileHandle.readline().rstrip()
                name = fileHandle.readline().rstrip()
                actionUrl = fileHandle.readline().rstrip()
                pickle = fileHandle.readline()
                fileHandle.close()
            except:
                Logger.Error("Error fetching favourite", exc_info=True)
                if fileHandle and not fileHandle.closed:
                    fileHandle.close()
                raise

            if channelName == "" or name == "" or actionUrl == "" or pickle == "":
                Logger.Error("Apparently the file had too few lines, corrupt Favourite, removing it:\n"
                             "Pickle: %s\n"
                             "Channel: %s\n"
                             "Item: %s\n"
                             "ActionUrl: %s\n"
                             "Pickle: %s",
                             fav, channelName, name, actionUrl, pickle)

                # Remove the invalid favourite
                os.remove(fav)
                continue

            Logger.Debug("Found favourite: %s", name)
            item = Pickler.DePickleMediaItem(pickle)
            validationError = Pickler.Validate(item, logger=Logger.Instance())
            if validationError:
                Logger.Error("Invalid Pickled Item: %s\nRemoving favourite: %s", validationError, fav)

                # Remove the invalid favourite
                os.remove(fav)
                continue

            # add the channel name
            if channel is None:
                item.name = "%s [%s]" % (item.name, channelName)

            item.ClearDate()

            favs.append((actionUrl % (pickle,), item))
        return favs
Ejemplo n.º 5
0
    def PlayVideoItem(self):
        """Starts the videoitem using a playlist. """

        Logger.Debug("Playing videoitem using PlayListMethod")

        item = None
        try:
            item = Pickler.DePickleMediaItem(self.params[self.keywordPickle])

            if item.isDrmProtected and AddonSettings.ShowDrmWarning():
                Logger.Debug("Showing DRM Warning message")
                title = LanguageHelper.GetLocalizedString(LanguageHelper.DrmTitle)
                message = LanguageHelper.GetLocalizedString(LanguageHelper.DrmText)
                XbmcWrapper.ShowDialog(title, message)
            elif item.isDrmProtected:
                Logger.Debug("DRM Warning message disabled by settings")

            if not item.complete:
                item = self.channelObject.ProcessVideoItem(item)

            # validated the updated item
            if not item.complete or not item.HasMediaItemParts():
                Logger.Warning("UpdateVideoItem returned an item that had item.complete = False:\n%s", item)
                Statistics.RegisterError(self.channelObject, item=item)

            if not item.HasMediaItemParts():
                # the update failed or no items where found. Don't play
                XbmcWrapper.ShowNotification(LanguageHelper.GetLocalizedString(LanguageHelper.ErrorId),
                                             LanguageHelper.GetLocalizedString(LanguageHelper.NoStreamsId),
                                             XbmcWrapper.Error)
                Logger.Warning("Could not start playback due to missing streams. Item:\n%s", item)
                return

            playData = self.channelObject.PlayVideoItem(item)

            Logger.Debug("Continuing playback in plugin.py")
            if not playData:
                Logger.Warning("PlayVideoItem did not return valid playdata")
                return
            else:
                playList, srt = playData

            # Get the Kodi Player instance (let Kodi decide what player, see
            # http://forum.kodi.tv/showthread.php?tid=173887&pid=1516662#pid1516662)
            xbmcPlayer = xbmc.Player()

            # now we force the busy dialog to close, else the video will not play and the
            # setResolved will not work.
            xbmc.executebuiltin("Dialog.Close(busydialog)")

            resolvedUrl = None
            if item.IsResolvable():
                # now set the resolve to the first URL
                startIndex = playList.getposition()  # the current location
                if startIndex < 0:
                    startIndex = 0
                Logger.Info("Playing stream @ playlist index %s using setResolvedUrl method", startIndex)
                resolvedUrl = playList[startIndex].getfilename()
                xbmcplugin.setResolvedUrl(self.handle, True, playList[startIndex])
            else:
                # playlist do not use the setResolvedUrl
                Logger.Info("Playing stream using Playlist method")
                xbmcPlayer.play(playList)

            # the set the subtitles
            showSubs = AddonSettings.UseSubtitle()
            if srt and (srt != ""):
                Logger.Info("Adding subtitle: %s and setting showSubtitles to %s", srt, showSubs)
                XbmcWrapper.WaitForPlayerToStart(xbmcPlayer, logger=Logger.Instance(), url=resolvedUrl)

                xbmcPlayer.setSubtitles(srt)
                xbmcPlayer.showSubtitles(showSubs)

        except:
            if item:
                Statistics.RegisterError(self.channelObject, item=item)
            else:
                Statistics.RegisterError(self.channelObject)

            XbmcWrapper.ShowNotification(LanguageHelper.GetLocalizedString(LanguageHelper.ErrorId),
                                         LanguageHelper.GetLocalizedString(LanguageHelper.NoPlaybackId),
                                         XbmcWrapper.Error)
            Logger.Critical("Could not playback the url", exc_info=True)

        return
Ejemplo n.º 6
0
    def ProcessFolderList(self):
        """Wraps the channel.ProcessFolderList"""

        Logger.Info("Plugin::ProcessFolderList Doing ProcessFolderList")
        try:
            ok = True

            selectedItem = None
            if self.keywordPickle in self.params:
                selectedItem = Pickler.DePickleMediaItem(self.params[self.keywordPickle])

            watcher = stopwatch.StopWatch("Plugin ProcessFolderList", Logger.Instance())
            episodeItems = self.channelObject.ProcessFolderList(selectedItem)
            watcher.Lap("Class ProcessFolderList finished")

            if len(episodeItems) == 0:
                Logger.Warning("ProcessFolderList returned %s items", len(episodeItems))
                ok = self.__ShowEmptyInformation(episodeItems)
            else:
                Logger.Debug("ProcessFolderList returned %s items", len(episodeItems))

            xbmcItems = []
            for episodeItem in episodeItems:
                if episodeItem.thumb == "":
                    episodeItem.thumb = self.channelObject.noImage
                if episodeItem.fanart == "":
                    episodeItem.fanart = self.channelObject.fanart

                if episodeItem.type == 'folder' or episodeItem.type == 'append' or episodeItem.type == "page":
                    action = self.actionListFolder
                    folder = True
                elif episodeItem.IsPlayable():
                    action = self.actionPlayVideo
                    folder = False
                else:
                    Logger.Critical("Plugin::ProcessFolderList: Cannot determine what to add")
                    continue

                # Get the XBMC item
                item = episodeItem.GetXBMCItem()
                # Get the context menu items
                contextMenuItems = self.__GetContextMenuItems(self.channelObject, item=episodeItem)
                item.addContextMenuItems(contextMenuItems)
                # Get the action URL
                url = self.__CreateActionUrl(self.channelObject, action=action, item=episodeItem)
                # Add them to the list of XBMC items
                xbmcItems.append((url, item, folder))

            watcher.Lap("Kodi Items generated")
            # add items but if OK was False, keep it like that
            ok = ok and xbmcplugin.addDirectoryItems(self.handle, xbmcItems, len(xbmcItems))
            watcher.Lap("items send to Kodi")

            if selectedItem is None:
                # mainlist item register channel.
                Statistics.RegisterChannelOpen(self.channelObject, Initializer.StartTime)
                watcher.Lap("Statistics send")

            watcher.Stop()

            self.__AddSortMethodToHandle(self.handle, episodeItems)

            # set the content
            xbmcplugin.setContent(handle=self.handle, content=self.contentType)

            xbmcplugin.endOfDirectory(self.handle, ok)
        except:
            Statistics.RegisterError(self.channelObject)
            XbmcWrapper.ShowNotification(LanguageHelper.GetLocalizedString(LanguageHelper.ErrorId),
                                         LanguageHelper.GetLocalizedString(LanguageHelper.ErrorList),
                                         XbmcWrapper.Error, 4000)
            Logger.Error("Plugin::Error Processing FolderList", exc_info=True)
            xbmcplugin.endOfDirectory(self.handle, False)