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_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_episode_item(self, result_set): """ Creates a new MediaItem for an episode. This method creates a new MediaItem from the Regular Expression or Json results <result_set>. The method should be implemented by derived classes and are specific to the channel. :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex :return: A new MediaItem of type 'folder'. :rtype: MediaItem|None """ if self.__currentChannel is not None and result_set["channel"] != self.__currentChannel: Logger.debug("Skipping items due to channel mismatch: %s", result_set) return None item = chn_class.Channel.create_episode_item(self, result_set) if item is None: return None item.description = HtmlHelper.to_text(item.description) # update artswork if item.thumb and item.thumb.startswith("//"): item.thumb = "https:%s" % (item.thumb, ) # API url's # item.url = "https://vrtnu-api.vrt.be/search?i=video&facets[programUrl]={}&size=300".format( # item.url.replace("https:", "").replace(".relevant", "")) 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 = HtmlHelper.to_text(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_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.thumb = thumb or self.noImage item.complete = True item.description = HtmlHelper.to_text(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 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) time_stamp = result_set["created"] if time_stamp <= 1420070400: # older items don't have videos for now return None url = "{}/api/article/{}".format(self.baseUrl, result_set["externalId"]) item = MediaItem(result_set["title"], url) item.description = HtmlHelper.to_text(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", []) video_url = None for image in image_data: item.thumb = image.get("imageHigh", image.get("image")) video_url = image.get("url") # In some cases the main list only has videos if result_set.get("video", False): if video_url is None: return None item.type = "video" item.url = video_url return item
def create_video_item_api(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 """ # Could be: title = result_set['episodeTitle'] title = result_set['title'] url = "https://api.viervijfzes.be/content/{}".format( result_set['videoUuid']) item = MediaItem(title, url) item.type = "video" item.description = HtmlHelper.to_text( result_set.get("description").replace(">\r\n", ">")) item.thumb = result_set["image"] item.isGeoLocked = result_set.get("isProtected") date_time = DateHelper.get_date_from_posix(result_set["createdDate"]) item.set_date(date_time.year, date_time.month, date_time.day, date_time.hour, date_time.minute, date_time.second) item.set_info_label("duration", result_set["duration"]) if "epsiodeNumber" in result_set and "seasonNumber" in result_set: item.set_season_info(result_set["seasonNumber"], result_set["epsiodeNumber"]) 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 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.get("title") media_link = result_set.get("video", result_set.get("ipadLink")) item = MediaItem(title, media_link) item.thumb = result_set.get("image", result_set.get("imageLink")) item.type = 'video' item.description = HtmlHelper.to_text(result_set.get("text")) posix = result_set.get("timestamp", None) if posix: broadcast_date = DateHelper.get_date_from_posix(int(posix)) item.set_date(broadcast_date.year, broadcast_date.month, broadcast_date.day, broadcast_date.hour, broadcast_date.minute, broadcast_date.second) item.set_info_label("duration", result_set.get("duration", 0)) 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 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) media_link = result_set.get("ipadLink") title = result_set.get("title") # it seems overkill, but not all items have a contentLink and of we set # the url to self.baseUrl it will be a duplicate item if the titles are # equal url = result_set.get("contentLink") or media_link or self.baseUrl if not url.startswith("http"): url = parse.urljoin(self.baseUrl, url) item = MediaItem(title, url) if media_link: item.append_single_stream(media_link, self.channelBitrate) # get the thumbs from multiple locations thumb_urls = result_set.get("images", None) thumb_url = None if thumb_urls: # noinspection PyUnresolvedReferences thumb_url = \ thumb_urls[0].get("fullScreenLink", None) or \ thumb_urls[0].get("previewLink", None) or \ result_set.get("imageLink", None) if thumb_url and not thumb_url.startswith("http"): thumb_url = parse.urljoin(self.baseUrl, thumb_url) if thumb_url: item.thumb = thumb_url item.type = 'video' item.description = HtmlHelper.to_text(result_set.get("text")) posix = result_set.get("timestamp", None) if posix: broadcast_date = DateHelper.get_date_from_posix(int(posix)) item.set_date(broadcast_date.year, broadcast_date.month, broadcast_date.day, broadcast_date.hour, broadcast_date.minute, broadcast_date.second) item.complete = True return item