def AddEpisodePaging(self, data): """Performs pre-process actions for data processing/ Arguments: data : string - the retrieve data that was loaded for the current item and URL. Returns: A tuple of the data and a list of MediaItems that were generated. Accepts an data from the ProcessFolderList method, BEFORE the items are processed. Allows setting of parameters (like title etc) for the channel. Inside this method the <data> could be changed and additional items can be created. The return values should always be instantiated in at least ("", []). """ items = [] # we need to create page items. So let's just spoof the paging. Youtube has # a 50 max results per query limit. itemsPerPage = 50 data = UriHandler.Open(self.mainListUri, proxy=self.proxy) xml = xmlhelper.XmlHelper(data) nrItems = xml.GetSingleNodeContent("openSearch:totalResults") for index in range(1, int(nrItems), itemsPerPage): items.append(self.CreateEpisodeItem([index, itemsPerPage])) pass # Continue working normal! return data, items
def add_episode_paging(self, data): """ Performs pre-process actions for data processing. Accepts an data from the process_folder_list method, BEFORE the items are processed. Allows setting of parameters (like title etc) for the channel. Inside this method the <data> could be changed and additional items can be created. The return values should always be instantiated in at least ("", []). :param str data: The retrieve data that was loaded for the current item and URL. :return: A tuple of the data and a list of MediaItems that were generated. :rtype: tuple[str|JsonHelper,list[MediaItem]] """ items = [] # we need to create page items. So let's just spoof the paging. Youtube has # a 50 max results per query limit. items_per_page = 50 data = UriHandler.open(self.mainListUri, proxy=self.proxy) xml = xmlhelper.XmlHelper(data) nr_items = xml.get_single_node_content("openSearch:totalResults") for index in range(1, int(nr_items), items_per_page): items.append(self.create_episode_item([index, items_per_page])) # Continue working normal! return data, items
def CreateVideoItemHwInfo(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ xmlData = xmlhelper.XmlHelper(resultSet) title = xmlData.GetSingleNodeContent("title") # Retrieve an ID and create an URL like: http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=OHqu64Qnz9M url = xmlData.GetTagAttribute("enclosure", {'url': None}, {'type': 'video/youtube'}) Logger.Trace(url) item = mediaitem.MediaItem(title, url) item.icon = self.icon item.type = 'video' # date stuff date = xmlData.GetSingleNodeContent("pubDate") dayname, day, month, year, time, zone = date.split(' ', 6) month = DateHelper.GetMonthFromName(month, language="en") hour, minute, seconds = time.split(":") Logger.Trace("%s-%s-%s %s:%s", year, month, day, hour, minute) item.SetDate(year, month, day, hour, minute, 0) # # description stuff description = xmlData.GetSingleNodeContent("description") item.description = description # # thumbnail stuff item.thumb = self.noImage thumbUrls = xmlData.GetTagAttribute("enclosure", {'url': None}, {'type': 'image/jpg'}, firstOnly=False) for thumbUrl in thumbUrls: if thumbUrl != "" and "thumb" not in thumbUrl: item.thumb = thumbUrl # finish up item.complete = False return item
def create_video_item_hw_info(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ xml_data = xmlhelper.XmlHelper(result_set) title = xml_data.get_single_node_content("title") # Retrieve an ID and create an URL like: http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=OHqu64Qnz9M url = xml_data.get_tag_attribute("enclosure", {'url': None}, {'type': 'video/youtube'}) Logger.trace(url) item = MediaItem(title, url) item.icon = self.icon item.type = 'video' # date stuff date = xml_data.get_single_node_content("pubDate") dayname, day, month, year, time, zone = date.split(' ', 6) month = DateHelper.get_month_from_name(month, language="en") hour, minute, seconds = time.split(":") Logger.trace("%s-%s-%s %s:%s", year, month, day, hour, minute) item.set_date(year, month, day, hour, minute, 0) # # description stuff description = xml_data.get_single_node_content("description") item.description = description # # thumbnail stuff item.thumb = self.noImage thumb_urls = xml_data.get_tag_attribute("enclosure", {'url': None}, {'type': 'image/jpg'}, firstOnly=False) for thumb_url in thumb_urls: if thumb_url != "" and "thumb" not in thumb_url: item.thumb = thumb_url # finish up item.complete = False return item
def CreateVideoItem(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ # Logger.Trace(resultSet) xmlData = xmlhelper.XmlHelper(resultSet) title = xmlData.GetSingleNodeContent("title") url = xmlData.GetSingleNodeContent("link") description = xmlData.GetSingleNodeContent("description") description = description.replace("<![CDATA[ ", "").replace("]]>", "").replace( "<p>", "").replace("</p>", "\n") item = mediaitem.MediaItem(title, url) item.type = 'video' item.complete = False item.description = description item.thumb = self.noImage item.icon = self.icon date = xmlData.GetSingleNodeContent("pubDate") dateResult = Regexer.DoRegex("\w+, (\d+) (\w+) (\d+)", date)[-1] day = dateResult[0] monthPart = dateResult[1].lower() year = dateResult[2] try: monthLookup = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ] month = monthLookup.index(monthPart) + 1 item.SetDate(year, month, day) except: Logger.Error("Error matching month: %s", resultSet[4].lower(), exc_info=True) return item
def CreateVideoItem(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ xml = resultSet[0] xmlData = xmlhelper.XmlHelper(xml) title = xmlData.GetSingleNodeContent("title") eTitle = xmlData.GetSingleNodeContent("episodetitel") if not eTitle == title: title = "%s - %s" % (title, eTitle) thumb = xmlData.GetSingleNodeContent("thumbnail") url = xmlData.GetSingleNodeContent("movie") date = xmlData.GetSingleNodeContent("broadcastdatetime") desc = xmlData.GetSingleNodeContent("samenvattinglang") or title item = mediaitem.MediaItem(title, url) item.description = desc item.icon = self.icon item.thumb = thumb item.type = 'video' item.SetDate(date[0:4], date[5:7], date[8:10], date[11:13], date[14:16], date[17:20]) item.complete = False return item
def create_video_item(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ xml_data = xmlhelper.XmlHelper(result_set) title = xml_data.get_single_node_content("title") # Retrieve an ID and create an URL like: http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=OHqu64Qnz9M video_id = xml_data.get_single_node_content("id") last_slash = video_id.rfind(":") + 1 video_id = video_id[last_slash:] # The old url does no longer work: # url = "http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=%s" % (videoId,) url = "http://www.youtube.com/watch?v=%s" % (video_id, ) item = MediaItem(title, url) item.icon = self.icon item.type = 'video' # date stuff date = xml_data.get_single_node_content("published") year = date[0:4] month = date[5:7] day = date[8:10] hour = date[11:13] minute = date[14:16] # Logger.Trace("%s-%s-%s %s:%s", year, month, day, hour, minute) item.set_date(year, month, day, hour, minute, 0) # description stuff description = xml_data.get_single_node_content("media:description") item.description = description # thumbnail stuff thumb_url = xml_data.get_tag_attribute("media:thumbnail", {'url': None}, {'height': '360'}) # <media:thumbnail url="http://i.ytimg.com/vi/5sTMRR0_Wo8/0.jpg" height="360" width="480" time="00:09:52.500" xmlns:media="http://search.yahoo.com/mrss/" /> if thumb_url != "": item.thumb = thumb_url else: item.thumb = self.noImage # finish up item.complete = False return item