def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param dict[str,str|dict] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) url = "http://m.schooltv.nl/api/v1/programmas/%s/afleveringen.json?size=%s&sort=Nieuwste" % ( result_set['mid'], self.__PageSize) item = MediaItem(result_set['title'], url) item.thumb = result_set.get('image', self.noImage) item.description = result_set.get('description', None) age_groups = result_set.get('ageGroups', ['Onbekend']) item.description = "%s\n\nLeeftijden: %s" % (item.description, ", ".join(age_groups)) return item
def create_episode_item(self, result_set, append_subtitle=True): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :param bool append_subtitle: Should we append a subtitle? :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) url = result_set['href'] if not url.startswith("http"): url = "{}{}".format(self.baseUrl, url) title = result_set["title"] if title is None: title = self.parentItem.name elif append_subtitle and "subtitle" in result_set: title = "{} - {}".format(title, result_set["subtitle"]) item = MediaItem(title, url) item.description = result_set.get('synopsis', item.description) image_template = result_set.get("imageTemplate") item.fanart = image_template.replace("{recipe}", "1920x1080") item.thumb = image_template.replace("{recipe}", "608x342") return item
def add_live_channel_and_extract_data(self, data): """ Add the live channel and extract the correct data to process further. 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]] """ Logger.info("Performing Pre-Processing") items = [] title = LanguageHelper.get_localized_string( LanguageHelper.LiveStreamTitleId) item = MediaItem("\a.: {} :.".format(title), self.liveUrl) item.type = "folder" items.append(item) if not data: return "[]", items json_data = Regexer.do_regex( r"setupBroadcastArchive\('Tv',\s*([^;]+)\);", data) if isinstance(json_data, (tuple, list)) and len(json_data) > 0: Logger.debug("Pre-Processing finished") return json_data[0], items Logger.info("Cannot extract JSON data from HTML.") return data, items
def create_series_season_item(self, result_set): """ Creates a MediaItem of type 'folder' for a season 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 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 """ title = "Sesong {}".format(result_set["name"]) season_id = result_set["id"] if not result_set.get("hasOnDemandRightsEpisodes", True): return None parent_url, qs = self.parentItem.url.split("?", 1) url = "{}/seasons/{}/episodes?apiKey={}".format(parent_url, season_id, self.__api_key) item = MediaItem(title, url) item.type = 'folder' return item
def create_live_channel_item(self, result_set): """ Creates a MediaItem of type 'video' for live 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,dict|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 """ # noinspection PyTypeChecker url = "{}{}?apiKey={}".format(self.baseUrl, result_set["_links"]["manifest"]["href"], self.__api_key) live_data = result_set["_embedded"]["playback"] # type: dict item = MediaItem(live_data["title"], url) item.type = "video" item.isLive = True item.isGeoLocked = live_data.get("isGeoBlocked") # noinspection PyTypeChecker self.__get_image(live_data["posters"][0]["image"]["items"], "pixelWidth", "url") return item
def add_live_items(self, data): """ Performs pre-process actions for data processing and adds the live channels if present. 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 = [] if self.liveUrl: Logger.debug("Adding live item") live_item = MediaItem("\aLive TV", self.liveUrl) live_item.dontGroup = True items.append(live_item) return data, items
def get_main_list_items(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 = [] url_pattern = "https://api-live.dumpert.nl/mobile_api/json/video/%s/%s/" for page in range(0, 2): item = MediaItem("Toppertjes - Pagina %s" % (page + 1, ), url_pattern % ('toppers', page)) items.append(item) for page in range(0, 10): item = MediaItem("Filmpjes - Pagina %s" % (page + 1, ), url_pattern % ('latest', page)) items.append(item) item = MediaItem("Zoeken", "searchSite") items.append(item) return data, items
def create_search_program_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 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 """ Logger.trace(result_set) title = result_set["Title"] # Not used: uuid = result_set["Uuid"] abstract_key = result_set["AbstractKey"] url = "http://www.rtl.nl/system/s4m/vfd/version=1/d=pc/output=json/fun=getseasons/ak={}".format( abstract_key) item = MediaItem(title, url) time_stamp = result_set["LastBroadcastDate"] # =1546268400000 date_time = DateHelper.get_date_from_posix(int(time_stamp) / 1000) item.set_date(date_time.year, date_time.month, date_time.day, date_time.hour, date_time.minute, date_time.second) return item
def create_episode_json_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) title = "%(title)s" % result_set url = "https://urplay.se/api/bff/v1/series/{}".format(result_set["id"]) fanart = "https://assets.ur.se/id/%(id)s/images/1_hd.jpg" % result_set thumb = "https://assets.ur.se/id/%(id)s/images/1_l.jpg" % result_set item = MediaItem(title, url) item.thumb = thumb item.description = result_set.get("description") item.fanart = fanart 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 result_set: The result_set of the self.episodeItemRegex :type result_set: list[str]|dict[str,dict[str,dict]] :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ Logger.trace(result_set) if "fullengthSegment" in result_set and "segment" in result_set[ "fullengthSegment"]: video_id = result_set["fullengthSegment"]["segment"]["id"] geo_location = result_set["fullengthSegment"]["segment"][ "geolocation"] geo_block = False if "flags" in result_set["fullengthSegment"]["segment"]: geo_block = result_set["fullengthSegment"]["segment"][ "flags"].get("geoblock", None) Logger.trace("Found geoLocation/geoBlock: %s/%s", geo_location, geo_block) else: Logger.warning("No video information found.") return None url = "http://www.srf.ch/player/webservice/videodetail/index?id=%s" % ( video_id, ) item = MediaItem(result_set["titleFull"], url) item.type = "video" # noinspection PyTypeChecker item.thumb = result_set.get("segmentThumbUrl", None) # apparently only the 144 return the correct HEAD info # item.thumb = "%s/scale/width/288" % (item.thumb, ) # the HEAD will not return a size, so Kodi can't handle it # item.fanart = resultSet.get("imageUrl", None) item.description = result_set.get("description", "") date_value = str(result_set["time_published"]) # 2015-01-20 22:17:59" date_time = DateHelper.get_date_from_string(date_value, "%Y-%m-%d %H:%M:%S") item.set_date(*date_time[0:6]) item.icon = self.icon item.httpHeaders = self.httpHeaders item.complete = False return item
def create_video_item_new(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 result_set: The result_set of the self.episodeItemRegex :type result_set: list[str]|dict[str,str] :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ Logger.trace(result_set) videos = self.__get_nested_value(result_set, "Assets", "Video") if not videos: Logger.warning("No video information found.") return None video_infos = [vi for vi in videos if vi["fullLength"]] if len(video_infos) > 0: video_info = video_infos[0] else: Logger.warning("No full length video found.") return None # noinspection PyTypeChecker video_id = video_info["id"] url = "http://il.srgssr.ch/integrationlayer/1.0/ue/srf/video/play/%s.json" % ( video_id, ) item = MediaItem(result_set["title"], url) item.type = "video" item.thumb = self.__get_nested_value(video_info, "Image", "ImageRepresentations", "ImageRepresentation", 0, "url") item.description = self.__get_nested_value(video_info, "AssetMetadatas", "AssetMetadata", 0, "description") date_value = str(result_set["publishedDate"]) date_value = date_value[0:-6] # 2015-01-20T22:17:59" date_time = DateHelper.get_date_from_string(date_value, "%Y-%m-%dT%H:%M:%S") item.set_date(*date_time[0:6]) item.icon = self.icon item.httpHeaders = self.httpHeaders item.complete = False return item
def create_api_genre_type(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the API. 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 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 This works for: __typename=Genre """ item = MediaItem(result_set["name"], "#genre_item") item.fanart = self.fanart item.thumb = self.noImage item.metaData[self.__genre_id] = result_set["id"] return item
def create_api_selection_type(self, result_set): """ Creates a new MediaItem for the new GraphQL Api. 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. :param list[str]|dict result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None This works for: __typename=Selection """ if result_set["type"].lower() == "upcoming": return None item = MediaItem(result_set["name"], self.parentItem.url) item.metaData[self.__folder_id] = result_set["id"] item.metaData.update(self.parentItem.metaData) item.thumb = self.__get_thumb(result_set[self.__parent_images], width=720) item.fanart = self.__get_thumb(result_set[self.__parent_images]) return item
def add_search(self, data): """ Adds a search item. The return values should always be instantiated in at least ("", []). :param JsonHelper 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]] """ Logger.info("Performing Pre-Processing") items = [] title = "\a.: %s :." % (self.searchInfo.get( self.language, self.searchInfo["se"])[1], ) Logger.trace("Adding search item: %s", title) search_item = MediaItem(title, "searchSite") search_item.thumb = self.noImage search_item.fanart = self.fanart search_item.dontGroup = True items.append(search_item) Logger.debug("Pre-Processing finished") return data, items
def create_folder_item(self, result_set): """ Creates a MediaItem of type 'folder' 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) if self.parentItem.url.endswith(str(DateHelper.this_year())): return None url = "%s%s" % (self.baseUrl, result_set[3]) name = result_set[4] item = MediaItem(name.title(), url) day = result_set[0] month = result_set[1] month = DateHelper.get_month_from_name(month, "nl", short=False) year = result_set[2] item.set_date(year, month, day) item.complete = True return item
def create_json_season_item(self, result_set): """ Creates a MediaItem of type 'folder' 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) # { # "seasonNumber": 3, # "id": "season-3", # "episodesId": "achtergeslotendeuren.net5-season-3-episodes", # "clipsId": "achtergeslotendeuren.net5-season-3-clips", # "title": "Seizoen 3", # "format": "achtergeslotendeuren", # "channel": "net5", # "episodesLink": "https://api.kijk.nl/v1/default/seasons/achtergeslotendeuren.net5/3/episodes", # "clipsLink": "https://api.kijk.nl/v1/default/seasons/achtergeslotendeuren.net5/3/clips" # } # https://api.kijk.nl/v1/default/seasons/achtergeslotendeuren.net5/2/episodes?limit=100&offset=1 url = "{}?limit=100&offset=1".format(result_set["episodesLink"]) item = MediaItem(result_set["title"], url) item.fanart = self.parentItem.fanart item.thumb = self.parentItem.thumb return item
def search_site(self, url=None): """ Creates an list of items by searching the site. This method is called when the URL of an item is "searchSite". The channel calling this should implement the search functionality. This could also include showing of an input keyboard and following actions. The %s the url will be replaced with an URL encoded representation of the text to search for. :param str|None url: Url to use to search with a %s for the search parameters. :return: A list with search results as MediaItems. :rtype: list[MediaItem] """ items = [] if url is None: item = MediaItem("Search Not Implented", "", type='video') items.append(item) else: items = [] needle = XbmcWrapper.show_key_board() if needle: Logger.debug("Searching for '%s'", needle) # convert to HTML needle = HtmlEntityHelper.url_encode(needle) search_url = url % (needle, ) temp = MediaItem("Search", search_url) return self.process_folder_list(temp) return items
def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ url = parse.urljoin( self.baseUrl, HtmlEntityHelper.convert_html_entities(result_set[0])) name = result_set[1] if name == "Tags": return None if name == "Authors": return None if name == "Most Viewed": return None if name == "Top Rated": name = "Recent" url = "http://channel9.msdn.com/Feeds/RSS" else: url = "%s?sort=atoz" % (url, ) item = MediaItem(name, url) item.complete = True return item
def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) title = result_set.get("title") if not title: return None if title.islower(): title = "%s%s" % (title[0].upper(), title[1:]) link = result_set.get("feedLink") if not link.startswith("http"): link = parse.urljoin(self.baseUrl, link) item = MediaItem(title, link) item.complete = True return item
def create_page_item(self, result_set): """ Creates a MediaItem of type 'page' 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'page'. :rtype: MediaItem|None """ Logger.trace(result_set) next_page = result_set["next"] if not next_page: Logger.debug("No more items available") return None more = LanguageHelper.get_localized_string(LanguageHelper.MorePages) url = "%s=%s" % (self.parentItem.url.rsplit("=", 1)[0], next_page) item = MediaItem(more, url) item.complete = True return item
def create_alpha_item(self, result_set): """ Creates a MediaItem of type 'folder' using the Alpha chars available. It uses 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. :param list[str]|dict result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ program_count = result_set.get("availableInternationally", 0) if program_count <= 0: return None title = result_set["title"] url_part = title.lower() if url_part == "0-9": url_part = "$" url = "https://psapi.nrk.no/medium/tv/letters/{}/indexelements?onlyOnDemandRights=false&" \ "apiKey={}".format(url_part, self.__api_key) title = LanguageHelper.get_localized_string(LanguageHelper.StartWith) % (title, ) item = MediaItem(title, url) item.type = 'folder' return item
def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ if not result_set[0] == "": self.promotionId = result_set[0] Logger.debug("Setting PromotionId to: %s", result_set[0]) return None # <li><a href="(/guide/season/[^"]+)">(\d+)</a></li> # if (self.channelCode == "southpark"): # url = "%s/ajax/seasonepisode/%s" % (self.baseUrl, result_set[2]) # url = http://www.southpark.nl/feeds/full-episode/carousel/14/424b7b57-e459-4c9c-83ca-9b924350e94d # else: url = "%s/feeds/full-episode/carousel/%s/%s" % ( self.baseUrl, result_set[2], self.promotionId) item = MediaItem("Season %02d" % int(result_set[2]), url) item.complete = True return item
def create_instalment_season_item(self, result_set): """ Creates a MediaItem of type 'folder' for a season 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 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 """ title = result_set["title"] season_id = result_set["name"] if title != season_id: title = "{} - {}".format(season_id, title) url = "{}{}?apiKey={}".format(self.baseUrl, result_set["href"], self.__api_key) item = MediaItem(title, url) item.type = 'folder' return item
def create_single_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 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 """ if self.__hasAlreadyVideoItems: # we already have items, so don't show this one, it will be a duplicate return None result_set = result_set.replace('\\x27', "'") json_data = JsonHelper(result_set) url = self.parentItem.url title = json_data.get_value("name") description = HtmlHelper.to_text(json_data.get_value("description")) item = MediaItem(title, url, type="video") item.description = description return item
def create_page_item(self, result_set): """ Creates a MediaItem of type 'page' 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'page'. :rtype: MediaItem|None """ Logger.debug("Starting create_page_item") Logger.trace(result_set) url = result_set["href"] page = url.rsplit("=", 1)[-1] item = MediaItem(page, url) item.type = "page" Logger.trace("Created '%s' for url %s", item.name, item.url) return item
def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) genres = result_set[0] if self.__genre and self.__genre not in genres: Logger.debug("Item '%s' filtered due to genre: %s", result_set[2], genres) return None url = result_set[1] if "&" in url: url = HtmlEntityHelper.convert_html_entities(url) if not url.startswith("http:"): url = "%s%s" % (self.baseUrl, url) # get the ajax page for less bandwidth url = "%s?sida=1&sort=tid_stigande&embed=true" % (url, ) item = MediaItem(result_set[2], url) item.complete = True item.isGeoLocked = True return item
def alpha_listing(self, data): """ Creates a alpha listing with items pointing to the alpha listing on line. :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]] """ Logger.info("Generating an Alpha list for BBC") items = [] # https://www.bbc.co.uk/iplayer/a-z/a title_format = LanguageHelper.get_localized_string(LanguageHelper.StartWith) url_format = "https://www.bbc.co.uk/iplayer/a-z/%s" for char in "abcdefghijklmnopqrstuvwxyz0": if char == "0": char = "0-9" sub_item = MediaItem(title_format % (char.upper(),), url_format % (char,)) sub_item.complete = True sub_item.dontGroup = True sub_item.HttpHeaders = {"X-Requested-With": "XMLHttpRequest"} items.append(sub_item) return data, items
def extract_page_data(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 = [] json = JsonHelper(data) data = json.get_value("data") Logger.trace(data) if json.get_value("loadMore", fallback=False): url, page = self.parentItem.url.rsplit("/", 1) url = "{0}/{1}".format(url, int(page) + 1) page_item = MediaItem("{0}".format(int(page) + 2), url) page_item.type = "page" items.append(page_item) return data, items
def create_json_episode_item(self, result_set): """ Creates a new MediaItem for an episode. 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. :param dict result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) meta = result_set["meta"] name = meta["header"]["title"] url = "{}{}".format(self.baseUrl, result_set["url"]) item = MediaItem(name, url) item.description = meta.get("description") item.isGeoLocked = True media_info = result_set.get("media") if media_info is not None: item.thumb = media_info.get("image", {}).get("url") return item
def create_folder_item(self, result_set): """ Creates a MediaItem of type 'folder' 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. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) if result_set["Type"] == "sport": # http://www.foxsports.nl/video/filter/alle/tennis/ url = "%s/video/filter/fragments/1/alle/%s/" % (self.baseUrl, result_set["Url"]) elif result_set["Type"] == "meest_bekeken": url = "%s/video/filter/fragments/1/meer" % (self.baseUrl, ) else: # http://www.foxsports.nl/video/filter/samenvattingen/ url = "%s/video/filter/fragments/1/%s/" % (self.baseUrl, result_set["Url"]) title = result_set["Title"] if not title[0].isupper(): title = "%s%s" % (title[0].upper(), title[1:]) item = MediaItem(title, url) item.complete = True item.thumb = self.noImage item.fanart = self.fanart return item