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 _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 _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 _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_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_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 _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 _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 _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_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 _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 _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)