def play_video(provider, context, re_match): def _compare(item): vq = context.get_settings().get_video_quality() return vq - item['format'].get('video', {}).get('resolution', 0) try: video_id = context.get_param('video_id') client = provider.get_client(context) video_streams = client.get_video_streams(context, video_id) video_stream = kodion.utils.find_best_fit(video_streams, _compare) if video_stream['format'].get('rtmpe', False): message = context.localize( provider.LOCAL_MAP['youtube.error.rtmpe_not_supported']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_item = VideoItem(video_id, video_stream['url']) video_id_dict = {video_id: video_item} utils.update_video_infos(provider, context, video_id_dict) # Trigger post play events if provider.is_logged_in(): command = 'RunPlugin(%s)' % context.create_uri( ['events', 'post_play'], {'video_id': video_id}) context.execute(command) pass return video_item except YouTubeException, ex: message = ex.get_message() message = kodion.utils.strip_html_from_text(message) context.get_ui().show_notification(message, time_milliseconds=15000) pass
def add_url(self, url, provider, context): url_components = urlparse.urlparse(url) if url_components.hostname.lower( ) == 'youtube.com' or url_components.hostname.lower( ) == 'www.youtube.com': params = dict(urlparse.parse_qsl(url_components.query)) if url_components.path.lower() == '/watch': video_id = params.get('v', '') if video_id: plugin_uri = context.create_uri(['play'], {'video_id': video_id}) video_item = VideoItem('', plugin_uri) self._video_id_dict[video_id] = video_item pass playlist_id = params.get('list', '') if playlist_id: if self._flatten: self._playlist_ids.append(playlist_id) pass else: playlist_item = DirectoryItem( '', context.create_uri(['playlist', playlist_id])) playlist_item.set_fanart(provider.get_fanart(context)) self._playlist_id_dict[playlist_id] = playlist_item pass pass pass elif url_components.path.lower() == '/playlist': playlist_id = params.get('list', '') if playlist_id: if self._flatten: self._playlist_ids.append(playlist_id) pass else: playlist_item = DirectoryItem( '', context.create_uri(['playlist', playlist_id])) playlist_item.set_fanart(provider.get_fanart(context)) self._playlist_id_dict[playlist_id] = playlist_item pass pass pass elif self.RE_CHANNEL_ID.match(url_components.path): re_match = self.RE_CHANNEL_ID.match(url_components.path) channel_id = re_match.group('channel_id') if self._flatten: self._channel_ids.append(channel_id) pass else: channel_item = DirectoryItem( '', context.create_uri(['channel', channel_id])) channel_item.set_fanart(provider.get_fanart(context)) self._channel_id_dict[channel_id] = channel_item pass pass else: context.log_debug('Unknown path "%s"' % url_components.path) pass pass pass
def play_video(provider, context, re_match): try: video_id = context.get_param('video_id') client = provider.get_client(context) video_streams = client.get_video_streams(context, video_id) if len(video_streams) == 0: message = context.localize( provider.LOCAL_MAP['youtube.error.no_video_streams_found']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_stream = kodion.utils.select_stream(context, video_streams) if video_stream is None: return False if video_stream['video'].get('rtmpe', False): message = context.localize( provider.LOCAL_MAP['youtube.error.rtmpe_not_supported']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_item = VideoItem(video_id, video_stream['url']) if video_stream.get('meta', None): video_item.set_subtitles(video_stream['meta'].get( 'subtitles', None)) video_id_dict = {video_id: video_item} utils.update_video_infos(provider, context, video_id_dict) # Trigger post play events if provider.is_logged_in(): command = 'RunPlugin(%s)' % context.create_uri( ['events', 'post_play'], {'video_id': video_id}) context.execute(command) pass return video_item except YouTubeException, ex: message = ex.get_message() message = kodion.utils.strip_html_from_text(message) context.get_ui().show_notification(message, time_milliseconds=15000) pass
def play_video(provider, context, re_match): try: video_id = context.get_param('video_id') client = provider.get_client(context) video_streams = client.get_video_streams(context, video_id) if len(video_streams) == 0: message = context.localize(provider.LOCAL_MAP['youtube.error.no_video_streams_found']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_stream = kodion.utils.select_stream(context, video_streams) if video_stream is None: return False if video_stream['video'].get('rtmpe', False): message = context.localize(provider.LOCAL_MAP['youtube.error.rtmpe_not_supported']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_item = VideoItem(video_id, video_stream['url']) if video_stream.get('meta', None): video_item.set_subtitles(video_stream['meta'].get('subtitles', None)) video_id_dict = {video_id: video_item} utils.update_video_infos(provider, context, video_id_dict) # Trigger post play events if provider.is_logged_in(): command = 'RunPlugin(%s)' % context.create_uri(['events', 'post_play'], {'video_id': video_id}) context.execute(command) pass return video_item except YouTubeException, ex: message = ex.get_message() message = kodion.utils.strip_html_from_text(message) context.get_ui().show_notification(message, time_milliseconds=15000) pass
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 _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 _screen_object_to_item(self, context, screen_object, show_format_title=False): screen_object_type = screen_object.get('type', '') if screen_object_type == '': raise kodion.KodimonException('Missing type for screenObject') fanart = self.get_fanart(context) format_id = screen_object.get('format_id', screen_object.get('id', '')).split(':') if len(format_id) == 2: channel_id = format_id[0] format_id = format_id[1] if channel_id == 'tvog': channel_id = 'pro7' pass data = self._load_format_content(context, channel_id, format_id, return_cached_only=True) fanart = data.get('fanart', self.get_fanart(context)) pass if screen_object_type == 'video_item_date_no_label' or screen_object_type == 'video_item_date' \ or screen_object_type == 'video_item_format_no_label' or screen_object_type == 'video_item_format': name = screen_object.get('title', screen_object['video_title']) if screen_object_type == 'video_item_format_no_label' or show_format_title: name = '%s - %s' % (screen_object['format_title'], name) pass video_item = VideoItem(name, context.create_uri(['play'], {'id': screen_object['id']}), image=screen_object.get('image_url', '')) video_item.set_fanart(fanart) video_item.set_duration_from_seconds(int(screen_object.get('duration', '60'))) date_time = datetime_parser.parse(screen_object.get('start', '0000-00-00')) video_item.set_aired_from_datetime(date_time) video_item.set_premiered_from_datetime(date_time) video_item.set_year_from_datetime(date_time) try_set_season_and_episode(video_item) context_menu = [(context.localize(kodion.constants.localize.WATCH_LATER), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(video_item)}))] video_item.set_context_menu(context_menu) return video_item elif screen_object_type == 'format_item_home' or screen_object_type == 'format_item': format_item = DirectoryItem(screen_object['title'], context.create_uri([channel_id, 'library', format_id]), image=screen_object['image_url']) format_item.set_fanart(fanart) context_menu = [(context.localize(kodion.constants.localize.FAVORITES_ADD), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)}))] format_item.set_context_menu(context_menu) return format_item raise kodion.KodimonException("Unknown type '%s' for screen_object" % screen_object_type)
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() 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 make_video_item_from_json_data(context, provider, json_data, playlist_item_id_dict={}): video_id = json_data['id'] video_item = VideoItem(json_data['title'], uri=context.create_uri(['play'], {'video_id': video_id})) video_item.set_image(json_data.get('image', '')) """ This is experimental. We try to get the most information out of the title of a video. This is not based on any language. In some cases this won't work at all. TODO: via language and settings provide the regex for matching episode and season. """ video_item.set_season(1) video_item.set_episode(1) for regex in __RE_SEASON_EPISODE_MATCHES__: re_match = regex.search(video_item.get_name()) if re_match: if 'season' in re_match.groupdict(): video_item.set_season(int(re_match.group('season'))) pass if 'episode' in re_match.groupdict(): video_item.set_episode(int(re_match.group('episode'))) pass break pass settings = context.get_settings() # plot channel_name = json_data.get('channel-title', '') description = kodion.utils.strip_html_from_text(json_data.get('description', '')) if channel_name and settings.get_bool('youtube.view.description.show_channel_name', True): description = '[UPPERCASE][B]%s[/B][/UPPERCASE][CR][CR]%s' % (channel_name, description) pass video_item.set_studio(channel_name) # video_item.add_cast(channel_name) video_item.add_artist(channel_name) video_item.set_plot(description) # date time date_str = json_data.get('date', '') if date_str: datetime = utils.datetime_parser.parse() video_item.set_year_from_datetime(datetime) video_item.set_aired_from_datetime(datetime) video_item.set_premiered_from_datetime(datetime) pass # duration duration = json_data.get('duration', '') if duration: duration = utils.datetime_parser.parse(duration) # we subtract 1 seconds because YouTube returns +1 second to much video_item.set_duration_from_seconds(duration.seconds - 1) pass # set fanart video_item.set_fanart(provider.get_fanart(context)) context_menu = [] replace_context_menu = False # Refresh ('My Subscriptions', all my playlists) if context.get_path() == '/special/new_uploaded_videos/' or context.get_path().startswith( '/channel/mine/playlist/'): yt_context_menu.append_refresh(context_menu, provider, context) pass # Queue Video yt_context_menu.append_queue_video(context_menu, provider, context) # play all videos of the playlist some_playlist_match = re.match('^/channel/(.+)/playlist/(?P<playlist_id>.*)/$', context.get_path()) if some_playlist_match: replace_context_menu = True playlist_id = some_playlist_match.group('playlist_id') yt_context_menu.append_play_all_from_playlist(context_menu, provider, context, playlist_id, video_id) yt_context_menu.append_play_all_from_playlist(context_menu, provider, context, playlist_id) pass # 'play with...' (external player) if context.get_settings().is_support_alternative_player_enabled(): yt_context_menu.append_play_with(context_menu, provider, context) pass my_playlists = {} if provider.is_logged_in(): resource_manager = provider.get_resource_manager(context) my_playlists = resource_manager.get_related_playlists(channel_id='mine') pass if provider.is_logged_in(): # add 'Watch Later' only if we are not in my 'Watch Later' list watch_later_playlist_id = my_playlists.get('watchLater', '') yt_context_menu.append_watch_later(context_menu, provider, context, watch_later_playlist_id, video_id) pass channel_id = json_data.get('channel-id', '') # got to [CHANNEL] if channel_id and channel_name: # only if we are not directly in the channel provide a jump to the channel if kodion.utils.create_path('channel', channel_id) != context.get_path(): yt_context_menu.append_go_to_channel(context_menu, provider, context, channel_id, channel_name) pass pass # description links yt_context_menu.append_content_from_description(context_menu, provider, context, video_id) # find related videos yt_context_menu.append_related_videos(context_menu, provider, context, video_id) if provider.is_logged_in(): # add 'Like Video' only if we are not in my 'Liked Videos' list refresh_container = context.get_path().startswith( '/channel/mine/playlist/LL') or context.get_path() == '/special/disliked_videos/' yt_context_menu.append_rate_video(context_menu, provider, context, video_id, refresh_container) # add video to a selected playlist yt_context_menu.append_add_video_to_playlist(context_menu, provider, context, video_id) # provide 'remove' for videos in my playlists if video_id in playlist_item_id_dict: playlist_match = re.match('^/channel/mine/playlist/(?P<playlist_id>.*)/$', context.get_path()) if playlist_match: playlist_id = playlist_match.group('playlist_id') # we support all playlist except 'Watch History' if not playlist_id.startswith('HL'): playlist_item_id = playlist_item_id_dict[video_id] context_menu.append((context.localize(provider.LOCAL_MAP['youtube.remove']), 'RunPlugin(%s)' % context.create_uri( ['playlist', 'remove', 'video'], {'playlist_id': playlist_id, 'video_id': playlist_item_id, 'video_name': video_item.get_name()}))) pass pass pass # subscribe to the channel of the video yt_context_menu.append_subscribe_to_channel(context_menu, provider, context, channel_id, channel_name) pass if len(context_menu) > 0: video_item.set_context_menu(context_menu, replace=replace_context_menu) pass return video_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 play_video(provider, context, re_match): try: video_id = context.get_param('video_id') client = provider.get_client(context) try: f = open(context._get_cache_path() + '/history.json', 'r') history = json.load(f) except: history = {} if not video_id in history: f = open(context._get_cache_path() + '/history.json', 'w') stamp = datetime.now().strftime('%s') history[video_id] = stamp json.dump(history, f) video_streams = client.get_video_streams(context, video_id) if len(video_streams) == 0: message = context.localize( provider.LOCAL_MAP['youtube.error.no_video_streams_found']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_stream = kodion.utils.select_stream(context, video_streams) if video_stream is None: return False if video_stream['video'].get('rtmpe', False): message = context.localize( provider.LOCAL_MAP['youtube.error.rtmpe_not_supported']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_item = VideoItem(video_id, video_stream['url']) if video_stream.get('meta', None): video_item.set_subtitles(video_stream['meta'].get( 'subtitles', None)) video_id_dict = {video_id: video_item} utils.update_video_infos(provider, context, video_id_dict) #get related video and set to queue videos = [] json_data = client.get_related_videos(video_id) if not v3.handle_error(provider, context, json_data): return False result = v3.response_to_items(provider, context, json_data, process_next_page=False) videos.extend(result) context.log_debug('video: "%s' % videos[0].get_uri()) playlist = context.get_video_playlist() for x in videos: r = re.compile("video_id=(.*)") m = r.search(x.get_uri()) vid = m.group(1) if vid not in history: playlist.add(x) break # Trigger post play events if provider.is_logged_in(): command = 'RunPlugin(%s)' % context.create_uri( ['events', 'post_play'], {'video_id': video_id}) context.execute(command) pass return video_item except YouTubeException, ex: message = ex.get_message() message = kodion.utils.strip_html_from_text(message) context.get_ui().show_notification(message, time_milliseconds=15000) pass
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 _screen_object_to_item(self, context, screen_object, show_format_title=False): screen_object_type = screen_object.get('type', '') if screen_object_type == '': raise kodion.KodimonException('Missing type for screenObject') fanart = self.get_fanart(context) format_id = screen_object.get('format_id', screen_object.get('id', '')).split(':') if len(format_id) == 2: channel_id = format_id[0] format_id = format_id[1] if channel_id == 'tvog': channel_id = 'pro7' pass data = self._load_format_content(context, channel_id, format_id, return_cached_only=True) fanart = data.get('fanart', self.get_fanart(context)) pass if screen_object_type == 'video_item_date_no_label' or screen_object_type == 'video_item_date' \ or screen_object_type == 'video_item_format_no_label' or screen_object_type == 'video_item_format': name = screen_object.get('title', screen_object['video_title']) if screen_object_type == 'video_item_format_no_label' or show_format_title: name = '%s - %s' % (screen_object['format_title'], name) pass video_item = VideoItem(name, context.create_uri( ['play'], {'id': screen_object['id']}), image=screen_object.get('image_url', '')) video_item.set_fanart(fanart) video_item.set_duration_from_seconds( int(screen_object.get('duration', '60'))) date_time = datetime_parser.parse( screen_object.get('start', '0000-00-00')) video_item.set_aired_from_datetime(date_time) video_item.set_premiered_from_datetime(date_time) video_item.set_year_from_datetime(date_time) try_set_season_and_episode(video_item) context_menu = [ (context.localize(kodion.constants.localize.WATCH_LATER), 'RunPlugin(%s)' % context.create_uri( [kodion.constants.paths.WATCH_LATER, 'add'], {'item': kodion.items.to_jsons(video_item)})) ] video_item.set_context_menu(context_menu) return video_item elif screen_object_type == 'format_item_home' or screen_object_type == 'format_item': format_item = DirectoryItem( screen_object['title'], context.create_uri([channel_id, 'library', format_id]), image=screen_object['image_url']) format_item.set_fanart(fanart) context_menu = [ (context.localize(kodion.constants.localize.FAVORITES_ADD), 'RunPlugin(%s)' % context.create_uri( [kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)})) ] format_item.set_context_menu(context_menu) return format_item raise kodion.KodimonException("Unknown type '%s' for screen_object" % screen_object_type)
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 _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 do_xml_video_response(context, provider, video_xml): if isinstance(video_xml, basestring): video_xml = ET.fromstring(video_xml) do_xml_error(context, provider, video_xml) video_xml = video_xml.find('video') pass video_id = video_xml.get('id') title = video_xml.find('title').text video_item = VideoItem(title, context.create_uri(['play'], {'video_id': video_id})) # channel name channel_name = '' owner = video_xml.find('owner') if owner is not None: channel_name = owner.get('username') pass video_item.set_studio(channel_name) video_item.add_artist(channel_name) # date upload_date = video_xml.find('upload_date') if upload_date is not None and upload_date.text is not None: upload_date = upload_date.text upload_date = upload_date.split(' ') if len(upload_date) == 2: date = upload_date[0].split('-') time = upload_date[1].split(':') if len(date) == 3 and len(time) == 3: video_item.set_date(int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2])) video_item.set_year(int(date[0])) video_item.set_aired(int(date[0]), int(date[1]), int(date[2])) video_item.set_premiered(int(date[0]), int(date[1]), int(date[2])) pass pass pass # plot plot = video_xml.find('description').text if plot is None: plot = '' pass settings = context.get_settings() if channel_name and settings.get_bool('vimeo.view.description.show_channel_name', True): plot = '[UPPERCASE][B]%s[/B][/UPPERCASE][CR][CR]%s' % (channel_name, plot) pass video_item.set_plot(plot) # duration duration = int(video_xml.find('duration').text) if duration is not None: video_item.set_duration_from_seconds(duration) pass # thumbs thumbnails = video_xml.find('thumbnails') if thumbnails is not None: for thumbnail in thumbnails: height = int(thumbnail.get('height')) if height >= 360: video_item.set_image(thumbnail.text) break pass pass video_item.set_fanart(provider.get_fanart(context)) # context menu context_menu = [] if provider.is_logged_in(): # like/unlike is_like = video_xml.get('is_like') == '1' if is_like: like_text = context.localize(provider._local_map['vimeo.unlike']) context_menu.append( (like_text, 'RunPlugin(%s)' % context.create_uri(['video', 'unlike'], {'video_id': video_id}))) else: like_text = context.localize(provider._local_map['vimeo.like']) context_menu.append( (like_text, 'RunPlugin(%s)' % context.create_uri(['video', 'like'], {'video_id': video_id}))) pass # watch later is_watch_later = video_xml.get('is_watchlater') == '1' if is_watch_later: watch_later_text = context.localize(provider._local_map['vimeo.watch-later.remove']) context_menu.append( (watch_later_text, 'RunPlugin(%s)' % context.create_uri(['video', 'watch-later', 'remove'], {'video_id': video_id}))) else: watch_later_text = context.localize(provider._local_map['vimeo.watch-later.add']) context_menu.append( (watch_later_text, 'RunPlugin(%s)' % context.create_uri(['video', 'watch-later', 'add'], {'video_id': video_id}))) pass # add to * (album, channel or group) context_menu.append((context.localize(provider._local_map['vimeo.video.add-to']), 'RunPlugin(%s)' % context.create_uri(['video', 'add-to'], {'video_id': video_id}))) # remove from * (album, channel or group) context_menu.append((context.localize(provider._local_map['vimeo.video.remove-from']), 'RunPlugin(%s)' % context.create_uri(['video', 'remove-from'], {'video_id': video_id}))) pass # Go to user owner = video_xml.find('owner') if owner is not None: owner_name = owner.get('display_name') owner_id = owner.get('id') context_menu.append((context.localize(provider._local_map['vimeo.user.go-to']) % '[B]' + owner_name + '[/B]', 'Container.Update(%s)' % context.create_uri(['user', owner_id]))) pass video_item.set_context_menu(context_menu) return video_item
def play_video(provider, context, re_match): try: video_id = context.get_param('video_id') client = provider.get_client(context) video_streams = client.get_video_streams(context, video_id) if len(video_streams) == 0: message = context.localize( provider.LOCAL_MAP['youtube.error.no_video_streams_found']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_stream = None if context.get_settings().use_debrid(): import urlresolver resolver_url = 'http://youtube.com/watch?v=%s' % video_id hmf = urlresolver.HostedMediaFile(url=resolver_url) resolved = hmf.resolve() if not resolved or not isinstance(resolved, basestring): try: message = resolved.msg except: message = 'Reason unknown, refer to URLResolver debug logging.' context.log_warning('URLResolver unable to resolve: %s\n%s' % (resolver_url, message)) elif resolved.startswith('plugin://'): context.log_warning( 'URLResolver unusable result: %s\nCheck the log above for debrid resolver errors, ' 'confirm debrid resolver is enabled, and has a lower number set in the priority ' 'setting than the YouTube(or offending) resolver.' % resolved) else: video_stream = { 'container': 'URLResolver', 'title': video_streams[0]['title'], 'url': resolved, 'meta': video_streams[0]['meta'], 'video': { 'encoding': '', 'height': 0 }, 'audio': { 'bitrate': 0, 'encoding': '' } } context.log_debug( 'URLResolver resolved now using video_stream:\n%s' % video_stream) if not video_stream: video_stream = kodion.utils.select_stream(context, video_streams) if video_stream is None: return False if video_stream['video'].get('rtmpe', False): message = context.localize( provider.LOCAL_MAP['youtube.error.rtmpe_not_supported']) context.get_ui().show_notification(message, time_milliseconds=5000) return False video_item = VideoItem(video_id, video_stream['url']) if video_stream.get('meta', None): video_item.set_subtitles(video_stream['meta'].get( 'subtitles', None)) video_id_dict = {video_id: video_item} utils.update_video_infos(provider, context, video_id_dict) # Trigger post play events if provider.is_logged_in(): command = 'RunPlugin(%s)' % context.create_uri( ['events', 'post_play'], {'video_id': video_id}) context.execute(command) pass return video_item except YouTubeException, ex: message = ex.get_message() message = kodion.utils.strip_html_from_text(message) context.get_ui().show_notification(message, time_milliseconds=15000) pass