def Add(self, channel, item, actionUrl): """ Adds a favourite for a specific channel. @param channel: The channel @param item: The mediaitem @param actionUrl: The mediaitem's actionUrl Returns nothing """ Logger.Debug("Adding item %s\nfor channel %s\n%s", item, channel, actionUrl) fileName = self.__filePattern % (channel.guid, item.guid) filePath = os.path.join(self.FavouriteFolder, fileName) pickle = Pickler.PickleMediaItem(item) # Just double check for folder existence if not os.path.isdir(self.FavouriteFolder): os.makedirs(self.FavouriteFolder) # replacing to pickle in the actionUrl to save space actionUrl = actionUrl.replace(pickle, "%s") fileHandle = None try: fileHandle = open(filePath, mode='w') fileHandle.write("%s\n%s\n%s\n%s" % (channel.channelName, item.name, actionUrl, pickle)) fileHandle.close() except: Logger.Error("Error saving favourite", exc_info=True) if fileHandle and not fileHandle.closed: fileHandle.close() raise return
def __CreateActionUrl(self, channel, action, item=None, category=None): """Creates an URL that includes an action Arguments: channel : Channel - The channel object to use for the URL action : string - Action to create an url for Keyword Arguments: item : MediaItem - The media item to add """ if action is None: raise Exception("action is required") params = dict() if channel: params[self.keywordChannel] = channel.moduleName if channel.channelCode: params[self.keywordChannelCode] = channel.channelCode params[self.keywordAction] = action # it might have an item or not if item is not None: params[self.keywordPickle] = Pickler.PickleMediaItem(item) if action == self.actionPlayVideo and item.isLive: params[self.keywordRandomLive] = random.randint(10000, 99999) if category: params[self.keywordCategory] = category url = "%s?" % (self.pluginName, ) for k in params.keys(): url = "%s%s=%s&" % (url, k, params[k]) url = url.strip('&') # Logger.Trace("Created url: '%s'", url) return url