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) title = result_set["title"] if title is None: Logger.warning("Found item with all <null> items. Skipping") return None if "subtitle" in result_set and result_set['subtitle'].lower( ) not in title.lower(): title = "%(title)s - %(subtitle)s" % result_set url = "http://m.schooltv.nl/api/v1/afleveringen/%(mid)s.json" % result_set item = MediaItem(title, url) item.description = result_set.get("description", "") age_groups = result_set.get('ageGroups', ['Onbekend']) item.description = "%s\n\nLeeftijden: %s" % (item.description, ", ".join(age_groups)) item.thumb = result_set.get("image", "") item.icon = self.icon item.type = 'video' item.fanart = self.fanart item.complete = False item.set_info_label("duration", result_set['duration']) if "publicationDate" in result_set: broadcast_date = DateHelper.get_date_from_posix( int(result_set['publicationDate'])) item.set_date(broadcast_date.year, broadcast_date.month, broadcast_date.day, broadcast_date.hour, broadcast_date.minute, broadcast_date.second) return item
def get_live_items(self, data): """ Adds live stream items. 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("Fetching episode items") items = [] live_items = MediaItem("\a.: Live TV :.", "") live_items.thumb = self.noImage live_items.icon = self.icon items.append(live_items) live_base = "http://il.srgssr.ch/integrationlayer/1.0/ue/srf/video/play/%s.json" live_channels = { "SRF 1 live": ("c4927fcf-e1a0-0001-7edd-1ef01d441651", "srf1.png"), "SRF zwei live": ("c49c1d64-9f60-0001-1c36-43c288c01a10", "srf2.png"), "SRF info live": ("c49c1d73-2f70-0001-138a-15e0c4ccd3d0", "srfinfo.png") } for live_item in live_channels.keys(): item = MediaItem(live_item, live_base % (live_channels[live_item][0], )) item.thumb = self.get_image_location(live_channels[live_item][1]) item.icon = self.icon item.isGeoLocked = True item.type = "video" live_items.items.append(item) return data, items
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) thumb_url = "%s%s" % (self.baseUrl, result_set[6]) url = "%s%s" % (self.baseUrl, result_set[5]) name = "%s %s %s %s" % (result_set[1], result_set[2], result_set[3], result_set[4]) video_url = result_set[0] video_url = video_url.replace(" ", "%20") # convert RTMP to HTTP #rtmp://media.omroepgelderland.nl /uitzendingen/video/2012/07/120714 338 Carrie on.mp4 #http://content.omroep.nl/omroepgelderland/uitzendingen/video/2012/07/120714 338 Carrie on.mp4 video_url = video_url.replace( "rtmp://media.omroepgelderland.nl", "http://content.omroep.nl/omroepgelderland") item = MediaItem(name, url) item.thumb = thumb_url item.icon = self.icon item.type = 'video' item.append_single_stream(video_url) # set date month = datehelper.DateHelper.get_month_from_name( result_set[3], "nl", False) day = result_set[2] year = result_set[4] item.set_date(year, month, day) item.complete = True return item
def create_category_item(self, result_set): """ Creates a MediaItem of type 'video/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. 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 = result_set["Url"] if "http://" not in url and "https://" not in url: url = "%s%s" % (self.baseUrl, url) thumb = result_set["Thumb"] if thumb.startswith("//"): thumb = "https:%s" % (thumb, ) item = MediaItem(result_set['Title'], url) item.icon = self.icon item.thumb = thumb item.isGeoLocked = result_set["Abroad"] == "false" if result_set["Date1"] is not None and result_set["Date1"].lower( ) != "imorgon": year, month, day, hour, minutes = self.__get_date( result_set["Date1"], result_set["Date2"], result_set["Date3"]) item.set_date(year, month, day, hour, minutes, 0) if "/video/" in url: item.type = "video" video_id = url.split("/")[4] item.url = "https://www.svtplay.se/video/%s?type=embed&output=json" % ( video_id, ) # else: # # make sure we get the right tab for displaying # item.url = "%s?tab=program" % (item.url, ) return item
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 = "http://www.dumpert.nl/%s/%s/" for page in range(1, 3): item = MediaItem("Toppertjes - Pagina %s" % (page, ), url_pattern % ('toppers', page)) item.icon = self.icon items.append(item) for page in range(1, 11): item = MediaItem("Filmpjes - Pagina %s" % (page, ), url_pattern % ('filmpjes', page)) item.icon = self.icon items.append(item) item = MediaItem("Zoeken", "searchSite") item.icon = self.icon items.append(item) return data, items
def create_episode_item_json(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 result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) # add { to make it valid Json again. if it would be in the regex it would # not find all items # data = JsonHelper("{%s" % (result_set,)) # title local_title = result_set.get("local_title") original_title = result_set.get("original_name") if local_title == "" or local_title is None: title = original_title elif original_title != local_title: title = "%s (%s)" % (local_title, original_title) else: title = local_title # the URL serie_id = result_set["id"] url = "%sepisodes.json?per=2147483647&franchise_id=%s" % ( self.mainListUri[0:43], serie_id) item = MediaItem(title, url) item.icon = self.icon item.complete = True # thumbs if "image" in result_set and result_set["image"] is not None: # noinspection PyTypeChecker thumb = result_set["image"]["riptide_image_id"] thumb = "http://images.mtvnn.com/%s/original" % (thumb, ) item.thumb = thumb # others item.description = result_set["local_long_description"] 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) xml_data = XmlHelper(result_set) title = xml_data.get_single_node_content("title") url = xml_data.get_single_node_content("link") description = xml_data.get_single_node_content("description") description = description.replace("<![CDATA[ ", "").replace("]]>", "").replace("<p>", "").replace("</p>", "\n") item = MediaItem(title, url) item.type = 'video' item.complete = False item.description = description item.thumb = self.noImage item.icon = self.icon date = xml_data.get_single_node_content("pubDate") date_result = Regexer.do_regex(r"\w+, (\d+) (\w+) (\d+)", date)[-1] day = date_result[0] month_part = date_result[1].lower() year = date_result[2] try: month_lookup = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] month = month_lookup.index(month_part) + 1 item.set_date(year, month, day) except: Logger.error("Error matching month: %s", result_set[4].lower(), exc_info=True) return item
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 list[str]|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) item.icon = self.icon item.thumb = self.__get_thumb_image( result_set.get("image") or self.noImage) # No fanart for now # item.fanart = self.__get_thumb_image(resultSet.get("image") or self.fanart, fanartSize=True) item.isGeoLocked = result_set.get('onlyAvailableInSweden', False) return item
def __ShowEmptyInformation(self, items, favs=False): """ Adds an empty item to a list or just shows a message. @type favs: boolean indicating that we are dealing with favourites @param items: the list of items @rtype : boolean indicating succes or not """ if self.channelObject: Statistics.RegisterError(self.channelObject) if favs: title = LanguageHelper.GetLocalizedString(LanguageHelper.NoFavsId) else: title = LanguageHelper.GetLocalizedString(LanguageHelper.ErrorNoEpisodes) behaviour = AddonSettings.GetEmptyListBehaviour() 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 emptyListItem = MediaItem("- %s -" % (title.strip("."), ), "", type='video') emptyListItem.icon = self.channelObject.icon emptyListItem.thumb = self.channelObject.noImage emptyListItem.fanart = self.channelObject.fanart emptyListItem.dontGroup = True emptyListItem.description = "This listing was left empty intentionally." emptyListItem.complete = True emptyListItem.fanart = self.channelObject.fanart # add funny stream here? # part = emptyListItem.CreateNewEmptyMediaPart() # for s, b in YouTube.GetStreamsFromYouTube("", self.channelObject.proxy): # part.AppendMediaStream(s, b) # if we add one, set OK to True ok = True items.append(emptyListItem) else: ok = True XbmcWrapper.ShowNotification(LanguageHelper.GetLocalizedString(LanguageHelper.ErrorId), title, XbmcWrapper.Error, 2500) return ok
def StievieChannelMenu(self, data): items = [] live = MediaItem("Live %s" % (self.parentItem.name, ), "#livestream") live.isLive = True live.type = "video" live.description = self.parentItem.description live.metaData = self.parentItem.metaData live.thumb = self.parentItem.thumb items.append(live) if not self.__dashStreamsSupported: # Only list the channel content if DASH is supported return data, items # https://epg.medialaan.io/epg/v2/schedule?date=2017-04-25&channels%5B%5D=vtm&channels%5B%5D=2be&channels%5B%5D=vitaya&channels%5B%5D=caz&channels%5B%5D=kzoom&channels%5B%5D=kadet&channels%5B%5D=qmusic # https://epg.medialaan.io/epg/v2/schedule?date=2017-04-25&channels[]=vtm&channels[]=2be&channels[]=vitaya&channels[]=caz&channels[]=kzoom&channels[]=kadet&channels[]=qmusic # https://epg.medialaan.io/epg/v2/schedule?date=2017-05-04&channels[]=vtm&channels[]=2be&channels[]=vitaya&channels[]=caz&channels[]=kzoom&channels[]=kadet&channels[]=qmusic channelId = self.parentItem.metaData["channelId"] channels = (channelId, ) query = "&channels%%5B%%5D=%s" % ("&channels%5B%5D=".join(channels), ) today = datetime.datetime.now() days = ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"] for i in range(0, 7, 1): airDate = today - datetime.timedelta(i) Logger.Trace("Adding item for: %s", airDate) day = days[airDate.weekday()] if i == 0: day = "Vandaag" elif i == 1: day = "Gisteren" elif i == 2: day = "Eergisteren" title = "%04d-%02d-%02d - %s" % (airDate.year, airDate.month, airDate.day, day) url = "https://epg.medialaan.io/epg/v2/schedule?date=%d-%02d-%02d%s" % (airDate.year, airDate.month, airDate.day, query) extra = MediaItem(title, url) extra.complete = True extra.icon = self.icon extra.thumb = self.noImage extra.dontGroup = True extra.SetDate(airDate.year, airDate.month, airDate.day, text="") extra.metaData["airDate"] = airDate items.append(extra) 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) # 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 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 result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ # Logger.Trace(result_set) json = result_set title = json["name"] program_id = json["nid"] program_id = HtmlEntityHelper.url_encode(program_id) url = "http://webapi.tv4play.se/play/video_assets" \ "?platform=tablet&per_page=%s&is_live=false&type=episode&" \ "page=1&node_nids=%s&start=0" % (self.maxPageSize, program_id, ) if "channel" in json and json["channel"]: # noinspection PyTypeChecker channel_id = json["channel"]["nid"] Logger.trace("ChannelId found: %s", channel_id) else: channel_id = "tv4" Logger.warning("ChannelId NOT found. Assuming %s", channel_id) # match the exact channel or put them in TV4 is_match_for_channel = channel_id.startswith(self.__channelId) is_match_for_channel |= self.channelCode == "tv4se" and not channel_id.startswith( "sjuan") and not channel_id.startswith("tv12") if not is_match_for_channel: Logger.debug("Channel mismatch for '%s': %s vs %s", title, channel_id, self.channelCode) return None item = MediaItem(title, url) item.icon = self.icon item.thumb = result_set.get("program_image", self.noImage) item.isPaid = result_set.get("is_premium", False) return item
def create_json_video(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,any|None] 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 """ video_id = result_set['id'] # Categories to use # category = result_set["maincategory"].title() # subcategory = result_set["subcategory"].title() url = "https://api.nos.nl/mobile/video/%s/phone.json" % (video_id, ) item = MediaItem(result_set['title'], url, type="video") item.icon = self.icon if 'image' in result_set: images = result_set['image']["formats"] matched_image = images[-1] for image in images: if image["width"] >= 720: matched_image = image break item.thumb = matched_image["url"].values()[0] item.description = result_set["description"] item.complete = False item.isGeoLocked = result_set.get("geoprotection", False) # set the date and time date = result_set["published_at"] time_stamp = DateHelper.get_date_from_string(date, date_format="%Y-%m-%dT%H:%M:%S+{0}".format(date[-4:])) item.set_date(*time_stamp[0:6]) return item
def create_video_item_json(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 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) image_data = result_set.get("media", []) thumb = None url = None for image in image_data: thumb = image.get("imageHigh", image["image"]) url = image.get("url") item = MediaItem(result_set["title"], url) item.type = "video" item.icon = self.icon item.thumb = thumb or self.noImage item.complete = True item.description = result_set.get("text") part = item.create_new_empty_media_part() M3u8.update_part_with_m3u8_streams(part, url, proxy=self.proxy, channel=self) # Let's not do the time now time_stamp = result_set["created"] date_time = DateHelper.get_date_from_posix(time_stamp) item.set_date(date_time.year, date_time.month, date_time.day, date_time.hour, date_time.minute, date_time.second) return item
def add_days(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 = [] now = datetime.datetime.now() from_date = now - datetime.timedelta(6) Logger.debug( "Showing dates starting from %02d%02d%02d to %02d%02d%02d", from_date.year, from_date.month, from_date.day, now.year, now.month, now.day) current = from_date while current <= now: url = "https://api.538.nl/api/v1/schedule/station/radio-538" \ "?since=%s-%s-%sT00%%3A00%%3A00%%2B01%%3A00" \ "&until=%s-%s-%sT23%%3A59%%3A59%%2B01%%3A00" % \ (current.year, current.month, current.day, current.year, current.month, current.day) # "&_=1483280915489%%02d%%02d%%02d" title = "Afleveringen van %02d-%02d-%02d" % ( current.year, current.month, current.day) date_item = MediaItem(title, url) date_item.icon = self.icon date_item.thumb = self.noImage date_item.complete = True items.append(date_item) current = current + datetime.timedelta(1) return data, items
def create_video_item_old(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) thumb_url = result_set[1] url = "%s%s" % (self.baseUrl, result_set[2]) title = result_set[6] item = MediaItem(title, url) item.thumb = self.noImage if thumb_url: item.thumb = thumb_url item.icon = self.icon item.type = 'video' if result_set[3]: # set date day = result_set[3] month = result_set[4] year = result_set[5] Logger.trace("%s-%s-%s", year, month, day) month = datehelper.DateHelper.get_month_from_name( month, "nl", True) item.set_date(year, month, day) item.complete = False 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 """ item = MediaItem(result_set[1], "%s%s?page=1" % (self.baseUrl, result_set[0])) item.icon = self.icon item.complete = True return item
def StievieMenu(self, data): """ Creates the main Stievie menu """ items = [] if not self.__dashStreamsSupported: return data, items programs = MediaItem("\b.: Programma's :.", "https://vod.medialaan.io/vod/v2/programs?offset=0&limit=0") programs.dontGroup = True items.append(programs) search = MediaItem("Zoeken", "searchSite") search.complete = True search.icon = self.icon search.thumb = self.noImage search.dontGroup = True search.SetDate(2200, 1, 1, text="") items.append(search) return data, items
def add_page_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]] """ Logger.info("Performing Pre-Processing") items = [] json = JsonHelper(data) total_results = json.get_value("totalResults") from_value = json.get_value("from") size_value = json.get_value("size") if from_value + size_value < total_results: more_pages = LanguageHelper.get_localized_string( LanguageHelper.MorePages) url = self.parentItem.url.split('?')[0] url = "%s?size=%s&from=%s&sort=Nieuwste" % ( url, size_value, from_value + size_value) Logger.debug("Adding next-page item from %s to %s", from_value + size_value, from_value + size_value + size_value) next_page = MediaItem(more_pages, url) next_page.icon = self.parentItem.icon next_page.fanart = self.parentItem.fanart next_page.thumb = self.parentItem.thumb next_page.dontGroup = True items.append(next_page) Logger.debug("Pre-Processing finished") return json, items
def add_categories_and_search(self, data): """ Adds some generic items such as search and categories to the main listing. 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 = [] max_items = 200 categories = { # "\a.: Mest spelade :.": "https://urplay.se/Mest-spelade", "\a.: Mest delade :.": "https://urplay.se/sok?product_type=program&query=&view=most_viewed&rows=%s&start=0" % (max_items, ), "\a.: Senaste :.": "https://urplay.se/sok?product_type=program&query=&view=latest&rows=%s&start=0" % (max_items, ), "\a.: Sista chansen :.": "https://urplay.se/sok?product_type=program&query=&view=default&rows=%s&start=0" % (max_items, ), "\a.: Kategorier :.": "https://urplay.se/", "\a.: Sök :.": "searchSite" } for cat in categories: item = MediaItem(cat, categories[cat]) item.thumb = self.noImage item.complete = True item.icon = self.icon item.dontGroup = True items.append(item) Logger.debug("Pre-Processing finished") 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 dict[str,Any] 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"] date = result_set["trailers"][0]["postdate"] url = result_set["trailers"][0]["url"] thumb_url = result_set["poster"] if "http:" not in thumb_url: thumb_url = "%s%s" % (self.baseUrl, thumb_url) fanart = thumb_url.replace("poster.jpg", "background.jpg") # get the url that shows all trailers/clips. Because the json # only shows the most recent one. url = "%s%s" % (self.baseUrl, url) # Logger.Trace(date) dates = date.split(" ") # Logger.Trace(dates) day = dates[1] month = datehelper.DateHelper.get_month_from_name(dates[2], "en") year = dates[3] # dummy class item = MediaItem(title, url) item.icon = self.icon item.thumb = thumb_url.replace("poster.jpg", "poster-xlarge.jpg") item.fanart = fanart item.set_date(year, month, day) item.complete = True return item
def AddVideoPageItemsJson(self, data): items = [] json = JsonHelper(data) currentOffset = json.GetValue("request", "offset") or 0 itemsOnThisPage = len(json.GetValue("response", "items") or []) totalItems = json.GetValue("response", "total") if totalItems > currentOffset + itemsOnThisPage: # add next page items newOffset = currentOffset + itemsOnThisPage seriesId = json.GetValue("request", "parentSeriesOID")[0] url = "https://vod.medialaan.io/api/1.0/list?app_id=%s&parentSeriesOID=%s&offset=%s" % (self.__app, seriesId, newOffset) more = LanguageHelper.GetLocalizedString(LanguageHelper.MorePages) item = MediaItem(more, url) item.thumb = self.noImage item.icon = self.icon item.fanart = self.parentItem.fanart item.complete = True items.append(item) return json, items
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 """ # 0 1 2 3 #<a class="item" href="([^"]+)"[^=]+="([^"]+)" alt="([^"]+)[^:]+<div class="date">([^<]+) item = MediaItem(result_set[2], result_set[0], type='video') item.icon = self.icon item.description = result_set[2] item.thumb = result_set[1] try: month = datehelper.DateHelper.get_month_from_name( result_set[4], "nl") item.set_date(result_set[5], month, result_set[3], result_set[6], result_set[7], 0) except: Logger.error("Error matching month: %s", result_set[4].lower(), exc_info=True) 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 """ Logger.trace(result_set) url = result_set["url"] if not url.startswith("http"): url = "%s%s" % (self.baseUrl, url) name = result_set["title"] item = MediaItem(name, url) item.type = 'video' item.icon = self.icon item.thumb = self.noImage month = result_set["month"] month = DateHelper.get_month_from_name(month, "en", False) day = result_set["day"] year = result_set["year"] item.set_date(year, month, day) item.complete = False return item
def create_live_stream(self, result_set): """ Creates a MediaItem of type 'video' for a live stream 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 """ items = [] for key_value, stream_value in result_set.items(): Logger.trace(stream_value) # noinspection PyArgumentList channel_data = self.__channelData.get(key_value, None) if not channel_data: continue url = channel_data[ "url"] if "url" in channel_data else stream_value["mpd"] live_item = MediaItem(channel_data["title"], url) live_item.isLive = True live_item.type = 'video' live_item.fanart = channel_data.get("fanart", self.fanart) live_item.thumb = channel_data.get("icon", self.icon) live_item.icon = channel_data.get("icon", self.icon) live_item.metaData["channel_key"] = key_value items.append(live_item) return items
def create_show_item(self, result_set): """ Creates a MediaItem of type 'folder' for a show 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 result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) exclude = { 11: "Dagelijkse Kost", 388: "Het journaal", 400: "Karakters", 413: "Het weer" } if result_set["id"] in exclude.keys(): return None # # dummy class # url = "http://www.een.be/mediatheek/tag/%s" item = MediaItem(result_set["title"], result_set["url"]) item.icon = self.icon item.type = "folder" item.complete = True if "image" in result_set and "data" in result_set["image"]: # noinspection PyTypeChecker item.thumb = result_set["image"]["data"]["url"] # noinspection PyTypeChecker item.fanart = result_set["image"]["data"]["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 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"] # The id = result_set["id"] url = "http://api.playplex.viacom.com/feeds/networkapp/intl/series/items/1.5/%s" \ "?key=networkapp1.0&brand=mtv&platform=android®ion=%s&version=2.2" % \ (result_set["id"], self.__region) item = MediaItem(title, url) item.icon = self.icon item.description = result_set.get("description", None) item.complete = True images = result_set.get("images", []) if images: # mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png # http://playplex.mtvnimages.com/uri/mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png for image in images: # noinspection PyTypeChecker if image["width"] > 500: item.fanart = "http://playplex.mtvnimages.com/uri/%(url)s" % image else: item.thumb = "http://playplex.mtvnimages.com/uri/%(url)s" % image 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.icon = self.icon item.thumb = self.noImage item.complete = True item.isGeoLocked = True return item
def parse_sub_list(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]] """ item = self.parentItem url = item.url items = [] stations = os.listdir(url) for station in stations: if not station.endswith(".strm"): continue name = station.replace(".strm", "") stream = os.path.join(url, station) station_item = MediaItem(name, stream) station_item.icon = os.path.join(url, "%s%s" % (name, ".tbn")) station_item.complete = True station_item.description = station_item.name station_item.append_single_stream(stream) station_item.type = "playlist" station_item.thumb = station_item.icon items.append(station_item) 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[int] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ url = "http://gdata.youtube.com/feeds/api/users/hardwareinfovideo/uploads?max-results=%s&start-index=%s" % ( result_set[1], result_set[0]) title = "Hardware Info TV %04d-%04d" % (result_set[0], result_set[0] + result_set[1]) item = MediaItem(title, url) item.complete = True item.icon = self.icon item.thumb = self.noImage return item