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 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]] """ # add live stuff live = MediaItem("\bLive streams", self.__liveUrl) live.icon = self.icon live.thumb = self.noImage live.complete = True live.HttpHeaders = self.__authenticationHeaders items = [live] return data, 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 """ 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_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.icon = self.icon 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 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.icon = self.icon sub_item.thumb = self.noImage sub_item.dontGroup = True sub_item.HttpHeaders = {"X-Requested-With": "XMLHttpRequest"} items.append(sub_item) return data, items
def create_main_list(self, data): """ Performs pre-process actions for data processing and creates the main menu list 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 = [] live = LanguageHelper.get_localized_string( LanguageHelper.LiveStreamTitleId) live_tv = "{} - TV".format(live) live_radio = "{} - Radio".format(live) links = { live_tv: "https://psapi.nrk.no/tv/live?apiKey={}".format(self.__api_key), live_radio: "https://psapi.nrk.no/radio/live?apiKey={}".format(self.__api_key), "Recommended": "https://psapi.nrk.no/medium/tv/recommendedprograms?maxnumber=100&startRow=0&apiKey={}" .format(self.__api_key), "Popular": "https://psapi.nrk.no/medium/tv/popularprogramssuper?maxnumber=100&startRow=0&apiKey={}" .format(self.__api_key), "Recent": "https://psapi.nrk.no/medium/tv/recentlysentprograms?maxnumber=100&startRow=0&apiKey={}" .format(self.__api_key), "Categories": "https://psapi.nrk.no/medium/tv/categories?apiKey={}".format( self.__api_key), "A - Å": "https://psapi.nrk.no/medium/tv/letters?apiKey={}".format( self.__api_key), "Søk": "#searchSite" } for name, url in links.items(): item = MediaItem(name, url) item.icon = self.icon item.thumb = self.noImage item.complete = True item.HttpHeaders = self.httpHeaders items.append(item) Logger.debug("Pre-Processing finished") return data, items
def create_movie(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) movie_id = result_set['id'] url = "%s/movies/%s" % (self.baseUrl, movie_id) item = MediaItem(result_set["name"], url) item.icon = self.icon item.thumb = result_set["thumb"].replace("nocropthumb/[format]/", "") item.complete = True item.HttpHeaders = self.httpHeaders if self.scheduleData: Logger.debug("Adding schedule data") schedule_data = [s for s in self.scheduleData if s['movieId'] == movie_id] schedule = "" day = "" for s in schedule_data: start = s['start'] day, start = start.split("T") hour, minute, ignore = start.split(":", 2) start = "%s:%s" % (hour, minute) end = s['end'] ignore, end = end.split("T") hour, minute, ignore = end.split(":", 2) end = "%s:%s" % (hour, minute) schedule = "%s%s-%s, " % (schedule, start, end) item.description = "%s\n\n%s: %s" % (item.description, day, schedule.strip(', ')) item.description = "%s\n\n%s" % (item.description, result_set.get('teaser', "")) if not item.description.endswith('.'): item.description = "%s." % (item.description, ) if "releaseDate" in result_set: item.description = "%s\n\nRelease datum: %s" % (item.description, result_set["releaseDate"]) # Dates? # date = result_set.get('releaseDate', None) # if date is not None: # year, month, day = date.split("-") # item.set_date(year, month, day) item.description = item.description.strip() 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 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 """ Logger.trace(result_set) is_serie_title = result_set["seriesTitle"] if not is_serie_title: return None if result_set["mediaType"] == "game": return None elif result_set["mediaType"] == "episode": title = "%(title)s (Episode)" % result_set else: title = result_set["title"] video_id = result_set["id"] url = "http://media.mtvnservices.com/pmt/e1/access/index.html?uri=mgid:%s:%s&configtype=edge" \ % (self.__mgid, video_id, ) item = MediaItem(title, url) item.description = result_set.get("description", None) item.type = "video" item.icon = self.icon item.fanart = self.fanart item.HttpHeaders = self.httpHeaders item.complete = False if "datePosted" in result_set: date = DateHelper.get_date_from_posix( float(result_set["datePosted"]["unixOffset"]) / 1000) item.set_date(date.year, date.month, date.day, date.hour, date.minute, date.second) if "images" in result_set: images = result_set.get("images", {}) thumbs = images.get("thumbnail", {}) item.thumb = thumbs.get("r16-9", self.noImage) 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 """ Logger.trace(result_set) # Validate the input and raise errors if not isinstance(result_set, dict): Logger.critical( "No Dictionary as a result_set. Implement a custom create_video_item" ) raise NotImplementedError( "No Dictionary as a result_set. Implement a custom create_video_item" ) elif "title" not in result_set or "url" not in result_set: Logger.warning("No ?P<title> or ?P<url> in result_set") raise LookupError("No ?P<title> or ?P<url> in result_set") # The URL url = self._prefix_urls(result_set["url"]) # The title if "subtitle" in result_set and result_set["subtitle"]: # noinspection PyStringFormat title = "%(title)s - %(subtitle)s" % result_set else: title = result_set["title"] if title.isupper(): title = title.title() item = MediaItem(title, url) item.thumb = self._prefix_urls(result_set.get("thumburl", "")) item.description = result_set.get("description", "") item.icon = self.icon item.type = 'video' item.fanart = self.fanart item.HttpHeaders = self.httpHeaders item.complete = False return item
def create_cinema(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) cinema = MediaItem(result_set["name"], "") cinema.icon = self.icon cinema.thumb = result_set["image"].replace("nocropthumb/[format]/", "") cinema.complete = True now_playing_url = "%s/cinemas/%s/movies/nowplaying" % ( self.baseUrl, result_set["id"]) now_playing = MediaItem("Trailers", now_playing_url) now_playing.icon = self.icon # https://www.pathe.nl/nocropthumb/[format]/gfx_content/bioscoop/foto/pathe.nl_380x218px_amersfoort.jpg now_playing.complete = True now_playing.HttpHeaders = self.httpHeaders cinema.items.append(now_playing) now = datetime.datetime.now() for i in range(0, 10): date = now + datetime.timedelta(days=i) title = "%s-%02d-%02d" % (date.year, date.month, date.day) schedule_url = "%s/cinemas/%s/schedules?date=%s" % ( self.baseUrl, result_set["id"], title) schedule = MediaItem("Agenda: %s" % (title, ), schedule_url) schedule.icon = self.icon schedule.complete = True schedule.thumb = cinema.thumb schedule.HttpHeaders = self.httpHeaders cinema.items.append(schedule) return cinema
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) # Validate the input and raise errors if not isinstance(result_set, dict): Logger.critical( "No Dictionary as a result_set. Implement a custom create_video_item" ) raise NotImplementedError( "No Dictionary as a result_set. Implement a custom create_video_item" ) elif "title" not in result_set or "url" not in result_set: Logger.warning("No ?P<title> or ?P<url> in result_set") raise LookupError("No ?P<title> or ?P<url> in result_set") # The URL url = self._prefix_urls(result_set["url"]) # The title title = result_set["title"] if title.isupper(): title = title.title() item = MediaItem(title, url) item.description = result_set.get("description", "") item.thumb = result_set.get("thumburl", "") item.icon = self.icon item.type = 'folder' item.fanart = self.fanart item.HttpHeaders = self.httpHeaders item.complete = True return item
def add_categories_and_specials(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]] """ Logger.info("Performing Pre-Processing") items = [] extras = { LanguageHelper.get_localized_string(LanguageHelper.Search): ("searchSite", None, False), LanguageHelper.get_localized_string(LanguageHelper.TvShows): ("http://webapi.tv4play.se/play/programs?is_active=true&platform=tablet" "&per_page=1000&fl=nid,name,program_image,is_premium,updated_at,channel&start=0", None, False) } # Channel 4 specific items if self.channelCode == "tv4se": extras.update({ LanguageHelper.get_localized_string(LanguageHelper.Categories): ("http://webapi.tv4play.se/play/categories.json", None, False), LanguageHelper.get_localized_string(LanguageHelper.MostViewedEpisodes): ("http://webapi.tv4play.se/play/video_assets/most_viewed?type=episode" "&platform=tablet&is_live=false&per_page=%s&start=0" % (self.maxPageSize, ), None, False), }) # if self.loggedOn: # extras.update({ # "\a.: Favoriter :.": ( # "http://www.tv4play.se/program/favourites", # None, True # ), # }) today = datetime.datetime.now() days = [ LanguageHelper.get_localized_string(LanguageHelper.Monday), LanguageHelper.get_localized_string(LanguageHelper.Tuesday), LanguageHelper.get_localized_string(LanguageHelper.Wednesday), LanguageHelper.get_localized_string(LanguageHelper.Thursday), LanguageHelper.get_localized_string(LanguageHelper.Friday), LanguageHelper.get_localized_string(LanguageHelper.Saturday), LanguageHelper.get_localized_string(LanguageHelper.Sunday) ] for i in range(0, 7, 1): start_date = today - datetime.timedelta(i) end_date = start_date + datetime.timedelta(1) day = days[start_date.weekday()] if i == 0: day = LanguageHelper.get_localized_string( LanguageHelper.Today) elif i == 1: day = LanguageHelper.get_localized_string( LanguageHelper.Yesterday) Logger.trace("Adding item for: %s - %s", start_date, end_date) # Old URL: # url = "http://webapi.tv4play.se/play/video_assets?exclude_node_nids=" \ # "nyheterna,v%C3%A4der,ekonomi,lotto,sporten,nyheterna-blekinge,nyheterna-bor%C3%A5s," \ # "nyheterna-dalarna,nyheterna-g%C3%A4vle,nyheterna-g%C3%B6teborg,nyheterna-halland," \ # "nyheterna-helsingborg,nyheterna-j%C3%B6nk%C3%B6ping,nyheterna-kalmar,nyheterna-link%C3%B6ping," \ # "nyheterna-lule%C3%A5,nyheterna-malm%C3%B6,nyheterna-norrk%C3%B6ping,nyheterna-skaraborg," \ # "nyheterna-skellefte%C3%A5,nyheterna-stockholm,nyheterna-sundsvall,nyheterna-ume%C3%A5," \ # "nyheterna-uppsala,nyheterna-v%C3%A4rmland,nyheterna-v%C3%A4st,nyheterna-v%C3%A4ster%C3%A5s," \ # "nyheterna-v%C3%A4xj%C3%B6,nyheterna-%C3%B6rebro,nyheterna-%C3%B6stersund,tv4-tolken," \ # "fotbollskanalen-europa" \ # "&platform=tablet&per_page=32&is_live=false&product_groups=2&type=episode&per_page=100" url = "http://webapi.tv4play.se/play/video_assets?exclude_node_nids=" \ "&platform=tablet&per_page=32&is_live=false&product_groups=2&type=episode&per_page=100" url = "%s&broadcast_from=%s&broadcast_to=%s&" % ( url, start_date.strftime("%Y%m%d"), end_date.strftime("%Y%m%d")) extras[day] = (url, start_date, False) extras[LanguageHelper.get_localized_string( LanguageHelper.CurrentlyPlayingEpisodes )] = ( "http://webapi.tv4play.se/play/video_assets?exclude_node_nids=&platform=tablet&" "per_page=32&is_live=true&product_groups=2&type=episode&per_page=100", None, False) for name in extras: title = name url, date, is_live = extras[name] item = MediaItem(title, url) item.dontGroup = True item.complete = True item.thumb = self.noImage item.HttpHeaders = self.httpHeaders item.isLive = is_live if date is not None: item.set_date(date.year, date.month, date.day, 0, 0, 0, text=date.strftime("%Y-%m-%d")) else: item.set_date(1901, 1, 1, 0, 0, 0, text="") items.append(item) if not self.channelCode == "tv4se": return data, items # Add Live TV # live = MediaItem("\a.: Live-TV :.", # "http://tv4events1-lh.akamaihd.net/i/EXTRAEVENT5_1@324055/master.m3u8", # type="video") # live.dontGroup = True # # live.isDrmProtected = True # live.isGeoLocked = True # live.isLive = True # items.append(live) Logger.debug("Pre-Processing finished") return data, items
def add_others(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]] """ Logger.info("Performing Pre-Processing") items = [] others = MediaItem( "\b.: Populair :.", "https://api.kijk.nl/v2/default/sections/popular_PopularVODs?offset=0" ) items.append(others) days = MediaItem("\b.: Deze week :.", "#lastweek") items.append(days) search = MediaItem("\b.: Zoeken :.", "searchSite") search.complete = True search.icon = self.icon search.thumb = self.noImage search.dontGroup = True search.HttpHeaders = {"X-Requested-With": "XMLHttpRequest"} items.append(search) if self.channelCode == "veronica": live = LanguageHelper.get_localized_string( LanguageHelper.LiveStreamTitleId) live_radio = MediaItem("Radio Veronica {}".format(live), "") live_radio.type = "video" live_radio.icon = self.icon live_radio.thumb = self.noImage live_radio.dontGroup = True part = live_radio.create_new_empty_media_part() live_stream = "https://talparadiohls-i.akamaihd.net/hls/live/585615/VR-Veronica-1/playlist.m3u8" if AddonSettings.use_adaptive_stream_add_on(with_encryption=False, channel=self): stream = part.append_media_stream(live_stream, 0) M3u8.set_input_stream_addon_input(stream, self.proxy) live_radio.complete = True else: for s, b in M3u8.get_streams_from_m3u8(live_stream, self.proxy): live_radio.complete = True part.append_media_stream(s, b) items.append(live_radio) Logger.debug("Pre-Processing finished") return data, items