def _on_explore_genre(self, context, re_match): result = [] genre = re_match.group('genre') if not genre: json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_categories) category = re_match.group('category') genres = json_data.get(category, []) for genre in genres: title = genre['title'] genre_item = DirectoryItem(title, context.create_uri(['explore', 'genre', category, title])) genre_item.set_fanart(self.get_fanart(context)) result.append(genre_item) pass else: params = context.get_params() page = int(params.get('page', 1)) json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_genre, genre=genre, page=page) path = context.get_path() result = self._do_mobile_collection(context, json_data, path, params) pass return result
def _get_channel_formats(self, context, re_match): self._set_sort_method_for_content_type(context, kodion.constants.content_type.TV_SHOWS) result = [] # load the formats of the given channel channel_id = re_match.group('channelid') json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self._get_client(context).get_formats, self._get_client(context). API_V2, channel_id) screen = json_data.get('screen', {}) screen_objects = screen.get('screen_objects', {}) for screen_object in screen_objects: format_id = screen_object['id'].split(':') channel_id = format_id[0] format_id = format_id[1] format_item = DirectoryItem(screen_object['title'], context.create_uri([channel_id, 'library', format_id]), image=screen_object['image_url']) fanart = self.get_fanart(context) data = self._load_format_content(context, channel_id, format_id, return_cached_only=True) if data is not None: fanart = data.get('fanart', self.get_fanart(context)) pass 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) result.append(format_item) pass return self._sort_result_by_name(result)
def _display_channels(_channel_ids): _channel_id_dict = {} for channel_id in _channel_ids: channel_item = DirectoryItem( '', context.create_uri(['channel', channel_id])) channel_item.set_fanart(provider.get_fanart(context)) _channel_id_dict[channel_id] = channel_item pass _channel_item_dict = {} utils.update_channel_infos(provider, context, _channel_id_dict, channel_items_dict=_channel_item_dict) utils.update_fanarts(provider, context, _channel_item_dict) # clean up - remove empty entries _result = [] for key in _channel_id_dict: _channel_item = _channel_id_dict[key] if _channel_item.get_name(): _result.append(_channel_item) pass pass return _result
def _on_explore_genre(self, context, re_match): result = [] genre = re_match.group('genre') if not genre: json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_categories) category = re_match.group('category') genres = json_data.get(category, []) for genre in genres: title = genre['title'] genre_item = DirectoryItem(title, context.create_uri(['explore', 'genre', category, title])) genre_item.set_fanart(self.get_fanart(context)) result.append(genre_item) pass else: context.set_content_type(kodion.constants.content_type.SONGS) params = context.get_params() page = int(params.get('page', 1)) json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_genre, genre=genre, page=page) path = context.get_path() result = self._do_mobile_collection(context, json_data, path, params) pass return result
def on_root(self, context, re_match): result = [] # favorites if len(context.get_favorite_list().list()) > 0: fav_item = kodion.items.FavoritesItem(context, fanart=self.get_fanart(context)) fav_item.set_name('[B]%s[/B]' % fav_item.get_name()) result.append(fav_item) pass # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = kodion.items.WatchLaterItem(context, fanart=self.get_fanart(context)) result.append(watch_later_item) pass # list channels for channel_id in self._channel_ids: channel_config = Client.CHANNELS[channel_id] channel_id = channel_config['id'] channel_title = channel_config['title'] channel_item = DirectoryItem(channel_title, context.create_uri([channel_id, 'formats'])) channel_item.set_fanart(context.create_resource_path('media', channel_id, 'background.jpg')) channel_item.set_image(context.create_resource_path('media', channel_id, 'logo.png')) result.append(channel_item) pass # search search_item = kodion.items.SearchItem(context, image=context.create_resource_path('media', 'search.png'), fanart=self.get_fanart(context)) result.append(search_item) return result
def on_channel_format(self, context, re_match): channel_id = re_match.group("channel_id") format_id = re_match.group("format_id") channel_config = Client.CHANNELS[channel_id] client = self.get_client(context) # try to process tabs seo_url = context.get_param("seoUrl", "") if not seo_url: raise KodionException("seoUrl missing") format_tabs = client.get_format_tabs(channel_config, seo_url) # only on season tab -> show the content directly if len(format_tabs) == 1 and format_tabs[0]["type"] == "tab": format_tab = format_tabs[0] return self._on_channel_format_list(context, channel_config, format_tab["id"]) # show the tabs/sections tabs = [] for format_tab in format_tabs: if format_tab["type"] == "tab": tab_item = DirectoryItem( format_tab["title"], # /[CHANNEL_ID]/format/[FORMAT_ID]/list/[FORMAT_LIST_ID]/ context.create_uri([channel_id, "format", format_id, "list", str(format_tab["id"])]), ) tab_item.set_image(format_tab["images"]["thumb"]) tab_item.set_fanart(format_tab["images"]["fanart"]) tabs.append(tab_item) pass elif format_tab["type"] == "date-span": tab_title = format_tab["title"] image = format_tab["images"]["thumb"] fanart = format_tab["images"]["fanart"] tab_item = DirectoryItem( tab_title, # /[CHANNEL_ID]/format/[FORMAT_ID]/year/[YEAR]/ context.create_uri( [channel_id, "format", format_id, "year", tab_title], {"start": format_tab["start"], "end": format_tab["end"], "image": image, "fanart": fanart}, ), ) tab_item.set_image(image) tab_item.set_fanart(fanart) tabs.append(tab_item) pass else: raise KodionException('Unknown type "%s" for tab' % format_tab["type"]) pass return tabs
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 _get_channel_highlights(self, context, re_match): result = [] channel_id = re_match.group('channelid') channel_image = context.create_resource_path('media', 'channels' '%s.png' % channel_id) category = re_match.group('category') if category is None: # Popular Shows item = DirectoryItem(context.localize(self._local_map['7tv.popular_shows']), context.create_uri([channel_id, 'highlights', 'Beliebte Sendungen']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Current Entire Episodes item = DirectoryItem(context.localize(self._local_map['7tv.current_entire_episodes']), context.create_uri([channel_id, 'highlights', 'Aktuelle ganze Folgen']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Newest Clips item = DirectoryItem(context.localize(self._local_map['7tv.newest_clips']), context.create_uri([channel_id, 'highlights', 'Neueste Clips']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) else: json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 5, self._get_client(context).get_homepage, self._get_client(context).API_V2, channel_id) screen = json_data.get('screen', {}) screen_objects = screen.get('screen_objects', []) for screen_object in screen_objects: if screen_object.get('type', '') == 'sushi_bar': if screen_object.get('title', '') == category: sub_screen_objects = screen_object.get('screen_objects', []) for sub_screen_object in sub_screen_objects: result.append(self._screen_object_to_item(context, sub_screen_object, show_format_title=(category == 'Neueste Clips'))) pass break pass pass if category == 'Beliebte Sendungen': self._set_sort_method_for_content_type(context, kodion.constants.content_type.TV_SHOWS) result = self._sort_result_by_name(result) else: self._set_sort_method_for_content_type(context, kodion.constants.content_type.EPISODES) result = self._sort_result_by_aired(result) pass return result
def on_search(self, search_text, context, re_match): result = [] params = context.get_params() page = int(params.get('page', 1)) category = params.get('category', 'sounds') path = context.get_path() if page == 1 and category == 'sounds': people_params = {} people_params.update(params) people_params['category'] = 'people' people_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.people']) + '[/B]', context.create_uri(path, people_params), image=context.create_resource_path('media', 'users.png')) people_item.set_fanart(self.get_fanart(context)) result.append(people_item) playlist_params = {} playlist_params.update(params) playlist_params['category'] = 'sets' playlist_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.playlists']) + '[/B]', context.create_uri(path, playlist_params), image=context.create_resource_path('media', 'playlists.png')) playlist_item.set_fanart(self.get_fanart(context)) result.append(playlist_item) pass json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).search, search_text, category=category, page=page) result.extend(self._do_collection(context, json_data, path, params)) return result
def on_channel_format(self, context, re_match): channel_id = re_match.group('channel_id') format_id = re_match.group('format_id') channel_config = Client.CHANNELS[channel_id] client = self.get_client(context) # try to process tabs seo_url = context.get_param('seoUrl', '') if not seo_url: raise KodionException('seoUrl missing') format_tabs = client.get_format_tabs(channel_config, seo_url) # only on season tab -> show the content directly if len(format_tabs) == 1 and format_tabs[0]['type'] == 'tab': format_tab = format_tabs[0] return self._on_channel_format_list(context, channel_config, format_tab['id']) # show the tabs/sections tabs = [] for format_tab in format_tabs: if format_tab['type'] == 'tab': tab_item = DirectoryItem(format_tab['title'], # /[CHANNEL_ID]/format/[FORMAT_ID]/list/[FORMAT_LIST_ID]/ context.create_uri( [channel_id, 'format', format_id, 'list', str(format_tab['id'])])) tab_item.set_image(format_tab['images']['thumb']) tab_item.set_fanart(format_tab['images']['fanart']) tabs.append(tab_item) pass elif format_tab['type'] == 'date-span': tab_title = format_tab['title'] image = format_tab['images']['thumb'] fanart = format_tab['images']['fanart'] tab_item = DirectoryItem(tab_title, # /[CHANNEL_ID]/format/[FORMAT_ID]/year/[YEAR]/ context.create_uri([channel_id, 'format', format_id, 'year', tab_title], {'start': format_tab['start'], 'end': format_tab['end'], 'image': image, 'fanart': fanart})) tab_item.set_image(image) tab_item.set_fanart(fanart) tabs.append(tab_item) pass else: raise KodionException('Unknown type "%s" for tab' % format_tab['type']) pass return tabs
def _get_channel_content(self, context, re_match): channel_id = re_match.group('channelid') result = [] channel_image = context.create_resource_path('media', 'channels', '%s.png' % channel_id) # Highlights item = DirectoryItem(context.localize( kodion.constants.localize.HIGHLIGHTS), context.create_uri([channel_id, 'highlights']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Library item = DirectoryItem(context.localize( kodion.constants.localize.LIBRARY), context.create_uri([channel_id, 'library']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) return result
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 on_channel_format_per_year(self, context, re_match): result = [] channel_id = re_match.group('channel_id') format_id = re_match.group('format_id') year = re_match.group('year') start_date_param = context.get_param('start') start_date = datetime.datetime(*time.strptime(start_date_param, '%Y-%m-%d %H:%M:%S')[:6]) end_date_param = context.get_param('end') end_date = datetime.datetime(*time.strptime(end_date_param, '%Y-%m-%d %H:%M:%S')[:6]) image = context.get_param('image', '') fanart = context.get_param('fanart', self.get_fanart(context)) for month in range(start_date.month, end_date.month + 1): month_text = context.localize(30510 + month - 1) month_item = DirectoryItem(month_text, # /[CHANNEL_ID]/format/[FORMAT_ID]/year/[year]/month/[month]/ context.create_uri( [channel_id, 'format', format_id, 'year', year, 'month', str(month)], {'start': start_date_param, 'end': end_date_param}), image=image, fanart=fanart) result.append(month_item) pass # reverse order of the month result = result[::-1] return result
def _do_formats(self, context, json_formats): result = [] formats = json_formats.get('items', []) # 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 format_data in formats: if show_only_free_videos and not format_data['free']: continue format_title = format_data['title'] params = {} if format_data.get('seoUrl', ''): params['seoUrl'] = format_data['seoUrl'] pass format_item = DirectoryItem( format_title, # /rtl/format/2/ context.create_uri( [format_data['station'], 'format', str(format_data['id'])], params)) format_item.set_image(format_data['images']['thumb']) format_item.set_fanart(format_data['images']['fanart']) result.append(format_item) if self.is_logged_in(): if context.get_path() == '/nowtv/favorites/list/': context_menu = [ (context.localize( self._local_map['nowtv.remove_from_favs']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'delete'], {'format_id': format_data['id']})) ] pass else: context_menu = [ (context.localize( self._local_map['nowtv.add_to_favs']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'add'], {'format_id': format_data['id']})) ] pass else: context_menu = [ (context.localize(self._local_map['nowtv.add_to_favs']), 'RunPlugin(%s)' % context.create_uri( [kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)})) ] pass format_item.set_context_menu(context_menu) pass return result
def on_search(self, search_text, context, re_match): context.get_ui().set_view_mode('videos') result = [] json_data = self.get_client(context).search(search_text) list = json_data.get('result', {}).get('content', {}).get('list', {}) for key in list: item = list[key] title = item['result'] format_id = item['formatid'] search_item = DirectoryItem(title, context.create_uri(['format', format_id])) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) pass return result
def on_search(self, search_text, context, re_match): context.get_ui().set_view_mode('videos') result = [] json_data = self.get_client(context).search(search_text) list = json_data.get('result', {}).get('content', {}).get('list', {}) for key in list: item = list[key] title = item['result'] format_id = item['formatid'] search_item = DirectoryItem( title, context.create_uri(['format', format_id])) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) pass return result
def _feed_to_item(self, json_data, context): result = [] data = json_data['data']['data'] for item in data: gallery_item = DirectoryItem(item['title'], context.create_uri(['show', str(item['id'])])) gallery_item.set_fanart(self.get_fanart(context)) image = item.get('thumbnails', []) if len(image) > 0: image = image[0].get('url', '') gallery_item.set_image(image) pass result.append(gallery_item) pass return result
def _do_formats(self, context, json_formats): result = [] formats = json_formats.get("items", []) # 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 format_data in formats: if show_only_free_videos and not format_data["free"]: continue format_title = format_data["title"] params = {} if format_data.get("seoUrl", ""): params["seoUrl"] = format_data["seoUrl"] pass format_item = DirectoryItem( format_title, # /rtl/format/2/ context.create_uri([format_data["station"], "format", str(format_data["id"])], params), ) format_item.set_image(format_data["images"]["thumb"]) format_item.set_fanart(format_data["images"]["fanart"]) result.append(format_item) if self.is_logged_in(): if context.get_path() == "/nowtv/favorites/list/": context_menu = [ ( context.localize(self._local_map["nowtv.remove_from_favs"]), "RunPlugin(%s)" % context.create_uri(["nowtv", "favorites", "delete"], {"format_id": format_data["id"]}), ) ] pass else: context_menu = [ ( context.localize(self._local_map["nowtv.add_to_favs"]), "RunPlugin(%s)" % context.create_uri(["nowtv", "favorites", "add"], {"format_id": format_data["id"]}), ) ] pass else: context_menu = [ ( context.localize(self._local_map["nowtv.add_to_favs"]), "RunPlugin(%s)" % context.create_uri( [kodion.constants.paths.FAVORITES, "add"], {"item": kodion.items.to_jsons(format_item)} ), ) ] pass format_item.set_context_menu(context_menu) pass return result
def test_latest_videos(self): provider = Provider() context = kodion.Context(path='/favs/latest/') format_item = DirectoryItem( u'Test', context.create_uri(['pro7', 'library', '277'])) context.get_favorite_list().add(format_item) result = provider.navigate(context) items = result[0] pass
def _display_playlists(_playlist_ids): _playlist_id_dict = {} for playlist_id in _playlist_ids: playlist_item = DirectoryItem('', context.create_uri(['playlist', playlist_id])) playlist_item.set_fanart(provider.get_fanart(context)) _playlist_id_dict[playlist_id] = playlist_item pass _channel_item_dict = {} utils.update_playlist_infos(provider, context, _playlist_id_dict, _channel_item_dict) utils.update_fanarts(provider, context, _channel_item_dict) # clean up - remove empty entries _result = [] for key in _playlist_id_dict: _playlist_item = _playlist_id_dict[key] if _playlist_item.get_name(): _result.append(_playlist_item) pass return _result
def on_channel_format(self, context, re_match): channel_id = re_match.group('channel_id') channel_config = Client.CHANNELS[channel_id] client = self.get_client(context) # try to process tabs seo_url = context.get_param('seoUrl', '') if seo_url: format_tabs = client.get_format_tabs(channel_config, seo_url) # with only one tab we could display the whole list of videos if len(format_tabs) == 1: format_tab = format_tabs[0] return self._on_channel_format_list(context, channel_config, format_tab['id']) # show the tabs/sections tabs = [] for format_tab in format_tabs: if format_tab['type'] == 'season' or format_tab['type'] == 'year': tab_item = DirectoryItem(format_tab['title'], context.create_uri([channel_id, 'formatlist', str(format_tab['id'])])) tab_item.set_image(format_tab['images']['thumb']) tab_item.set_fanart(format_tab['images']['fanart']) tabs.append(tab_item) pass elif format_tab['type'] == 'year': tab_item = DirectoryItem(format_tab['title'], context.create_uri([channel_id, 'yearlist', str(format_tab['id'])])) tab_item.set_image(format_tab['images']['thumb']) tab_item.set_fanart(format_tab['images']['fanart']) tabs.append(tab_item) pass else: raise KodionException('Unknown type "%s" for tab' % format_tab['type']) pass return tabs format_id = re_match.group('format_id') return []
def _display_channels(_channel_ids): _channel_id_dict = {} for channel_id in _channel_ids: channel_item = DirectoryItem('', context.create_uri(['channel', channel_id])) channel_item.set_fanart(provider.get_fanart(context)) _channel_id_dict[channel_id] = channel_item pass _channel_item_dict = {} utils.update_channel_infos(provider, context, _channel_id_dict, channel_items_dict=_channel_item_dict) utils.update_fanarts(provider, context, _channel_item_dict) # clean up - remove empty entries _result = [] for key in _channel_id_dict: _channel_item = _channel_id_dict[key] if _channel_item.get_name(): _result.append(_channel_item) pass pass return _result
def get_items(self, provider, context): result = [] if self._flatten and len(self._channel_ids) > 0: # remove duplicates self._channel_ids = list(set(self._channel_ids)) channels_item = DirectoryItem( '[B]' + context.localize(provider.LOCAL_MAP['youtube.channels']) + '[/B]', context.create_uri( ['special', 'description_links'], {'channel_ids': ','.join(self._channel_ids)}), context.create_resource_path('media', 'playlist.png')) channels_item.set_fanart(provider.get_fanart(context)) result.append(channels_item) pass if self._flatten and len(self._playlist_ids) > 0: # remove duplicates self._playlist_ids = list(set(self._playlist_ids)) playlists_item = DirectoryItem( '[B]' + context.localize(provider.LOCAL_MAP['youtube.playlists']) + '[/B]', context.create_uri( ['special', 'description_links'], {'playlist_ids': ','.join(self._playlist_ids)}), context.create_resource_path('media', 'playlist.png')) playlists_item.set_fanart(provider.get_fanart(context)) result.append(playlists_item) pass if not self._flatten: result.extend(self.get_channel_items(provider, context)) pass if not self._flatten: result.extend(self.get_playlist_items(provider, context)) pass # add videos result.extend(self.get_video_items(provider, context)) return result
def _on_library(self, context, re_match): context.set_content_type(kodion.constants.content_type.TV_SHOWS) context.add_sort_method(kodion.constants.sort_method.LABEL) result = [] json_data = context.get_function_cache().get( FunctionCache.ONE_HOUR, self.get_client(context).get_formats) format_list = json_data.get('result', {}).get('content', {}).get('formatlist') for key in format_list: now_format = format_list[key] title = now_format['formatlong'] format_id = now_format['formatid'] free_episodes = int(now_format.get('free_episodes', '0')) if free_episodes >= 1: format_item = DirectoryItem( title, context.create_uri(['format', format_id])) # set image image = self.get_client(context).get_config( )['images']['format-thumbnail-url'].replace( '%FORMAT_ID%', format_id) format_item.set_image(image) # set fanart fanart = self.get_client(context).get_config( )['images']['format-fanart-url'].replace( '%FORMAT_ID%', format_id) format_item.set_fanart(fanart) context_menu = [ (context.localize(self._local_map['now.add_to_favs']), 'RunPlugin(%s)' % context.create_uri( [kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)})) ] format_item.set_context_menu(context_menu) result.append(format_item) pass pass return result
def on_root(self, context, re_match): path = context.get_path() result = [] self.get_client(context) # is logged in? if self._is_logged_in: # track json_data = self.get_client(context).get_user('me') me_item = self._do_item(context, json_data, path) result.append(me_item) # stream stream_item = DirectoryItem(context.localize(self._local_map['soundcloud.stream']), context.create_uri(['stream']), image=context.create_resource_path('media', 'stream.png')) stream_item.set_fanart(self.get_fanart(context)) result.append(stream_item) pass # search search_item = DirectoryItem(context.localize(kodion.constants.localize.SEARCH), context.create_uri([kodion.constants.paths.SEARCH, 'list']), image=context.create_resource_path('media', 'search.png')) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) # explore explore_item = DirectoryItem(context.localize(self._local_map['soundcloud.explore']), context.create_uri('explore'), image=context.create_resource_path('media', 'explore.png')) explore_item.set_fanart(self.get_fanart(context)) result.append(explore_item) return result
def _do_formats(self, context, json_formats): result = [] formats = json_formats.get('items', []) # 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 format_data in formats: if show_only_free_videos and not format_data['free']: continue format_title = format_data['title'] params = {} if format_data.get('seoUrl', ''): params['seoUrl'] = format_data['seoUrl'] pass format_item = DirectoryItem(format_title, # /rtl/format/2/ context.create_uri([format_data['station'], 'format', str(format_data['id'])], params)) format_item.set_image(format_data['images']['thumb']) format_item.set_fanart(format_data['images']['fanart']) result.append(format_item) if self.is_logged_in(): if context.get_path() == '/nowtv/favorites/list/': context_menu = [(context.localize(self._local_map['nowtv.remove_from_favs']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'delete'], {'format_id': format_data['id']}))] pass else: context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']), 'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'add'], {'format_id': format_data['id']}))] pass else: context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)}))] pass format_item.set_context_menu(context_menu) pass return result
def _do_formats(self, context, json_formats): result = [] formats = json_formats.get('items', []) for format_data in formats: format_title = format_data['title'] params = {} if format_data.get('seoUrl', ''): params['seoUrl'] = format_data['seoUrl'] pass format_item = DirectoryItem(format_title, context.create_uri([format_data['station'], 'format', str(format_data['id'])], params)) format_item.set_image(format_data['images']['thumb']) format_item.set_fanart(format_data['images']['fanart']) result.append(format_item) context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)}))] format_item.set_context_menu(context_menu) pass return result
def _feed_to_item(self, json_data, context): result = [] data = json_data['data']['data'] for item in data: gallery_item = DirectoryItem( item['title'], context.create_uri(['show', str(item['id'])])) gallery_item.set_fanart(self.get_fanart(context)) image = item.get('thumbnails', []) if len(image) > 0: image = image[0].get('url', '') gallery_item.set_image(image) pass result.append(gallery_item) pass return result
def _get_channel_formats(self, context, re_match): self._set_sort_method_for_content_type( context, kodion.constants.content_type.TV_SHOWS) result = [] # load the formats of the given channel channel_id = re_match.group('channelid') json_data = context.get_function_cache().get( FunctionCache.ONE_DAY, self._get_client(context).get_formats, self._get_client(context).API_V2, channel_id) screen = json_data.get('screen', {}) screen_objects = screen.get('screen_objects', {}) for screen_object in screen_objects: format_id = screen_object['id'].split(':') channel_id = format_id[0] format_id = format_id[1] format_item = DirectoryItem( screen_object['title'], context.create_uri([channel_id, 'library', format_id]), image=screen_object['image_url']) fanart = self.get_fanart(context) data = self._load_format_content(context, channel_id, format_id, return_cached_only=True) if data is not None: fanart = data.get('fanart', self.get_fanart(context)) pass 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) result.append(format_item) pass return self._sort_result_by_name(result)
def _on_library(self, context, re_match): context.set_content_type(kodion.constants.content_type.TV_SHOWS) context.add_sort_method(kodion.constants.sort_method.LABEL) result = [] json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_formats) format_list = json_data.get('result', {}).get('content', {}).get('formatlist') for key in format_list: now_format = format_list[key] title = now_format['formatlong'] format_id = now_format['formatid'] free_episodes = int(now_format.get('free_episodes', '0')) if free_episodes >= 1: format_item = DirectoryItem(title, context.create_uri(['format', format_id])) # set image image = self.get_client(context).get_config()['images']['format-thumbnail-url'].replace('%FORMAT_ID%', format_id) format_item.set_image(image) # set fanart fanart = self.get_client(context).get_config()['images']['format-fanart-url'].replace('%FORMAT_ID%', format_id) format_item.set_fanart(fanart) context_menu = [(context.localize(self._local_map['now.add_to_favs']), 'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'], {'item': kodion.items.to_jsons(format_item)}))] format_item.set_context_menu(context_menu) result.append(format_item) pass pass return result
def get_items(self, provider, context): result = [] if self._flatten and len(self._channel_ids) > 0: # remove duplicates self._channel_ids = list(set(self._channel_ids)) channels_item = DirectoryItem('[B]' + context.localize(provider.LOCAL_MAP['youtube.channels']) + '[/B]', context.create_uri(['special', 'description_links'], {'channel_ids': ','.join(self._channel_ids)}), context.create_resource_path('media', 'playlist.png')) channels_item.set_fanart(provider.get_fanart(context)) result.append(channels_item) pass if self._flatten and len(self._playlist_ids) > 0: # remove duplicates self._playlist_ids = list(set(self._playlist_ids)) playlists_item = DirectoryItem('[B]' + context.localize(provider.LOCAL_MAP['youtube.playlists']) + '[/B]', context.create_uri(['special', 'description_links'], {'playlist_ids': ','.join(self._playlist_ids)}), context.create_resource_path('media', 'playlist.png')) playlists_item.set_fanart(provider.get_fanart(context)) result.append(playlists_item) pass if not self._flatten: result.extend(self.get_channel_items(provider, context)) pass if not self._flatten: result.extend(self.get_playlist_items(provider, context)) pass # add videos result.extend(self.get_video_items(provider, context)) return result
def _get_channel_content(self, context, re_match): channel_id = re_match.group('channelid') result = [] channel_image = context.create_resource_path('media', 'channels', '%s.png' % channel_id) # Highlights item = DirectoryItem(context.localize(kodion.constants.localize.HIGHLIGHTS), context.create_uri([channel_id, 'highlights']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Library item = DirectoryItem(context.localize(kodion.constants.localize.LIBRARY), context.create_uri([channel_id, 'library']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) 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 _on_tracks(self, context, re_match): result = [] user_id = re_match.group('user_id') params = context.get_params() page = int(params.get('page', 1)) json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_user, user_id) user_image = json_data.get('avatar_url', '') user_image = self._get_hires_image(user_image) if page == 1: # playlists playlists_item = DirectoryItem(context.localize(self._local_map['soundcloud.playlists']), context.create_uri(['user/playlists', user_id]), image=user_image) playlists_item.set_fanart(self.get_fanart(context)) result.append(playlists_item) # likes likes_item = DirectoryItem(context.localize(self._local_map['soundcloud.likes']), context.create_uri(['user/favorites', user_id]), image=user_image) likes_item.set_fanart(self.get_fanart(context)) result.append(likes_item) # following following_item = DirectoryItem(context.localize(self._local_map['soundcloud.following']), context.create_uri(['user/following', user_id]), image=user_image) following_item.set_fanart(self.get_fanart(context)) result.append(following_item) # follower follower_item = DirectoryItem(context.localize(self._local_map['soundcloud.follower']), context.create_uri(['user/follower', user_id]), image=user_image) follower_item.set_fanart(self.get_fanart(context)) result.append(follower_item) pass json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 10, self.get_client(context).get_tracks, user_id, page=page) path = context.get_path() result.extend(self._do_collection(context, json_data, path, params)) return result
def on_root(self, context, re_match): result = [] client = self.get_client(context) if self.is_logged_in(): # online favorites fav_item = DirectoryItem('[B]%s[/B]' % context.localize(kodion.constants.localize.FAVORITES), context.create_uri(['nowtv', 'favorites', 'list']), image=context.create_resource_path('media/favorites.png'), fanart=self.get_fanart(context)) result.append(fav_item) # online watch later wl_item = DirectoryItem('[B]%s[/B]' % context.localize(kodion.constants.localize.WATCH_LATER), context.create_uri(['nowtv', 'watch_later', 'list']), image=context.create_resource_path('media/watch_later.png'), fanart=self.get_fanart(context)) result.append(wl_item) pass else: # offline favorites if len(context.get_favorite_list().list()) > 0: fav_item = kodion.items.FavoritesItem(context, fanart=self.get_fanart(context)) fav_item.set_name('[B]%s[/B]' % fav_item.get_name()) result.append(fav_item) pass # offline watch later if len(context.get_watch_later_list().list()) > 0: wl_item = kodion.items.WatchLaterItem(context, fanart=self.get_fanart(context)) wl_item.set_name('[B]%s[/B]' % wl_item.get_name()) result.append(wl_item) pass pass # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = kodion.items.WatchLaterItem(context, fanart=self.get_fanart(context)) result.append(watch_later_item) pass # list channels for channel_id in self._channel_ids: channel_config = Client.CHANNELS[channel_id] channel_id = channel_config['id'] channel_title = channel_config['title'] channel_item = DirectoryItem(channel_title, context.create_uri([channel_id, 'formats'])) channel_item.set_fanart(context.create_resource_path('media', channel_id, 'background.jpg')) channel_item.set_image(context.create_resource_path('media', channel_id, 'logo.png')) result.append(channel_item) pass # search search_item = kodion.items.SearchItem(context, image=context.create_resource_path('media', 'search.png'), fanart=self.get_fanart(context)) result.append(search_item) return result
def on_root(self, context, re_match): result = [] # favorites and latest videos if len(context.get_favorite_list().list()) > 0: fav_item = DirectoryItem( '[B]' + context.localize(kodion.constants.localize.FAVORITES) + '[/B]', context.create_uri([kodion.constants.paths.FAVORITES, 'list']), image=context.create_resource_path('media', 'highlight.png')) fav_item.set_fanart(self.get_fanart(context)) result.append(fav_item) latest_item = DirectoryItem( '[B]' + context.localize(kodion.constants.localize.LATEST_VIDEOS) + '[/B]', context.create_uri(['favs', 'latest']), image=context.create_resource_path('media', 'highlight.png')) latest_item.set_fanart(self.get_fanart(context)) result.append(latest_item) pass # watch later if len(context.get_watch_later_list().list()) > 0: fav_item = DirectoryItem( '[B]' + context.localize(kodion.constants.localize.WATCH_LATER) + '[/B]', context.create_uri( [kodion.constants.paths.WATCH_LATER, 'list']), image=context.create_resource_path('media', 'highlight.png')) fav_item.set_fanart(self.get_fanart(context)) result.append(fav_item) # search search_item = DirectoryItem( '[B]' + context.localize(kodion.constants.localize.SEARCH) + '[/B]', context.create_uri([kodion.constants.paths.SEARCH, 'list']), image=context.create_resource_path('media', 'search.png')) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) # channels for channel in self._channel_id_list: channel_data = self._channel_data.get(channel, {}) channel_image = context.create_resource_path( 'media', 'channels', '%s.png' % channel) channel_item = DirectoryItem(channel_data.get('name', channel), context.create_uri(channel), image=channel_image) channel_item.set_fanart(self.get_fanart(context)) result.append(channel_item) pass return result, {self.RESULT_CACHE_TO_DISC: False}
def on_root(self, context, re_match): result = [] client = self.get_client(context) # featured featured_item = DirectoryItem(context.localize(self._local_map['vimeo.featured']), context.create_uri(['featured']), image=context.create_resource_path('media', 'featured.png')) featured_item.set_fanart(self.get_fanart(context)) result.append(featured_item) if self._is_logged_in: # my feed feed_item = DirectoryItem(context.localize(self._local_map['vimeo.my-feed']), context.create_uri(['user', 'me', 'feed']), image=context.create_resource_path('media', 'new_uploads.png')) feed_item.set_fanart(self.get_fanart(context)) result.append(feed_item) result.extend(self._create_user_items(user_id='me', context=context)) pass # search search_item = kodion.items.SearchItem(context, image=context.create_resource_path('media', 'search.png'), fanart=self.get_fanart(context)) result.append(search_item) # sign in if not self._is_logged_in: sign_in_item = DirectoryItem(context.localize(self._local_map['vimeo.sign-in']), context.create_uri(['sign', 'in']), image=context.create_resource_path('media', 'sign_in.png')) sign_in_item.set_fanart(self.get_fanart(context)) result.append(sign_in_item) pass return result
def _get_format_content(self, context, re_match): path = context.get_path() context.get_ui().set_view_mode('videos') self._set_sort_method_for_content_type(context, kodion.constants.content_type.EPISODES) params = context.get_params() clip_type = params.get('clip_type', 'full') page = int(params.get('page', '1')) result = [] channel_id = re_match.group('channelid') channel_image = context.create_resource_path('media', 'channels', '%s.png' % channel_id) format_id = re_match.group('formatid') data = self._load_format_content(context, channel_id, format_id) fanart = data.get('fanart', self.get_fanart(context)) if page == 1 and clip_type == 'full': # clips if 'Clips' in data: clips_item = DirectoryItem('[B]' + context.localize(self._local_map['7tv.clips']) + '[/B]', context.create_uri(path, {'clip_type': 'short'}), image=channel_image) clips_item.set_fanart(fanart) result.append(clips_item) pass # backstage if 'Backstage' in data: backstage_item = DirectoryItem('[B]' + context.localize(self._local_map['7tv.backstage']) + '[/B]', context.create_uri(path, {'clip_type': 'webexclusive'}), image=channel_image) backstage_item.set_fanart(fanart) result.append(backstage_item) pass pass # test for a possible next page (cached) next_page_test = context.get_function_cache().get(FunctionCache.ONE_HOUR, self._get_client(context).get_format_videos, self._get_client(context).API_V2, channel_id, format_id, clip_type, page=page + 1) next_page_test = next_page_test.get('objects', []) next_page = len(next_page_test) > 0 if page == 1: # the first page will work like this clip_type_map = {'full': 'Ganze Folgen', 'short': 'Clips', 'webexclusive': 'Backstage'} episodes = data.get(clip_type_map[clip_type], []) video_list = [] for episode in episodes: video_item = self._screen_object_to_item(context, episode) video_list.append(video_item) pass video_list = self._sort_result_by_aired(video_list, reverse=True) result.extend(video_list) if next_page: next_page_item = kodion.items.NextPageItem(context, page, fanart=fanart) result.append(next_page_item) pass else: video_list = [] episodes = context.get_function_cache().get(FunctionCache.ONE_HOUR, self._get_client(context).get_format_videos, self._get_client(context).API_V2, channel_id, format_id, clip_type, page=page) episodes = episodes.get('objects', []) for episode in episodes: video_item = self._screen_object_to_item(context, episode) video_list.append(video_item) pass video_list = self._sort_result_by_aired(video_list, reverse=True) result.extend(video_list) if next_page: next_page_item = kodion.items.NextPageItem(context, page, fanart=fanart) result.append(next_page_item) pass pass return result
def on_root(self, context, re_match): result = [] # favorites if len(context.get_favorite_list().list()) > 0: fav_item = kodion.items.FavoritesItem( context, fanart=self.get_fanart(context)) result.append(fav_item) pass # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = kodion.items.WatchLaterItem( context, fanart=self.get_fanart(context)) result.append(watch_later_item) pass client = self.get_client(context) # shows (A-Z) if 'library' in client.get_config()['supports']: library_item = DirectoryItem( context.localize(self._local_map['now.library']), context.create_uri(['library']), image=context.create_resource_path('media', 'library.png')) library_item.set_fanart(self.get_fanart(context)) result.append(library_item) pass # newest if 'new' in client.get_config()['supports']: newest_item = DirectoryItem( context.localize(self._local_map['now.newest']), context.create_uri(['newest']), image=context.create_resource_path('media', 'newest.png')) newest_item.set_fanart(self.get_fanart(context)) result.append(newest_item) pass # tips if 'tips' in client.get_config()['supports']: tips_item = DirectoryItem( context.localize(self._local_map['now.tips']), context.create_uri(['tips']), image=context.create_resource_path('media', 'tips.png')) tips_item.set_fanart(self.get_fanart(context)) result.append(tips_item) pass # top 10 if 'top10' in client.get_config()['supports']: top10_item = DirectoryItem( context.localize(self._local_map['now.top10']), context.create_uri(['top10']), image=context.create_resource_path('media', 'top10.png')) top10_item.set_fanart(self.get_fanart(context)) result.append(top10_item) pass # search if 'search' in client.get_config()['supports']: search_item = kodion.items.SearchItem( context, fanart=self.get_fanart(context)) result.append(search_item) pass return result
def _on_explore(self, context, re_match): result = [] # trending music music_trending_item = DirectoryItem(context.localize(self._local_map['soundcloud.music.trending']), context.create_uri(['explore', 'trending', 'music']), image=context.create_resource_path('media', 'music.png')) music_trending_item.set_fanart(self.get_fanart(context)) result.append(music_trending_item) # trending audio audio_trending_item = DirectoryItem(context.localize(self._local_map['soundcloud.audio.trending']), context.create_uri(['explore', 'trending', 'audio']), image=context.create_resource_path('media', 'audio.png')) audio_trending_item.set_fanart(self.get_fanart(context)) result.append(audio_trending_item) # genre music music_genre_item = DirectoryItem(context.localize(self._local_map['soundcloud.music.genre']), context.create_uri(['explore', 'genre', 'music']), image=context.create_resource_path('media', 'music.png')) music_genre_item.set_fanart(self.get_fanart(context)) result.append(music_genre_item) # genre audio audio_genre_item = DirectoryItem(context.localize(self._local_map['soundcloud.audio.genre']), context.create_uri(['explore', 'genre', 'audio']), image=context.create_resource_path('media', 'audio.png')) audio_genre_item.set_fanart(self.get_fanart(context)) result.append(audio_genre_item) return result
def on_root(self, context, re_match): result = [] # favorites and latest videos if len(context.get_favorite_list().list()) > 0: fav_item = DirectoryItem('[B]' + context.localize(kodion.constants.localize.FAVORITES) + '[/B]', context.create_uri([kodion.constants.paths.FAVORITES, 'list']), image=context.create_resource_path('media', 'highlight.png')) fav_item.set_fanart(self.get_fanart(context)) result.append(fav_item) latest_item = DirectoryItem('[B]' + context.localize(kodion.constants.localize.LATEST_VIDEOS) + '[/B]', context.create_uri(['favs', 'latest']), image=context.create_resource_path('media', 'highlight.png')) latest_item.set_fanart(self.get_fanart(context)) result.append(latest_item) pass # watch later if len(context.get_watch_later_list().list()) > 0: fav_item = DirectoryItem('[B]' + context.localize(kodion.constants.localize.WATCH_LATER) + '[/B]', context.create_uri([kodion.constants.paths.WATCH_LATER, 'list']), image=context.create_resource_path('media', 'highlight.png')) fav_item.set_fanart(self.get_fanart(context)) result.append(fav_item) # search search_item = DirectoryItem('[B]' + context.localize(kodion.constants.localize.SEARCH) + '[/B]', context.create_uri([kodion.constants.paths.SEARCH, 'list']), image=context.create_resource_path('media', 'search.png')) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) # channels for channel in self._channel_id_list: channel_data = self._channel_data.get(channel, {}) channel_image = context.create_resource_path('media', 'channels', '%s.png' % channel) channel_item = DirectoryItem(channel_data.get('name', channel), context.create_uri(channel), image=channel_image) channel_item.set_fanart(self.get_fanart(context)) result.append(channel_item) pass return result, {self.RESULT_CACHE_TO_DISC: False}
def _do_item(self, context, json_item, path): def _get_track_year(collection_item_json): # this would be the default info, but is mostly not set :( year = collection_item_json.get('release_year', '') if year: return year # we use a fallback. # created_at=2013/03/24 00:32:01 +0000 re_match = re.match('(?P<year>\d{4})(.*)', collection_item_json.get('created_at', '')) if re_match: year = re_match.group('year') if year: return year pass return '' def _get_image(json_data): image_url = json_data.get('artwork_url', '') # test avatar image if not image_url: image_url = json_data.get('avatar_url', '') # test tracks (used for playlists) if not image_url: tracks = json_data.get('tracks', []) if len(tracks) > 0: return _get_image(tracks[0]) # fall back is the user avatar (at least) image_url = json_data.get('user', {}).get('avatar_url', '') pass # try to convert the image to 500x500 pixel return self._get_hires_image(image_url) kind = json_item.get('kind', '') if kind == 'playlist': playlist_item = DirectoryItem(json_item['title'], context.create_uri(['playlist', unicode(json_item['id'])]), image=_get_image(json_item)) playlist_item.set_fanart(self.get_fanart(context)) if path == '/user/favorites/me/': context_menu = [(context.localize(self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])], {'like': '0'}))] else: context_menu = [(context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])], {'like': '1'}))] playlist_item.set_context_menu(context_menu) return playlist_item elif kind == 'user': username = json_item['username'] user_id = unicode(json_item['id']) if path == '/': user_id = 'me' username = '******' + username + '[/B]' pass user_item = DirectoryItem(username, context.create_uri(['user/tracks', user_id]), image=_get_image(json_item)) user_item.set_fanart(self.get_fanart(context)) if path == '/user/following/me/': context_menu = [(context.localize(self._local_map['soundcloud.unfollow']), 'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])], {'follow': '0'}))] pass else: context_menu = [(context.localize(self._local_map['soundcloud.follow']), 'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])], {'follow': '1'}))] pass user_item.set_context_menu(context_menu) return user_item elif kind == 'track': title = json_item['title'] track_item = AudioItem(title, context.create_uri('play', {'id': unicode(json_item['id'])}), image=_get_image(json_item)) track_item.set_fanart(self.get_fanart(context)) # title track_item.set_title(title) # genre track_item.set_genre(json_item.get('genre', '')) # duration track_item.set_duration_from_milli_seconds(json_item.get('duration', 0)) # artist track_item.set_artist_name(json_item.get('user', {}).get('username', '')) # year track_item.set_year(_get_track_year(json_item)) if path == '/user/favorites/me/': context_menu = [(context.localize(self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])], {'like': '0'}))] pass else: context_menu = [(context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])], {'like': '1'}))] track_item.set_context_menu(context_menu) return track_item elif kind == 'like': # A like has 'playlist' or 'track' so we find one of them and call this routine again, because the # data is same. test_playlist = json_item.get('playlist', None) if test_playlist is not None: return self._do_item(context, test_playlist, path) test_track = json_item.get('track', None) if test_track is not None: return self._do_item(context, test_track, path) pass elif kind == 'group': # at the moment we don't support groups """ group_item = DirectoryItem('Group-Dummy', '') return group_item """ return None raise kodion.KodimonException("Unknown kind of item '%s'" % kind)
def on_root(self, context, re_match): result = [] # favorites if len(context.get_favorite_list().list()) > 0: fav_item = kodion.items.FavoritesItem(context, fanart=self.get_fanart(context)) result.append(fav_item) pass # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = kodion.items.WatchLaterItem(context, fanart=self.get_fanart(context)) result.append(watch_later_item) pass client = self.get_client(context) # shows (A-Z) if 'library' in client.get_config()['supports']: library_item = DirectoryItem(context.localize(self._local_map['now.library']), context.create_uri(['library']), image=context.create_resource_path('media', 'library.png')) library_item.set_fanart(self.get_fanart(context)) result.append(library_item) pass # newest if 'new' in client.get_config()['supports']: newest_item = DirectoryItem(context.localize(self._local_map['now.newest']), context.create_uri(['newest']), image=context.create_resource_path('media', 'newest.png')) newest_item.set_fanart(self.get_fanart(context)) result.append(newest_item) pass # tips if 'tips' in client.get_config()['supports']: tips_item = DirectoryItem(context.localize(self._local_map['now.tips']), context.create_uri(['tips']), image=context.create_resource_path('media', 'tips.png')) tips_item.set_fanart(self.get_fanart(context)) result.append(tips_item) pass # top 10 if 'top10' in client.get_config()['supports']: top10_item = DirectoryItem(context.localize(self._local_map['now.top10']), context.create_uri(['top10']), image=context.create_resource_path('media', 'top10.png')) top10_item.set_fanart(self.get_fanart(context)) result.append(top10_item) pass # search if 'search' in client.get_config()['supports']: search_item = kodion.items.SearchItem(context, fanart=self.get_fanart(context)) result.append(search_item) pass return result
def on_root(self, context, re_match): result = [] # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = DirectoryItem( '[B]' + context.localize(constants.localize.WATCH_LATER) + '[/B]', context.create_uri([constants.paths.WATCH_LATER, 'list']), image=context.create_resource_path('media', 'watch_later.png')) watch_later_item.set_fanart(self.get_fanart(context)) result.append(watch_later_item) pass # search search_item = DirectoryItem( '[B]' + context.localize(constants.localize.SEARCH) + '[/B]', context.create_uri([constants.paths.SEARCH, 'list']), image=context.create_resource_path('media', 'search.png')) search_item.set_fanart(self.get_fanart(context)) result.append(search_item) # "Neu bei Netzkino/DZANGO" config = self._client.get_config() category_id = str(config['new']['id']) category_item = DirectoryItem( u'[B]%s[/B]' % config['new']['title'], context.create_uri(['category', category_id])) category_image_url = config['category_image_url'] if category_image_url: category_item.set_image(category_image_url % category_id) pass category_item.set_fanart(self.get_fanart(context)) result.append(category_item) # categories categories = context.get_function_cache().get( FunctionCache.ONE_DAY, self._client.get_categories) for category in categories: category_id = str(category['id']) category_item = DirectoryItem( category['title'], context.create_uri(['category', category_id])) category_image_url = config['category_image_url'] if category_image_url: category_item.set_image(category_image_url % category_id) pass category_item.set_fanart(self.get_fanart(context)) result.append(category_item) pass return result, {self.RESULT_CACHE_TO_DISC: False}
def _do_item(self, context, json_item, path, process_playlist=False): def _get_track_year(collection_item_json): # this would be the default info, but is mostly not set :( year = collection_item_json.get('release_year', '') if year: return year # we use a fallback. # created_at=2013/03/24 00:32:01 +0000 re_match = re.match('(?P<year>\d{4})(.*)', collection_item_json.get('created_at', '')) if re_match: year = re_match.group('year') if year: return year pass return '' def _get_image(json_data): image_url = json_data.get('artwork_url', '') # test avatar image if not image_url: image_url = json_data.get('avatar_url', '') # test tracks (used for playlists) if not image_url: tracks = json_data.get('tracks', []) if len(tracks) > 0: return _get_image(tracks[0]) # fall back is the user avatar (at least) image_url = json_data.get('user', {}).get('avatar_url', '') pass return self._get_hires_image(image_url) kind = json_item.get('kind', '') if kind == 'playlist': if process_playlist: result = [] tracks = json_item['tracks'] track_number = 1 for track in tracks: path = context.get_path() track_item = self._do_item(context, track, path) # set the name of the playlist for the albumname track_item.set_album_name(json_item['title']) # based on the position in the playlist we add a track number track_item.set_track_number(track_number) result.append(track_item) track_number += 1 pass return result else: playlist_item = DirectoryItem(json_item['title'], context.create_uri(['playlist', unicode(json_item['id'])]), image=_get_image(json_item)) playlist_item.set_fanart(self.get_fanart(context)) if path == '/user/favorites/me/': context_menu = [(context.localize(self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])], {'like': '0'}))] else: context_menu = [(context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])], {'like': '1'}))] playlist_item.set_context_menu(context_menu) return playlist_item pass elif kind == 'user': username = json_item['username'] user_id = unicode(json_item['id']) if path == '/': user_id = 'me' username = '******' + username + '[/B]' pass user_item = DirectoryItem(username, context.create_uri(['user/tracks', user_id]), image=_get_image(json_item)) user_item.set_fanart(self.get_fanart(context)) if path == '/user/following/me/': context_menu = [(context.localize(self._local_map['soundcloud.unfollow']), 'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])], {'follow': '0'}))] pass else: context_menu = [(context.localize(self._local_map['soundcloud.follow']), 'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])], {'follow': '1'}))] pass user_item.set_context_menu(context_menu) return user_item elif kind == 'track': title = json_item['title'] track_item = AudioItem(title, context.create_uri('play', {'audio_id': unicode(json_item['id'])}), image=_get_image(json_item)) track_item.set_fanart(self.get_fanart(context)) # title track_item.set_title(title) # genre track_item.set_genre(json_item.get('genre', '')) # duration track_item.set_duration_from_milli_seconds(json_item.get('duration', 0)) # artist track_item.set_artist_name(json_item.get('user', {}).get('username', '')) # year track_item.set_year(_get_track_year(json_item)) context_menu = [] # recommended tracks context_menu.append((context.localize(self._local_map['soundcloud.recommended']), 'Container.Update(%s)' % context.create_uri( ['explore', 'recommended', 'tracks', unicode(json_item['id'])]))) # like/unlike a track if path == '/user/favorites/me/': context_menu.append((context.localize(self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])], {'like': '0'}))) pass else: context_menu.append((context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])], {'like': '1'}))) pass # go to user username = json_item['user']['username'] user_id = str(json_item['user']['id']) if path != '/user/tracks/%s/' % user_id: context_menu.append(( context.localize(self._local_map['soundcloud.user.go_to']) % ('[B]%s[/B]' % username), 'Container.Update(%s)' % context.create_uri(['user', 'tracks', user_id]))) pass track_item.set_context_menu(context_menu) return track_item elif kind == 'like': # A like has 'playlist' or 'track' so we find one of them and call this routine again, because the # data is same. test_playlist = json_item.get('playlist', None) if test_playlist is not None: return self._do_item(context, test_playlist, path) test_track = json_item.get('track', None) if test_track is not None: return self._do_item(context, test_track, path) pass elif kind == 'group': # at the moment we don't support groups """ group_item = DirectoryItem('Group-Dummy', '') return group_item """ return None raise kodion.KodionException("Unknown kind of item '%s'" % kind)
def _get_channel_highlights(self, context, re_match): result = [] channel_id = re_match.group('channelid') channel_image = context.create_resource_path( 'media', 'channels' '%s.png' % channel_id) category = re_match.group('category') if category is None: # Popular Shows item = DirectoryItem( context.localize(self._local_map['7tv.popular_shows']), context.create_uri( [channel_id, 'highlights', 'Beliebte Sendungen']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Current Entire Episodes item = DirectoryItem(context.localize( self._local_map['7tv.current_entire_episodes']), context.create_uri([ channel_id, 'highlights', 'Aktuelle ganze Folgen' ]), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) # Newest Clips item = DirectoryItem( context.localize(self._local_map['7tv.newest_clips']), context.create_uri([channel_id, 'highlights', 'Neueste Clips']), image=channel_image) item.set_fanart(self.get_fanart(context)) result.append(item) else: json_data = context.get_function_cache().get( FunctionCache.ONE_MINUTE * 5, self._get_client(context).get_homepage, self._get_client(context).API_V2, channel_id) screen = json_data.get('screen', {}) screen_objects = screen.get('screen_objects', []) for screen_object in screen_objects: if screen_object.get('type', '') == 'sushi_bar': if screen_object.get('title', '') == category: sub_screen_objects = screen_object.get( 'screen_objects', []) for sub_screen_object in sub_screen_objects: result.append( self._screen_object_to_item( context, sub_screen_object, show_format_title=( category == 'Neueste Clips'))) pass break pass pass if category == 'Beliebte Sendungen': self._set_sort_method_for_content_type( context, kodion.constants.content_type.TV_SHOWS) result = self._sort_result_by_name(result) else: self._set_sort_method_for_content_type( context, kodion.constants.content_type.EPISODES) result = self._sort_result_by_aired(result) pass return result
def on_root(self, context, re_match): result = [] client = self.get_client(context) if self.is_logged_in(): # online favorites fav_item = DirectoryItem( '[B]%s[/B]' % context.localize(kodion.constants.localize.FAVORITES), context.create_uri(['nowtv', 'favorites', 'list']), image=context.create_resource_path('media/favorites.png'), fanart=self.get_fanart(context)) result.append(fav_item) # online watch later wl_item = DirectoryItem( '[B]%s[/B]' % context.localize(kodion.constants.localize.WATCH_LATER), context.create_uri(['nowtv', 'watch_later', 'list']), image=context.create_resource_path('media/watch_later.png'), fanart=self.get_fanart(context)) result.append(wl_item) pass else: # offline favorites if len(context.get_favorite_list().list()) > 0: fav_item = kodion.items.FavoritesItem( context, fanart=self.get_fanart(context)) fav_item.set_name('[B]%s[/B]' % fav_item.get_name()) result.append(fav_item) pass # offline watch later if len(context.get_watch_later_list().list()) > 0: wl_item = kodion.items.WatchLaterItem( context, fanart=self.get_fanart(context)) wl_item.set_name('[B]%s[/B]' % wl_item.get_name()) result.append(wl_item) pass pass # watch later if len(context.get_watch_later_list().list()) > 0: watch_later_item = kodion.items.WatchLaterItem( context, fanart=self.get_fanart(context)) result.append(watch_later_item) pass # list channels for channel_id in self._channel_ids: channel_config = Client.CHANNELS[channel_id] channel_id = channel_config['id'] channel_title = channel_config['title'] channel_item = DirectoryItem( channel_title, context.create_uri([channel_id, 'formats'])) channel_item.set_fanart( context.create_resource_path('media', channel_id, 'background.jpg')) channel_item.set_image( context.create_resource_path('media', channel_id, 'logo.png')) result.append(channel_item) pass # search search_item = kodion.items.SearchItem( context, image=context.create_resource_path('media', 'search.png'), fanart=self.get_fanart(context)) result.append(search_item) return result
def _get_format_content(self, context, re_match): path = context.get_path() context.get_ui().set_view_mode('videos') self._set_sort_method_for_content_type( context, kodion.constants.content_type.EPISODES) params = context.get_params() clip_type = params.get('clip_type', 'full') page = int(params.get('page', '1')) result = [] channel_id = re_match.group('channelid') channel_image = context.create_resource_path('media', 'channels', '%s.png' % channel_id) format_id = re_match.group('formatid') data = self._load_format_content(context, channel_id, format_id) fanart = data.get('fanart', self.get_fanart(context)) if page == 1 and clip_type == 'full': # clips if 'Clips' in data: clips_item = DirectoryItem( '[B]' + context.localize(self._local_map['7tv.clips']) + '[/B]', context.create_uri(path, {'clip_type': 'short'}), image=channel_image) clips_item.set_fanart(fanart) result.append(clips_item) pass # backstage if 'Backstage' in data: backstage_item = DirectoryItem( '[B]' + context.localize(self._local_map['7tv.backstage']) + '[/B]', context.create_uri(path, {'clip_type': 'webexclusive'}), image=channel_image) backstage_item.set_fanart(fanart) result.append(backstage_item) pass pass # test for a possible next page (cached) next_page_test = context.get_function_cache().get( FunctionCache.ONE_HOUR, self._get_client(context).get_format_videos, self._get_client(context).API_V2, channel_id, format_id, clip_type, page=page + 1) next_page_test = next_page_test.get('objects', []) next_page = len(next_page_test) > 0 if page == 1: # the first page will work like this clip_type_map = { 'full': 'Ganze Folgen', 'short': 'Clips', 'webexclusive': 'Backstage' } episodes = data.get(clip_type_map[clip_type], []) video_list = [] for episode in episodes: video_item = self._screen_object_to_item(context, episode) video_list.append(video_item) pass video_list = self._sort_result_by_aired(video_list, reverse=True) result.extend(video_list) if next_page: next_page_item = kodion.items.NextPageItem(context, page, fanart=fanart) result.append(next_page_item) pass else: video_list = [] episodes = context.get_function_cache().get( FunctionCache.ONE_HOUR, self._get_client(context).get_format_videos, self._get_client(context).API_V2, channel_id, format_id, clip_type, page=page) episodes = episodes.get('objects', []) for episode in episodes: video_item = self._screen_object_to_item(context, episode) video_list.append(video_item) pass video_list = self._sort_result_by_aired(video_list, reverse=True) result.extend(video_list) if next_page: next_page_item = kodion.items.NextPageItem(context, page, fanart=fanart) result.append(next_page_item) pass pass return result
def _create_user_items(self, user_id, context): result = [] # Videos videos_item = DirectoryItem(context.localize(self._local_map['vimeo.videos']), context.create_uri(['user', user_id, 'videos']), image=context.create_resource_path('media', 'videos.png')) videos_item.set_fanart(self.get_fanart(context)) result.append(videos_item) if user_id == 'me' and self.is_logged_in(): # Watch Later watch_later_item = DirectoryItem(context.localize(self._local_map['vimeo.watch-later']), context.create_uri(['user', 'me', 'watch-later']), image=context.create_resource_path('media', 'watch_later.png')) watch_later_item.set_fanart(self.get_fanart(context)) result.append(watch_later_item) pass # Likes likes_item = DirectoryItem(context.localize(self._local_map['vimeo.likes']), context.create_uri(['user', user_id, 'likes']), image=context.create_resource_path('media', 'likes.png')) likes_item.set_fanart(self.get_fanart(context)) result.append(likes_item) # Following following_item = DirectoryItem(context.localize(self._local_map['vimeo.following']), context.create_uri(['user', user_id, 'following']), image=context.create_resource_path('media', 'channel.png')) following_item.set_fanart(self.get_fanart(context)) result.append(following_item) # Groups groups_item = DirectoryItem(context.localize(self._local_map['vimeo.groups']), context.create_uri(['user', user_id, 'groups']), image=context.create_resource_path('media', 'groups.png')) groups_item.set_fanart(self.get_fanart(context)) result.append(groups_item) # Channels channels_item = DirectoryItem(context.localize(self._local_map['vimeo.channels']), context.create_uri(['user', user_id, 'channels']), image=context.create_resource_path('media', 'channels.png')) channels_item.set_fanart(self.get_fanart(context)) result.append(channels_item) # Albums albums_item = DirectoryItem(context.localize(self._local_map['vimeo.albums']), context.create_uri(['user', user_id, 'albums']), image=context.create_resource_path('media', 'albums.png')) albums_item.set_fanart(self.get_fanart(context)) result.append(albums_item) return result
def _do_item(self, context, json_item, path, process_playlist=False): def _get_track_year(collection_item_json): # this would be the default info, but is mostly not set :( year = collection_item_json.get('release_year', '') if year: return year # we use a fallback. # created_at=2013/03/24 00:32:01 +0000 re_match = re.match('(?P<year>\d{4})(.*)', collection_item_json.get('created_at', '')) if re_match: year = re_match.group('year') if year: return year pass return '' def _get_image(json_data): image_url = json_data.get('artwork_url', '') # test avatar image if not image_url: image_url = json_data.get('avatar_url', '') # test tracks (used for playlists) if not image_url: tracks = json_data.get('tracks', []) if len(tracks) > 0: return _get_image(tracks[0]) # fall back is the user avatar (at least) image_url = json_data.get('user', {}).get('avatar_url', '') pass return self._get_hires_image(image_url) kind = json_item.get('kind', '') if kind == 'playlist': if process_playlist: result = [] tracks = json_item['tracks'] track_number = 1 for track in tracks: path = context.get_path() track_item = self._do_item(context, track, path) # set the name of the playlist for the albumname track_item.set_album_name(json_item['title']) # based on the position in the playlist we add a track number track_item.set_track_number(track_number) result.append(track_item) track_number += 1 pass return result else: playlist_item = DirectoryItem( json_item['title'], context.create_uri(['playlist', unicode(json_item['id'])]), image=_get_image(json_item)) playlist_item.set_fanart(self.get_fanart(context)) if path == '/user/favorites/me/': context_menu = [ (context.localize( self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri( ['like/playlist', unicode(json_item['id'])], {'like': '0'})) ] else: context_menu = [ (context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri( ['like/playlist', unicode(json_item['id'])], {'like': '1'})) ] playlist_item.set_context_menu(context_menu) return playlist_item pass elif kind == 'user': username = json_item['username'] user_id = unicode(json_item['id']) if path == '/': user_id = 'me' username = '******' + username + '[/B]' pass user_item = DirectoryItem(username, context.create_uri( ['user/tracks', user_id]), image=_get_image(json_item)) user_item.set_fanart(self.get_fanart(context)) if path == '/user/following/me/': context_menu = [( context.localize(self._local_map['soundcloud.unfollow']), 'RunPlugin(%s)' % context.create_uri( ['follow', unicode(json_item['id'])], {'follow': '0'})) ] pass else: context_menu = [( context.localize(self._local_map['soundcloud.follow']), 'RunPlugin(%s)' % context.create_uri( ['follow', unicode(json_item['id'])], {'follow': '1'})) ] pass user_item.set_context_menu(context_menu) return user_item elif kind == 'track': title = json_item['title'] track_item = AudioItem( title, context.create_uri('play', {'audio_id': unicode(json_item['id'])}), image=_get_image(json_item)) track_item.set_fanart(self.get_fanart(context)) # title track_item.set_title(title) # genre track_item.set_genre(json_item.get('genre', '')) # duration track_item.set_duration_from_milli_seconds( json_item.get('duration', 0)) # artist track_item.set_artist_name( json_item.get('user', {}).get('username', '')) # year track_item.set_year(_get_track_year(json_item)) context_menu = [] # recommended tracks context_menu.append( (context.localize(self._local_map['soundcloud.recommended']), 'Container.Update(%s)' % context.create_uri([ 'explore', 'recommended', 'tracks', unicode(json_item['id']) ]))) # like/unlike a track if path == '/user/favorites/me/': context_menu.append( (context.localize(self._local_map['soundcloud.unlike']), 'RunPlugin(%s)' % context.create_uri( ['like/track', unicode(json_item['id'])], {'like': '0'}))) pass else: context_menu.append( (context.localize(self._local_map['soundcloud.like']), 'RunPlugin(%s)' % context.create_uri( ['like/track', unicode(json_item['id'])], {'like': '1'}))) pass # go to user username = json_item['user']['username'] user_id = str(json_item['user']['id']) if path != '/user/tracks/%s/' % user_id: context_menu.append( (context.localize(self._local_map['soundcloud.user.go_to']) % ('[B]%s[/B]' % username), 'Container.Update(%s)' % context.create_uri(['user', 'tracks', user_id]))) pass track_item.set_context_menu(context_menu) return track_item elif kind == 'like': # A like has 'playlist' or 'track' so we find one of them and call this routine again, because the # data is same. test_playlist = json_item.get('playlist', None) if test_playlist is not None: return self._do_item(context, test_playlist, path) test_track = json_item.get('track', None) if test_track is not None: return self._do_item(context, test_track, path) pass elif kind == 'group': # at the moment we don't support groups """ group_item = DirectoryItem('Group-Dummy', '') return group_item """ return None raise kodion.KodionException("Unknown kind of item '%s'" % kind)
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 on_channel_format(self, context, re_match): channel_id = re_match.group('channel_id') format_id = re_match.group('format_id') channel_config = Client.CHANNELS[channel_id] client = self.get_client(context) # try to process tabs seo_url = context.get_param('seoUrl', '') if not seo_url: raise KodionException('seoUrl missing') format_tabs = client.get_format_tabs(channel_config, seo_url) # only on season tab -> show the content directly if len(format_tabs) == 1 and format_tabs[0]['type'] == 'tab': format_tab = format_tabs[0] return self._on_channel_format_list(context, channel_config, format_tab['id']) # show the tabs/sections tabs = [] for format_tab in format_tabs: if format_tab['type'] == 'tab': tab_item = DirectoryItem( format_tab['title'], # /[CHANNEL_ID]/format/[FORMAT_ID]/list/[FORMAT_LIST_ID]/ context.create_uri([ channel_id, 'format', format_id, 'list', str(format_tab['id']) ])) tab_item.set_image(format_tab['images']['thumb']) tab_item.set_fanart(format_tab['images']['fanart']) tabs.append(tab_item) pass elif format_tab['type'] == 'date-span': tab_title = format_tab['title'] image = format_tab['images']['thumb'] fanart = format_tab['images']['fanart'] tab_item = DirectoryItem( tab_title, # /[CHANNEL_ID]/format/[FORMAT_ID]/year/[YEAR]/ context.create_uri( [channel_id, 'format', format_id, 'year', tab_title], { 'start': format_tab['start'], 'end': format_tab['end'], 'image': image, 'fanart': fanart })) tab_item.set_image(image) tab_item.set_fanart(fanart) tabs.append(tab_item) pass else: raise KodionException('Unknown type "%s" for tab' % format_tab['type']) pass return tabs