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 """ Logger.trace(result_set) url = "%s%s" % (self.baseUrl, result_set["Url"]) item = MediaItem(result_set["Title"], url) item.type = "video" item.thumb = result_set["Thumb"] item.complete = False if self.parentItem is None: item.fanart = self.fanart else: item.fanart = self.parentItem.fanart return item
def add_search_and_genres(self, data): """ Performs pre-process actions for data processing and adds a search option and genres. 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]] """ Logger.info("Performing Pre-Processing") items = [] if self.parentItem is not None and "genre" in self.parentItem.metaData: self.__genre = self.parentItem.metaData["genre"] Logger.debug("Parsing a specific genre: %s", self.__genre) return data, items search_item = MediaItem("\a.: Sök :.", "searchSite") search_item.complete = True search_item.thumb = self.noImage search_item.dontGroup = True search_item.fanart = self.fanart # search_item.set_date(2099, 1, 1, text="") # -> No items have dates, so adding this will force a date sort in Retrospect items.append(search_item) genres_item = MediaItem("\a.: Genrer :.", "") genres_item.complete = True genres_item.thumb = self.noImage genres_item.dontGroup = True genres_item.fanart = self.fanart items.append(genres_item) # find the actual genres genre_regex = '<li[^>]+genre[^>]*><button[^>]+data-value="(?<genre>[^"]+)"[^>]*>' \ '(?<title>[^>]+)</button></li>' genre_regex = Regexer.from_expresso(genre_regex) genres = Regexer.do_regex(genre_regex, data) for genre in genres: if genre["genre"] == "all": continue genre_item = MediaItem(genre["title"], self.mainListUri) genre_item.complete = True genre_item.thumb = self.noImage genre_item.fanart = self.fanart genre_item.metaData = {"genre": genre["genre"]} genres_item.items.append(genre_item) Logger.debug("Pre-Processing finished") return data, items
def __create_json_episode_item(self, result_set, check_channel=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 dict[str,any] result_set: The result_set of the self.episodeItemRegex :param bool check_channel: Compare channel ID's and ignore that that do not match. :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) # make sure we use ID as GUID if "id" in result_set: result_set["guid"] = result_set["id"] if check_channel and self.channelId is not None: channels = [int(c["guid"]) for c in result_set.get("channels", [])] valid_channel_found = any( [c for c in channels if c in self.channelId]) if not valid_channel_found: Logger.trace("Found item for wrong channel %s instead of %s", channels, self.channelId) return None # For now we keep using the API, otherwise we need to do more complex VideoItem parsing if self.useNewPages: raise NotImplementedError("The 'slug' part is no longer working") # So this no longer works # category_slug = self.__categories[result_set["category"]]["guid"] # url = "%s/%s/%s" % (self.baseUrl, category_slug, result_set['slug']) else: url = "http://playapi.mtgx.tv/v3/videos?format=%(guid)s&order=-airdate&type=program" % result_set item = MediaItem(result_set['title'], url) # Find the possible images if "images" in result_set and "landscape" in result_set["images"]: image_url = result_set["images"]["landscape"]["href"] item.thumb = self.__get_thumb_image(image_url) item.fanart = self.__get_thumb_image(image_url, True) elif "image" in result_set: item.thumb = self.__get_thumb_image(result_set["image"]) elif "_links" in result_set and "image" in result_set["_links"]: thumb_data = result_set["_links"]["image"] item.thumb = self.__get_thumb_image(thumb_data['href']) item.fanart = self.__get_thumb_image(thumb_data['href'], True) item.isGeoLocked = result_set.get('onlyAvailableInSweden', False) return item
def __show_empty_information(self, items, favs=False): """ Adds an empty item to a list or just shows a message. @type favs: boolean @param items: :param list[MediaItem] items: The list of items. :param bool favs: Indicating that we are dealing with favourites. :return: boolean indicating to report the listing as succes or not. :rtype: ok """ if favs: title = LanguageHelper.get_localized_string(LanguageHelper.NoFavsId) else: title = LanguageHelper.get_localized_string(LanguageHelper.ErrorNoEpisodes) behaviour = AddonSettings.get_empty_list_behaviour() Logger.debug("Showing empty info for mode (favs=%s): [%s]", favs, behaviour) if behaviour == "error": # show error ok = False elif behaviour == "dummy" and not favs: # We should add a dummy items, but not for favs empty_list_item = MediaItem("- %s -" % (title.strip("."), ), "", type='video') if self.channelObject: empty_list_item.icon = self.channelObject.icon empty_list_item.thumb = self.channelObject.noImage empty_list_item.fanart = self.channelObject.fanart else: icon = Config.icon fanart = Config.fanart empty_list_item.icon = icon empty_list_item.thumb = fanart empty_list_item.fanart = fanart empty_list_item.dontGroup = True empty_list_item.description = "This listing was left empty intentionally." empty_list_item.complete = True # add funny stream here? # part = empty_list_item.create_new_empty_media_part() # for s, b in YouTube.get_streams_from_you_tube("", self.channelObject.proxy): # part.append_media_stream(s, b) # if we add one, set OK to True ok = True items.append(empty_list_item) else: ok = True XbmcWrapper.show_notification(LanguageHelper.get_localized_string(LanguageHelper.ErrorId), title, XbmcWrapper.Error, 2500) return ok
def add_categories(self, data): """ Adds categories to the main listings. 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 = [] if self.parentItem and "code" in self.parentItem.metaData: self.__currentChannel = self.parentItem.metaData["code"] Logger.info("Only showing items for channel: '%s'", self.__currentChannel) return data, items cat = MediaItem("\a.: Categoriën :.", "https://www.vrt.be/vrtnu/categorieen.model.json") cat.fanart = self.fanart cat.thumb = self.noImage cat.icon = self.icon cat.dontGroup = True items.append(cat) live = MediaItem("\a.: Live Streams :.", "https://services.vrt.be/videoplayer/r/live.json") live.fanart = self.fanart live.thumb = self.noImage live.icon = self.icon live.dontGroup = True live.isLive = True items.append(live) channel_text = LanguageHelper.get_localized_string(30010) channels = MediaItem("\a.: %s :." % (channel_text, ), "#channels") channels.fanart = self.fanart channels.thumb = self.noImage channels.icon = self.icon channels.dontGroup = True items.append(channels) Logger.debug("Pre-Processing finished") return data, items
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") total = '' for result in result_set: total = "%s%s" % (total, result) total = HtmlEntityHelper.strip_amp(total) if not self.pageNavigationRegexIndex == '': item = MediaItem(result_set[self.pageNavigationRegexIndex], parse.urljoin(self.baseUrl, total)) else: item = MediaItem("0", "") item.type = "page" item.fanart = self.fanart item.HttpHeaders = self.httpHeaders Logger.debug("Created '%s' for url %s", item.name, item.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
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 """ items = [] if 'next' in result_set: title = LanguageHelper.get_localized_string( LanguageHelper.MorePages) url = result_set['next'] item = MediaItem(title, url) item.fanart = self.parentItem.fanart item.thumb = self.parentItem.thumb items.append(item) return items
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 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_api_single_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=Episode """ title = result_set['name'] url = '{}{}'.format(self.baseUrl, result_set['urls']['svtplay']) item = MediaItem(title, url) item.type = "video" item.description = result_set.get('longDescription') image_info = result_set.get("image") if image_info: item.thumb = self.__get_thumb(image_info, width=720) item.fanart = self.__get_thumb(image_info) item.isGeoLocked = result_set['restrictions']['onlyAvailableInSweden'] 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' item.thumb = self.parentItem.thumb item.fanart = self.parentItem.fanart return item
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' item.thumb = self.parentItem.thumb item.fanart = self.parentItem.fanart return item
def create_category_item(self, result_set): """ Creates a MediaItem of type 'folder' for a category 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 """ title = result_set["displayValue"] category_id = result_set["id"] url = "https://psapi.nrk.no/medium/tv/categories/{}/indexelements?apiKey={}"\ .format(category_id, self.__api_key) item = MediaItem(title, url) item.icon = self.icon item.type = 'folder' item.fanart = self.fanart item.thumb = self.__category_thumbs.get(category_id.lower(), self.noImage) 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.icon = self.icon item.type = 'folder' item.fanart = self.fanart item.thumb = self.noImage return item
def create_live_item(self, result_set): """ Creates a new MediaItem for an live item. 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") link = result_set.get("streamurl") item = MediaItem(title, link) stream_type = result_set["type"] item.type = "video" if stream_type == "tv" else "audio" item.isLive = True item.thumb = result_set.get('screenshot') item.fanart = result_set.get('image') if "radio" in title.lower(): item.type = "audio" 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 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["title"].replace("-", " ").title() # http://www.nickjr.nl/data/propertyStreamPage.json?&urlKey=dora&apiKey=nl_global_Nickjr_web&page=1 url = "%s/data/propertyStreamPage.json?&urlKey=%s&apiKey=%s&page=1" % ( self.baseUrl, result_set["seriesKey"], self.__apiKey) item = MediaItem(title, url) item.icon = self.icon item.complete = True item.fanart = self.fanart item.HttpHeaders = self.httpHeaders 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_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.thumb = self.parentItem.thumb item.icon = self.icon item.fanart = self.parentItem.fanart item.complete = True return item
def __create_search_result(self, result_set, result_type): """ 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 :param str result_type: Either a Serie or Program :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ # Logger.trace(result_set) url = "https://urplay.se/{}/{}".format(result_type, result_set["slug"]) item = MediaItem(result_set["title"], url) asset_id = result_set["ur_asset_id"] item.thumb = "https://assets.ur.se/id/{}/images/1_hd.jpg".format( asset_id) item.fanart = "https://assets.ur.se/id/{}/images/1_l.jpg".format( asset_id) if result_type == "program": item.set_info_label("duration", result_set["duration"] * 60) item.type = "video" return item
def create_api_tvserie_type(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 """ if not self.__show_folders: return None url = result_set["urls"]["svtplay"] item = MediaItem(result_set['name'], "#program_item") item.metaData["slug"] = url item.isGeoLocked = result_set.get('restrictions', {}).get('onlyAvailableInSweden', False) item.description = result_set.get('longDescription') image_info = result_set.get("image") if image_info: item.thumb = self.__get_thumb(image_info, width=720) item.fanart = self.__get_thumb(image_info) 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 create_trailer(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 """ Logger.trace(result_set) url = self.parentItem.url item = MediaItem(result_set["caption"], url, "video") item.thumb = result_set["still"].replace("nocropthumb/[format]/", "") item.fanart = item.thumb item.append_single_stream(result_set['filename']) item.complete = True item.HttpHeaders = self.httpHeaders 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 list_channels(self, data): """ Lists all the available channels. :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 = [] for name, meta in self.__channelData.items(): if "metaCode" not in meta: continue channel = MediaItem(meta["title"], self.mainListUri) # noinspection PyArgumentList channel.fanart = meta.get("fanart", self.fanart) # noinspection PyArgumentList channel.thumb = meta.get("icon", self.icon) # noinspection PyArgumentList channel.icon = meta.get("icon", self.icon) channel.dontGroup = True channel.metaData["code"] = meta["metaCode"] items.append(channel) return data, items
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 item.thumb = self.parentItem.thumb item.fanart = self.parentItem.fanart return item
def create_category(self, result_set): """ Creates a new MediaItem for an category folder. 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 """ # https://search.vrt.be/suggest?facets[categories]=met-audiodescriptie url = "https://search.vrt.be/suggest?facets[categories]=%(name)s" % result_set title = result_set["title"] thumb = result_set["imageStoreUrl"] if thumb.startswith("//"): thumb = "https:{}".format(thumb) item = MediaItem(title, url) item.description = title item.thumb = thumb item.icon = self.icon item.type = 'folder' item.fanart = self.fanart item.HttpHeaders = self.httpHeaders item.complete = True return item
def add_live_streams(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 = [] if self.parentItem is None: live_item = MediaItem( "\a.: Live TV :.", "https://d5ms27yy6exnf.cloudfront.net/live/omroepflevoland/tv/index.m3u8" ) live_item.icon = self.icon live_item.thumb = self.noImage live_item.type = 'video' live_item.dontGroup = True now = datetime.datetime.now() live_item.set_date(now.year, now.month, now.day, now.hour, now.minute, now.second) items.append(live_item) live_item = MediaItem( "\a.: Live Radio :.", "https://d5ms27yy6exnf.cloudfront.net/live/omroepflevoland/radio/index.m3u8" ) live_item.icon = self.icon live_item.thumb = self.noImage live_item.type = 'video' live_item.dontGroup = True now = datetime.datetime.now() live_item.set_date(now.year, now.month, now.day, now.hour, now.minute, now.second) items.append(live_item) # add "More" more = LanguageHelper.get_localized_string(LanguageHelper.MorePages) current_url = self.parentItem.url if self.parentItem is not None else self.mainListUri url, page = current_url.rsplit("=", 1) url = "{}={}".format(url, int(page) + 1) item = MediaItem(more, url) item.thumb = self.noImage item.icon = self.icon item.fanart = self.fanart item.complete = True items.append(item) return data, items
def create_instalment_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|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["titles"]["title"] sub_title = result_set["titles"]["subtitle"] # noinspection PyTypeChecker if result_set.get("availability", {}).get("status", "available") != "available": Logger.debug("Found '%s' with a non-available status", title) return None url = "https://psapi.nrk.no/programs/{}?apiKey={}".format( result_set["prfId"], self.__api_key) item = MediaItem(title, url) item.type = 'video' item.thumb = self.__get_image(result_set["image"], "width", "url") item.fanart = self.parentItem.fanart # noinspection PyTypeChecker item.isGeoLocked = result_set.get("usageRights", {}).get( "geoBlock", {}).get("isGeoBlocked", False) if sub_title and sub_title.strip(): item.description = sub_title if "firstTransmissionDateDisplayValue" in result_set: Logger.trace("Using 'firstTransmissionDateDisplayValue' for date") day, month, year = result_set[ "firstTransmissionDateDisplayValue"].split(".") item.set_date(year, month, day) elif "usageRights" in result_set and "from" in result_set[ "usageRights"] and result_set["usageRights"][ "from"] is not None: Logger.trace("Using 'usageRights.from.date' for date") # noinspection PyTypeChecker date_value = result_set["usageRights"]["from"]["date"].split( "+")[0] time_stamp = DateHelper.get_date_from_string( date_value, date_format="%Y-%m-%dT%H:%M:%S") item.set_date(*time_stamp[0:6]) return item