def _videos_to_items(self, context, videos, channel_config): result = [] show_only_free_videos = context.get_settings().get_bool('nowtv.videos.only_free', False) for video in videos: if show_only_free_videos and not video['free']: continue video_params = {'video_path': video['path'], 'video_id': str(video['id'])} title = video['title'] if not video['free']: title = '[B][%s][/B] - %s' % (video['price'], title) video_params['free'] = '0' video_params['price'] = video['price'] pass video_item = VideoItem(title, context.create_uri([channel_config['id'], 'play'], video_params)) duration = datetime_parser.parse(video['duration']) video_item.set_duration(duration.hour, duration.minute, duration.second) published = datetime_parser.parse(video['published']) video_item.set_aired_from_datetime(published) video_item.set_date_from_datetime(published) video_item.set_year_from_datetime(published) video_item.set_studio(video['format']) video_item.add_artist(video['format']) video_item.set_episode(video['episode']) video_item.set_season(video['season']) video_item.set_plot(video['plot']) video_item.set_image(video['images']['thumb']) video_item.set_fanart(video['images']['fanart']) result.append(video_item) pass return result
def _list_films(self, context, re_match, json_data, show_format_title=False, sort=True): context.get_ui().set_view_mode('videos') def _sort_newest(item): return item.get_aired() context.set_content_type(kodion.constants.content_type.EPISODES) context.add_sort_method(kodion.constants.sort_method.UNSORTED, kodion.constants.sort_method.VIDEO_YEAR, kodion.constants.sort_method.VIDEO_RUNTIME) result = [] content = json_data.get('result', {}).get('content', {}) max_page = int(content.get('maxpage', 1)) page = int(content.get('page', 1)) film_list = content.get('filmlist', {}) result_films = [] add_next_page_item = True keys = sorted(film_list.keys()) for key in keys: film = film_list[key] # as soon as we find non-free episodes we don't provide pagination # the 'continue' should skip all non-free episodes free = str(film.get('free', '0')) if free == '0': add_next_page_item = False continue title = film['headlinelong'] format_title = film['formatlong'] if show_format_title: title = format_title + ' - ' + title pass film_item = VideoItem(title, context.create_uri(['play'], {'video_id': film['id']})) film_item.set_studio(format_title) film_item.add_artist(format_title) format_id = film['formatid'] # set image image = self.get_client(context).get_config()['images']['format-thumbnail-url'].replace('%FORMAT_ID%', format_id) pictures = film.get('pictures', []) if pictures and isinstance(pictures, dict): image = film['pictures']['pic_0'] image = self.get_client(context).get_config()['images']['episode-thumbnail-url'].replace('%PIC_ID%', image) pass film_item.set_image(image) # set fanart fanart = self.get_client(context).get_config()['images']['format-fanart-url'].replace('%FORMAT_ID%', format_id) film_item.set_fanart(fanart) # season and episode film_item.set_season(film.get('season', '1')) film_item.set_episode(film.get('episode', '1')) # aired aired = datetime_parser.parse(film['sendestart']) film_item.set_aired_from_datetime(aired) film_item.set_date_from_datetime(aired) film_item.set_year_from_datetime(aired) # duration duration = datetime_parser.parse(film['duration']) film_item.set_duration(duration.hour, duration.minute, duration.second) # plot film_item.set_plot(film['articlelong']) context_menu = [(context.localize(self._local_map['now.watch_later']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(film_item)}))] film_item.set_context_menu(context_menu) result_films.append(film_item) pass if sort: result_films = sorted(result_films, key=_sort_newest, reverse=True) pass result.extend(result_films) if add_next_page_item and page < max_page: new_params = {} new_params.update(context.get_params()) new_params['page'] = page + 1 next_page_item = kodion.items.NextPageItem(context, current_page=page, fanart=self.get_fanart(context)) result.append(next_page_item) pass return result
def _list_films(self, context, re_match, json_data, show_format_title=False, sort=True): context.get_ui().set_view_mode('videos') def _sort_newest(item): return item.get_aired() context.set_content_type(kodion.constants.content_type.EPISODES) context.add_sort_method(kodion.constants.sort_method.UNSORTED, kodion.constants.sort_method.VIDEO_YEAR, kodion.constants.sort_method.VIDEO_RUNTIME) result = [] content = json_data.get('result', {}).get('content', {}) max_page = int(content.get('maxpage', 1)) page = int(content.get('page', 1)) film_list = content.get('filmlist', {}) result_films = [] add_next_page_item = True keys = sorted(film_list.keys()) for key in keys: film = film_list[key] # as soon as we find non-free episodes we don't provide pagination # the 'continue' should skip all non-free episodes free = str(film.get('free', '0')) if free == '0': add_next_page_item = False continue title = film['headlinelong'] format_title = film['formatlong'] if show_format_title: title = format_title + ' - ' + title pass film_item = VideoItem( title, context.create_uri(['play'], {'video_id': film['id']})) film_item.set_studio(format_title) film_item.add_artist(format_title) format_id = film['formatid'] # set image image = self.get_client(context).get_config( )['images']['format-thumbnail-url'].replace( '%FORMAT_ID%', format_id) pictures = film.get('pictures', []) if pictures and isinstance(pictures, dict): image = film['pictures']['pic_0'] image = self.get_client(context).get_config( )['images']['episode-thumbnail-url'].replace( '%PIC_ID%', image) pass film_item.set_image(image) # set fanart fanart = self.get_client( context).get_config()['images']['format-fanart-url'].replace( '%FORMAT_ID%', format_id) film_item.set_fanart(fanart) # season and episode film_item.set_season(film.get('season', '1')) film_item.set_episode(film.get('episode', '1')) # aired aired = datetime_parser.parse(film['sendestart']) film_item.set_aired_from_datetime(aired) film_item.set_date_from_datetime(aired) film_item.set_year_from_datetime(aired) # duration duration = datetime_parser.parse(film['duration']) film_item.set_duration(duration.hour, duration.minute, duration.second) # plot film_item.set_plot(film['articlelong']) context_menu = [( context.localize(self._local_map['now.watch_later']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(film_item)})) ] film_item.set_context_menu(context_menu) result_films.append(film_item) pass if sort: result_films = sorted(result_films, key=_sort_newest, reverse=True) pass result.extend(result_films) if add_next_page_item and page < max_page: new_params = {} new_params.update(context.get_params()) new_params['page'] = page + 1 next_page_item = kodion.items.NextPageItem( context, current_page=page, fanart=self.get_fanart(context)) result.append(next_page_item) pass return result
def _do_video_item(self, context, item): title = item['title'] subtitle = item.get('subtitle', '') if subtitle: title = '%s - %s' % (title, subtitle) pass image = self._get_image(item, 'landscape', width=440) # we try to get a nice background based on the show show = item.get('show', {}) if not show or show is None: show = {} pass fanart = self._get_image(show, 'background', width=1280, height=720, fallback=self.get_fanart(context)) path = self._get_path_from_url(context, item, 'self') video_id = item['id'] video_item = VideoItem(title, uri=context.create_uri(['play'], {'video_id': video_id}), image=image, fanart=fanart) _plot = item.get('long_description', item.get('short_description', '')) video_item.set_plot(_plot) duration = item.get('duration', '') if duration: try: duration = kodion.utils.datetime_parser.parse(duration) seconds = duration.second seconds += duration.minute * 60 seconds += duration.hour * 60 * 60 video_item.set_duration_from_seconds(seconds) except: duration = '' pass pass # update events based on their status stream = item.get('stream', {}) if stream is None: stream = {} pass status = stream.get('status', '') if status in ['replay', 'complete']: # video_item.set_title('[B][Replay][/B] %s' % video_item.get_title()) # do nothing pass elif status in ['live']: video_item.set_title('[B][Live][/B] %s' % video_item.get_title()) pass elif status in ['pre-event', 'soon']: try: starts_at = stream.get('starts_at', '') start_time = published = kodion.utils.datetime_parser.parse(starts_at) date_str = context.format_date_short(start_time) time_str = context.format_time(start_time) video_item.set_title('[B]%s %s (GMT)[/B] %s' % (date_str, time_str, video_item.get_title())) except: video_item.set_title('[B][Upcoming][/B] %s' % video_item.get_title()) pass pass # Fallback: we try to calculate a duration based on the event if not duration: try: starts_at = stream.get('starts_at', '') ends_at = stream.get('ends_at', '') if starts_at and ends_at: start_time = published = kodion.utils.datetime_parser.parse(starts_at) end_time = published = kodion.utils.datetime_parser.parse(ends_at) duration = end_time - start_time video_item.set_duration_from_seconds(duration.seconds) pass except: # do nothing pass pass published = item.get('published_on', '') if published: published = kodion.utils.datetime_parser.parse(published) if isinstance(published, datetime.date): published = datetime.datetime(published.year, published.month, published.day, 0, 0, 0, 0) pass video_item.set_aired_from_datetime(published) video_item.set_date_from_datetime(published) video_item.set_year(published.year) video_item.set_premiered_from_datetime(published) pass season = item.get('season_number', 1) if season and season is not None: video_item.set_season(int(season)) pass episode = item.get('episode_number', 1) if episode and episode is not None: video_item.set_episode(int(episode)) pass return video_item
def _videos_to_items(self, context, videos, prepend_format_title=False): result = [] # show only free videos if not logged in or or the setting is enabled show_only_free_videos = not self.is_logged_in() or context.get_settings().get_bool('nowtv.videos.only_free', False) for video in videos: if show_only_free_videos and not video['free'] and not video['payed']: continue video_params = {'video_path': video['path'], 'video_id': str(video['id'])} title = video['title'] if prepend_format_title: title = '%s - %s' % (video['format'], title) pass if not video['free'] and not video['payed']: title = '[B][%s][/B] - %s' % (video['price'], title) video_params['free'] = '0' video_params['price'] = video['price'] pass video_item = VideoItem(title, context.create_uri([video['channel'], 'play'], video_params)) duration = datetime_parser.parse(video['duration']) video_item.set_duration(duration.hour, duration.minute, duration.second) published = datetime_parser.parse(video['published']) video_item.set_aired_from_datetime(published) video_item.set_date_from_datetime(published) video_item.set_year_from_datetime(published) video_item.set_studio(video['format']) video_item.add_artist(video['format']) video_item.set_episode(video['episode']) video_item.set_season(video['season']) video_item.set_plot(video['plot']) video_item.set_image(video['images']['thumb']) video_item.set_fanart(video['images']['fanart']) context_menu = [] if self.is_logged_in(): if context.get_path() == '/nowtv/watch_later/list/': context_menu = [(context.localize(self._local_map['nowtv.remove_from_watch_later']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'watch_later', 'delete'], {'video_id': video['id']}))] pass else: context_menu = [(context.localize(self._local_map['nowtv.add_to_watch_later']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'watch_later', 'add'], {'video_id': video['id']}))] pass else: context_menu = [(context.localize(self._local_map['nowtv.add_to_watch_later']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(video_item)}))] pass if context_menu: video_item.set_context_menu(context_menu) pass result.append(video_item) pass return result
def _videos_to_items(self, context, videos, prepend_format_title=False): result = [] # show only free videos if not logged in or or the setting is enabled show_only_free_videos = not self.is_logged_in( ) and context.get_settings().get_bool('nowtv.videos.only_free', False) for video in videos: if show_only_free_videos and not video['free'] and not video[ 'payed']: continue video_params = { 'video_path': video['path'], 'video_id': str(video['id']) } title = video['title'] if prepend_format_title: title = '%s - %s' % (video['format'], title) pass if not video['free'] and not video['payed']: title = '[B][%s][/B] - %s' % (video['price'], title) video_params['free'] = '0' video_params['price'] = video['price'] pass video_item = VideoItem( title, context.create_uri([video['channel'], 'play'], video_params)) duration = datetime_parser.parse(video['duration']) video_item.set_duration(duration.hour, duration.minute, duration.second) published = datetime_parser.parse(video['published']) video_item.set_aired_from_datetime(published) video_item.set_date_from_datetime(published) video_item.set_year_from_datetime(published) video_item.set_studio(video['format']) video_item.add_artist(video['format']) video_item.set_episode(video['episode']) video_item.set_season(video['season']) video_item.set_plot(video['plot']) video_item.set_image(video['images']['thumb']) video_item.set_fanart(video['images']['fanart']) context_menu = [] if self.is_logged_in(): if context.get_path() == '/nowtv/watch_later/list/': context_menu = [ (context.localize( self._local_map['nowtv.remove_from_watch_later']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'watch_later', 'delete'], {'video_id': video['id']})) ] pass else: context_menu = [ (context.localize( self._local_map['nowtv.add_to_watch_later']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'watch_later', 'add'], {'video_id': video['id']})) ] pass else: context_menu = [ (context.localize( self._local_map['nowtv.add_to_watch_later']), 'RunPlugin(%s)' % context.create_uri( [kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(video_item)})) ] pass if context_menu: video_item.set_context_menu(context_menu) pass result.append(video_item) pass return result
def _create_video_item_from_post(self, post, context): def _read_custom_fields(_post, field_name): custom_fields = post.get('custom_fields', {}) field = custom_fields.get(field_name, []) if len(field) >= 1: return field[0] return u'' slug = post['slug'] title = self._html_parser.unescape(post['title']) movie_item = VideoItem(title, context.create_uri('play', {'slug': slug}), image=post.get('thumbnail', '')) # stars stars = _read_custom_fields(post, 'Stars') if stars: stars = stars.split(',') for star in stars: movie_item.add_cast(star.strip()) pass pass # director director = _read_custom_fields(post, 'Regisseur') if director: movie_item.set_director(director.strip()) pass # imdb imdb = _read_custom_fields(post, 'IMDb-Link') if imdb: movie_item.set_imdb_id(imdb) pass # rating rating = _read_custom_fields(post, 'IMDb-Bewertung') if rating: rating = rating.replace(',', '.') movie_item.set_rating(rating) pass # year year = _read_custom_fields(post, 'Jahr') if year: # There was one case with '2006/2012' as a result. Therefore we split every year. year = year.split('/')[0] movie_item.set_year(year) pass # fanart fanart = _read_custom_fields(post, 'featured_img_all') if not fanart: fanart = self.get_fanart(context) pass movie_item.set_fanart(fanart) # plot plot = self._html_parser.unescape(post['content']) plot = kodion.utils.strip_html_from_text(plot) movie_item.set_plot(plot) # date added - in this case date modified (why?!?!) date = datetime_parser.parse(post['modified']) movie_item.set_date_from_datetime(date) # context menu ctx_menu = [ (context.localize(constants.localize.WATCH_LATER_ADD), 'RunPlugin(%s)' % context.create_uri([constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(movie_item)})) ] movie_item.set_context_menu(ctx_menu) return movie_item
def _create_video_item_from_post(self, post, context): def _read_custom_fields(_post, field_name): custom_fields = post.get("custom_fields", {}) field = custom_fields.get(field_name, []) if len(field) >= 1: return field[0] return u"" slug = post["slug"] title = self._html_parser.unescape(post["title"]) movie_item = VideoItem(title, context.create_uri("play", {"slug": slug}), image=post.get("thumbnail", "")) # stars stars = _read_custom_fields(post, "Stars") if stars: stars = stars.split(",") for star in stars: movie_item.add_cast(star.strip()) pass pass # director director = _read_custom_fields(post, "Regisseur") if director: movie_item.set_director(director.strip()) pass # imdb imdb = _read_custom_fields(post, "IMDb-Link") if imdb: movie_item.set_imdb_id(imdb) pass # rating rating = _read_custom_fields(post, "IMDb-Bewertung") if rating: rating = rating.replace(",", ".") movie_item.set_rating(rating) pass # year year = _read_custom_fields(post, "Jahr") if year: # There was one case with '2006/2012' as a result. Therefore we split every year. year = year.split("/")[0] movie_item.set_year(year) pass # fanart fanart = _read_custom_fields(post, "featured_img_all") if not fanart: fanart = self.get_fanart(context) pass movie_item.set_fanart(fanart) # plot plot = self._html_parser.unescape(post["content"]) plot = kodion.utils.strip_html_from_text(plot) movie_item.set_plot(plot) # date added - in this case date modified (why?!?!) date = datetime_parser.parse(post["modified"]) movie_item.set_date_from_datetime(date) # context menu ctx_menu = [ ( context.localize(constants.localize.WATCH_LATER_ADD), "RunPlugin(%s)" % context.create_uri([constants.paths.WATCH_LATER, "add"], {"item": kodion.items.to_jsons(movie_item)}), ) ] movie_item.set_context_menu(ctx_menu) return movie_item
def _create_video_item_from_post(self, post, context): def _read_custom_fields(_post, field_name): custom_fields = post.get('custom_fields', {}) field = custom_fields.get(field_name, []) if len(field) >= 1: return field[0] return u'' slug = post['slug'] title = self._html_parser.unescape(post['title']) movie_item = VideoItem(title, context.create_uri('play', {'slug': slug}), image=post.get('thumbnail', '')) # stars stars = _read_custom_fields(post, 'Stars') if stars: stars = stars.split(',') for star in stars: movie_item.add_cast(star.strip()) pass pass # director director = _read_custom_fields(post, 'Regisseur') if director: movie_item.set_director(director.strip()) pass # imdb imdb = _read_custom_fields(post, 'IMDb-Link') if imdb: movie_item.set_imdb_id(imdb) pass # rating rating = _read_custom_fields(post, 'IMDb-Bewertung') if rating: rating = rating.replace(',', '.') movie_item.set_rating(rating) pass # year year = _read_custom_fields(post, 'Jahr') if year: # There was one case with '2006/2012' as a result. Therefore we split every year. year = year.split('/')[0] movie_item.set_year(year) pass # fanart fanart = _read_custom_fields(post, 'featured_img_all') if not fanart: fanart = self.get_fanart(context) pass movie_item.set_fanart(fanart) # plot plot = self._html_parser.unescape(post['content']) plot = kodion.utils.strip_html_from_text(plot) movie_item.set_plot(plot) # date added - in this case date modified (why?!?!) date = datetime_parser.parse(post['modified']) movie_item.set_date_from_datetime(date) # context menu ctx_menu = [(context.localize(constants.localize.WATCH_LATER_ADD), 'RunPlugin(%s)' % context.create_uri([constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(movie_item)}))] movie_item.set_context_menu(ctx_menu) return movie_item
def _videos_to_items(self, context, videos, prepend_format_title=False): result = [] # show only free videos if not logged in or or the setting is enabled show_only_free_videos = not self.is_logged_in() and context.get_settings().get_bool( "nowtv.videos.only_free", False ) for video in videos: if show_only_free_videos and not video["free"] and not video["payed"]: continue video_params = {"video_path": video["path"], "video_id": str(video["id"])} title = video["title"] if prepend_format_title: title = "%s - %s" % (video["format"], title) pass if not video["free"] and not video["payed"]: title = "[B][%s][/B] - %s" % (video["price"], title) video_params["free"] = "0" video_params["price"] = video["price"] pass video_item = VideoItem(title, context.create_uri([video["channel"], "play"], video_params)) duration = datetime_parser.parse(video["duration"]) video_item.set_duration(duration.hour, duration.minute, duration.second) published = datetime_parser.parse(video["published"]) video_item.set_aired_from_datetime(published) video_item.set_date_from_datetime(published) video_item.set_year_from_datetime(published) video_item.set_studio(video["format"]) video_item.add_artist(video["format"]) video_item.set_episode(video["episode"]) video_item.set_season(video["season"]) video_item.set_plot(video["plot"]) video_item.set_image(video["images"]["thumb"]) video_item.set_fanart(video["images"]["fanart"]) context_menu = [] if self.is_logged_in(): if context.get_path() == "/nowtv/watch_later/list/": context_menu = [ ( context.localize(self._local_map["nowtv.remove_from_watch_later"]), "RunPlugin(%s)" % context.create_uri(["nowtv", "watch_later", "delete"], {"video_id": video["id"]}), ) ] pass else: context_menu = [ ( context.localize(self._local_map["nowtv.add_to_watch_later"]), "RunPlugin(%s)" % context.create_uri(["nowtv", "watch_later", "add"], {"video_id": video["id"]}), ) ] pass else: context_menu = [ ( context.localize(self._local_map["nowtv.add_to_watch_later"]), "RunPlugin(%s)" % context.create_uri( [kodion.constants.paths.WATCH_LATER, "add"], {"item": kodion.items.to_jsons(video_item)} ), ) ] pass if context_menu: video_item.set_context_menu(context_menu) pass result.append(video_item) pass return result