def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. :param dict[str,str|dict] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) url = "http://m.schooltv.nl/api/v1/programmas/%s/afleveringen.json?size=%s&sort=Nieuwste" % ( result_set['mid'], self.__PageSize) item = MediaItem(result_set['title'], url) item.thumb = result_set.get('image', self.noImage) item.description = result_set.get('description', None) age_groups = result_set.get('ageGroups', ['Onbekend']) item.description = "%s\n\nLeeftijden: %s" % (item.description, ", ".join(age_groups)) return item
def create_episode_item(self, result_set): """ Creates a new MediaItem for an episode. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. :param dict[str,str] 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"] description = result_set.get("description", "") description_nl = result_set.get("introduction_lan1", "") thumb = result_set["image_full"] url = "https://www.24classics.com/app/core/server_load.php?" \ "r=default&page=luister&serial=&subserial=&hook=%s" % (result_set["hook"],) item = MediaItem(title, url) item.thumb = thumb item.description = "%s\n\n%s" % (description_nl, description) item.description = item.description.strip() item.complete = True 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) 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 create_episode_item_api(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] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ if not isinstance(result_set, dict): json_data = result_set[1].replace(""", "\"") result_set = JsonHelper(json_data) result_set = result_set.json brand = result_set["brand"] if brand != self.__channel_brand: return None title = result_set["title"] url = "{}{}".format(self.baseUrl, result_set["link"]) item = MediaItem(title, url) item.description = result_set["description"] item.isGeoLocked = True images = result_set["images"] item.poster = HtmlEntityHelper.convert_html_entities(images.get("poster")) item.thumb = HtmlEntityHelper.convert_html_entities(images.get("teaser")) return item
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[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ time_stamp = result_set["created"] if time_stamp <= 1420070400: # older items don't have videos for now return None url = "https://at5news.vinsontv.com/api/news?source=web&externalid={}".format( result_set["externalId"]) item = MediaItem(result_set["title"], url) item.complete = True item.description = result_set.get("text") date_time = DateHelper.get_date_from_posix(time_stamp) item.set_date(date_time.year, date_time.month, date_time.day) # noinspection PyTypeChecker image_data = result_set.get("media", []) for image in image_data: item.thumb = image.get("imageHigh", image["image"]) return item
def create_episode_item_new(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) url = "http://il.srgssr.ch/integrationlayer/1.0/ue/srf/assetSet/listByAssetGroup/%s.json?pageSize=100" % ( result_set["id"], ) item = MediaItem(result_set["title"], url) item.description = result_set.get("description", "") item.httpHeaders = self.httpHeaders item.thumb = self.__get_nested_value(result_set, "Image", "ImageRepresentations", "ImageRepresentation", 0, "url") item.complete = True 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.type = 'folder' item.HttpHeaders = self.httpHeaders item.complete = True return item
def create_single_video_item(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param str result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ if self.__hasAlreadyVideoItems: # we already have items, so don't show this one, it will be a duplicate return None result_set = result_set.replace('\\x27', "'") json_data = JsonHelper(result_set) url = self.parentItem.url title = json_data.get_value("name") description = HtmlHelper.to_text(json_data.get_value("description")) item = MediaItem(title, url, type="video") item.description = description return item
def create_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 """ if len(result_set) > 3 and result_set[3] != "": Logger.debug("Sub category folder found.") url = parse.urljoin( self.baseUrl, HtmlEntityHelper.convert_html_entities(result_set[3])) name = "\a.: %s :." % (result_set[4], ) item = MediaItem(name, url) item.complete = True item.type = "folder" return item url = parse.urljoin( self.baseUrl, HtmlEntityHelper.convert_html_entities(result_set[0])) name = HtmlEntityHelper.convert_html_entities(result_set[1]) helper = HtmlHelper(result_set[2]) description = helper.get_tag_content("div", {'class': 'description'}) item = MediaItem(name, "%s/RSS" % (url, )) item.type = 'folder' item.description = description.strip() date = helper.get_tag_content("div", {'class': 'date'}) if date == "": date = helper.get_tag_content("span", {'class': 'lastPublishedDate'}) if not date == "": date_parts = Regexer.do_regex(r"(\w+) (\d+)[^<]+, (\d+)", date) if len(date_parts) > 0: date_parts = date_parts[0] month_part = date_parts[0].lower() day_part = date_parts[1] year_part = date_parts[2] try: month = DateHelper.get_month_from_name(month_part, "en") item.set_date(year_part, month, day_part) except: Logger.error("Error matching month: %s", month_part, exc_info=True) item.complete = True return item
def create_json_episode_item(self, result_set): """ Creates a new MediaItem for an episode. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. :param dict result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) meta = result_set["meta"] name = meta["header"]["title"] url = "{}{}".format(self.baseUrl, result_set["url"]) item = MediaItem(name, url) item.description = meta.get("description") item.isGeoLocked = True media_info = result_set.get("media") if media_info is not None: item.thumb = media_info.get("image", {}).get("url") return item
def create_channel_item(self, channel): """ Creates a MediaItem of type 'video' for a live channel 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 channel: 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(channel) title = channel["programmeTitle"] episode = channel.get("episodeTitle", None) thumb = self.noImage channel_title = channel["displayName"] description = channel.get("longDescription") channel_id = channel["urlName"] if channel_id == "svtb": channel_id = "barnkanalen" elif channel_id == "svtk": channel_id = "kunskapskanalen" date_format = "%Y-%m-%dT%H:%M:%S" start_time = DateHelper.get_date_from_string( channel["publishingTime"][:19], date_format) end_time = DateHelper.get_date_from_string( channel["publishingEndTime"][:19], date_format) if episode: title = "%s: %s - %s (%02d:%02d - %02d:%02d)" \ % (channel_title, title, episode, start_time.tm_hour, start_time.tm_min, end_time.tm_hour, end_time.tm_min) else: title = "%s: %s (%02d:%02d - %02d:%02d)" \ % (channel_title, title, start_time.tm_hour, start_time.tm_min, end_time.tm_hour, end_time.tm_min) channel_item = MediaItem( title, "https://www.svt.se/videoplayer-api/video/ch-%s" % (channel_id.lower(), )) channel_item.type = "video" channel_item.description = description channel_item.isLive = True channel_item.isGeoLocked = True channel_item.thumb = thumb if "episodeThumbnailIds" in channel and channel["episodeThumbnailIds"]: channel_item.thumb = "https://www.svtstatic.se/image/wide/650/%s.jpg" % ( channel["episodeThumbnailIds"][0], ) return channel_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_video_item(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param result_set: The result_set of the self.episodeItemRegex :type result_set: list[str]|dict[str,dict[str,dict]] :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ Logger.trace(result_set) if "fullengthSegment" in result_set and "segment" in result_set[ "fullengthSegment"]: video_id = result_set["fullengthSegment"]["segment"]["id"] geo_location = result_set["fullengthSegment"]["segment"][ "geolocation"] geo_block = False if "flags" in result_set["fullengthSegment"]["segment"]: geo_block = result_set["fullengthSegment"]["segment"][ "flags"].get("geoblock", None) Logger.trace("Found geoLocation/geoBlock: %s/%s", geo_location, geo_block) else: Logger.warning("No video information found.") return None url = "http://www.srf.ch/player/webservice/videodetail/index?id=%s" % ( video_id, ) item = MediaItem(result_set["titleFull"], url) item.type = "video" # noinspection PyTypeChecker item.thumb = result_set.get("segmentThumbUrl", None) # apparently only the 144 return the correct HEAD info # item.thumb = "%s/scale/width/288" % (item.thumb, ) # the HEAD will not return a size, so Kodi can't handle it # item.fanart = resultSet.get("imageUrl", None) item.description = result_set.get("description", "") date_value = str(result_set["time_published"]) # 2015-01-20 22:17:59" date_time = DateHelper.get_date_from_string(date_value, "%Y-%m-%d %H:%M:%S") item.set_date(*date_time[0:6]) item.icon = self.icon item.httpHeaders = self.httpHeaders item.complete = False return item
def create_video_item_new(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param result_set: The result_set of the self.episodeItemRegex :type result_set: list[str]|dict[str,str] :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ Logger.trace(result_set) videos = self.__get_nested_value(result_set, "Assets", "Video") if not videos: Logger.warning("No video information found.") return None video_infos = [vi for vi in videos if vi["fullLength"]] if len(video_infos) > 0: video_info = video_infos[0] else: Logger.warning("No full length video found.") return None # noinspection PyTypeChecker video_id = video_info["id"] url = "http://il.srgssr.ch/integrationlayer/1.0/ue/srf/video/play/%s.json" % ( video_id, ) item = MediaItem(result_set["title"], url) item.type = "video" item.thumb = self.__get_nested_value(video_info, "Image", "ImageRepresentations", "ImageRepresentation", 0, "url") item.description = self.__get_nested_value(video_info, "AssetMetadatas", "AssetMetadata", 0, "description") date_value = str(result_set["publishedDate"]) date_value = date_value[0:-6] # 2015-01-20T22:17:59" date_time = DateHelper.get_date_from_string(date_value, "%Y-%m-%dT%H:%M:%S") item.set_date(*date_time[0:6]) item.icon = self.icon item.httpHeaders = self.httpHeaders item.complete = False return item
def create_api_tvshow_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 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=TvShow, KidsTvShow, Single """ url = result_set["urls"]["svtplay"] item = MediaItem(result_set['name'], "#program_item") item.metaData["slug"] = url item.icon = self.icon item.isGeoLocked = result_set.get('restrictions', {}).get('onlyAvailableInSweden', False) item.description = result_set.get('description') image_info = result_set.get("image") if image_info: item.thumb = self.__get_thumb(image_info) 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_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) url = "http://il.srgssr.ch/integrationlayer/1.0/ue/srf/assetSet/listByAssetGroup/%s.json" % ( result_set["id"], ) item = MediaItem(result_set["title"], url) item.description = result_set.get("description", "") item.httpHeaders = self.httpHeaders # the 0005 seems to be a quality thing: 0001, 0003, 0004, 0005 # http://www.srf.ch/webservice/picture/videogroup/c60026b7-2ed0-0001-b4b1-1f801a6355d0/0005 # http://www.srfcdn.ch/piccache/vis/videogroup/c6/00/c60026b7-2ed0-0001-b4b1-1f801a6355d0_0005_w_h_m.jpg # item.thumb = "http://www.srf.ch/webservice/picture/videogroup/%s/0005" % (resultSet["id"],) item.thumb = "http://www.srfcdn.ch/piccache/vis/videogroup/%s/%s/%s_0005_w_h_m.jpg" \ % (result_set["id"][0:2], result_set["id"][2:4], result_set["id"],) # item.thumb = resultSet.get("thumbUrl", None) # item.thumb = "%s/scale/width/288" % (item.thumb, ) # apparently only the 144 return the correct HEAD info # item.fanart = resultSet.get("imageUrl", None) $# the HEAD will not return a size, so Kodi can't handle it item.complete = True return item
def create_music_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) title = "%(composers)s - %(title)s" % result_set url = "https://www.24classics.com/app/ajax/auth.php?serial=%(serial)s" % result_set item = MediaItem(title, url) item.type = "video" # seems to not really work well with track numbers (not showing) # item.type = "audio" item.complete = False item.description = "Composers: %(composers)s\nPerformers: %(performers)s" % result_set item.set_info_label("TrackNumber", result_set["order"]) item.set_info_label("AlbumArtist", result_set["composers"].split(",")) item.set_info_label("Artist", result_set["performers"].split(",")) return item
def create_episode_json_item(self, result_set): """ Creates a new MediaItem for an episode. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ Logger.trace(result_set) title = "%(title)s" % result_set url = "https://urplay.se/api/bff/v1/series/{}".format(result_set["id"]) fanart = "https://assets.ur.se/id/%(id)s/images/1_hd.jpg" % result_set thumb = "https://assets.ur.se/id/%(id)s/images/1_l.jpg" % result_set item = MediaItem(title, url) item.thumb = thumb item.description = result_set.get("description") item.fanart = fanart return item
def create_video_item(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ xml_data = xmlhelper.XmlHelper(result_set) title = xml_data.get_single_node_content("title") # Retrieve an ID and create an URL like: http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=OHqu64Qnz9M video_id = xml_data.get_single_node_content("id") last_slash = video_id.rfind(":") + 1 video_id = video_id[last_slash:] # The old url does no longer work: # url = "http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=%s" % (videoId,) url = "http://www.youtube.com/watch?v=%s" % (video_id, ) item = MediaItem(title, url) item.type = 'video' # date stuff date = xml_data.get_single_node_content("published") year = date[0:4] month = date[5:7] day = date[8:10] hour = date[11:13] minute = date[14:16] # Logger.Trace("%s-%s-%s %s:%s", year, month, day, hour, minute) item.set_date(year, month, day, hour, minute, 0) # description stuff description = xml_data.get_single_node_content("media:description") item.description = description # thumbnail stuff thumb_url = xml_data.get_tag_attribute("media:thumbnail", {'url': None}, {'height': '360'}) # <media:thumbnail url="http://i.ytimg.com/vi/5sTMRR0_Wo8/0.jpg" height="360" width="480" time="00:09:52.500" xmlns:media="http://search.yahoo.com/mrss/" /> if thumb_url != "": item.thumb = thumb_url # finish up item.complete = False return item
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
def create_recent_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 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) show_title = result_set["abstract_name"] episode_title = result_set["title"] title = "{} - {}".format(show_title, episode_title) description = result_set.get("synopsis") uuid = result_set["uuid"] url = "https://api.rtl.nl/watch/play/api/play/xl/%s?device=web&drm=widevine&format=dash" % (uuid,) item = MediaItem(title.title(), url) item.type = "video" item.description = description item.thumb = "%s%s" % (self.posterBase, uuid,) audience = result_set.get("audience") Logger.debug("Found audience: %s", audience) item.isGeoLocked = audience == "ALLEEN_NL" # We can play the DRM stuff # item.isDrmProtected = audience == "DRM" station = result_set.get("station", None) if station: item.name = "{} ({})".format(item.name, station) icon = self.largeIconSet.get(station.lower(), None) if icon: Logger.trace("Setting icon to: %s", icon) item.icon = icon # 2018-12-05T19:30:00.000Z date_time = result_set.get("dateTime", None) if date_time: date_time = DateHelper.get_date_from_string(date_time[:-5], "%Y-%m-%dT%H:%M:%S") # The time is in UTC, and the show as at UTC+1 date_time = datetime.datetime(*date_time[:6]) + datetime.timedelta(hours=1) item.name = "{:02d}:{:02d}: {}".format(date_time.hour, date_time.minute, item.name) item.set_date(date_time.year, date_time.month, date_time.day, date_time.hour, date_time.minute, date_time.second) return item
def create_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,dict|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 """ Logger.trace(result_set) title = result_set["title"] if "subTitle" in result_set: title = "%s - %s" % (title, result_set["subTitle"]) mgid = result_set["id"].split(":")[-1] url = "http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed" \ "?mgid=mgid:arc:episode:mtvplay.com:%s" \ "&ep=%s" \ "&episodeType=segmented" \ "&imageEp=android.playplex.mtv.%s" \ "&arcEp=android.playplex.mtv.%s" \ % (mgid, self.__backgroundServiceEp, self.__region.lower(), self.__region.lower()) item = MediaItem(title, url) item.type = "video" item.description = result_set.get("description", None) item.isGeoLocked = 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: if image["width"] > 500: pass # no fanart here else: item.thumb = "http://playplex.mtvnimages.com/uri/%(url)s" % image date = result_set.get("originalAirDate", None) if not date: date = result_set.get("originalPublishDate", None) if date: time_stamp = date["timestamp"] 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 create_series_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 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"] sub_title = result_set.get("episodeTitle", None) if sub_title: title = "{} - {}".format(title, sub_title) if not result_set["usageRights"].get("hasRightsNow", True): Logger.debug("Found '%s' without 'usageRights'", title) return None url = "https://psapi.nrk.no/programs/{}?apiKey={}".format( result_set["id"], self.__api_key) item = MediaItem(title, url) item.type = 'video' # noinspection PyTypeChecker item.thumb = self.__get_image(result_set["image"]["webImages"], "pixelWidth", "imageUrl") item.description = result_set.get("longDescription", "") if not item.description: item.description = result_set.get("shortDescription", "") item.isGeoLocked = result_set.get("usageRights", {}).get("isGeoBlocked", False) self.__set_date(result_set, item) return item
def create_generic_item(self, result_set, program_type): """ Creates a MediaItem of type 'video' or 'folder' using the result_set from the regex and a basic set of values. 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"] if not result_set.get("hasOndemandRights", True): Logger.debug("Item '%s' has no on-demand rights", title) return None item_id = result_set["id"] if program_type == "programme": url = "https://psapi.nrk.no/programs/{}?apiKey={}".format(item_id, self.__api_key) item = MediaItem(title, url) item.type = 'video' else: use_old_series_api = False if use_old_series_api: url = "https://psapi.nrk.no/series/{}?apiKey={}".format(item_id, self.__api_key) else: url = "https://psapi.nrk.no/tv/catalog/series/{}?apiKey={}".format(item_id, self.__api_key) item = MediaItem(title, url) item.type = 'folder' item.isGeoLocked = result_set.get("isGeoBlocked", result_set.get("usageRights", {}).get("isGeoBlocked", False)) description = result_set.get("description") if description and description.lower() != "no description": item.description = description if "image" not in result_set or "webImages" not in result_set["image"]: return item # noinspection PyTypeChecker item.thumb = self.__get_image(result_set["image"]["webImages"], "pixelWidth", "imageUrl") # see if there is a date? self.__set_date(result_set, item) 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_hw_info(self, result_set): """ Creates a MediaItem of type 'video' using the result_set from the regex. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.update_video_item method is called if the item is focussed or selected for playback. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'video' or 'audio' (despite the method's name). :rtype: MediaItem|None """ xml_data = xmlhelper.XmlHelper(result_set) title = xml_data.get_single_node_content("title") # Retrieve an ID and create an URL like: http://www.youtube.com/get_video_info?hl=en_GB&asv=3&video_id=OHqu64Qnz9M url = xml_data.get_tag_attribute("enclosure", {'url': None}, {'type': 'video/youtube'}) Logger.trace(url) item = MediaItem(title, url) item.icon = self.icon item.type = 'video' # date stuff date = xml_data.get_single_node_content("pubDate") dayname, day, month, year, time, zone = date.split(' ', 6) month = DateHelper.get_month_from_name(month, language="en") hour, minute, seconds = time.split(":") Logger.trace("%s-%s-%s %s:%s", year, month, day, hour, minute) item.set_date(year, month, day, hour, minute, 0) # # description stuff description = xml_data.get_single_node_content("description") item.description = description # # thumbnail stuff item.thumb = self.noImage thumb_urls = xml_data.get_tag_attribute("enclosure", {'url': None}, {'type': 'image/jpg'}, firstOnly=False) for thumb_url in thumb_urls: if thumb_url != "" and "thumb" not in thumb_url: item.thumb = thumb_url # finish up item.complete = False return item
def __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 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_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,any] 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 = "http://playapi.mtgx.tv/v3/videos/stream/%(id)s" % result_set item = MediaItem(result_set["title"], url) item.type = "video" item.thumb = self.parentItem.thumb item.icon = self.parentItem.icon item.description = result_set.get("summary", None) aired_at = result_set.get("airedAt", None) if aired_at is None: aired_at = result_set.get("publishedAt", None) if aired_at is not None: # 2016-05-20T15:05:00+00:00 aired_at = aired_at.split("+")[0].rstrip('Z') time_stamp = DateHelper.get_date_from_string( aired_at, "%Y-%m-%dT%H:%M:%S") item.set_date(*time_stamp[0:6]) item.thumb = self.__get_thumb_image(result_set.get("image")) # webvttPath / samiPath # loginRequired is_premium = result_set.get("loginRequired", False) if is_premium and AddonSettings.hide_premium_items(): Logger.debug("Found premium item, hiding it.") return None srt = result_set.get("samiPath") if not srt: srt = result_set.get("subtitles_webvtt") if srt: Logger.debug("Storing SRT/WebVTT path: %s", srt) part = item.create_new_empty_media_part() part.Subtitle = srt return item