Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 27.47 KB | None | 0 0
  1. __author__ = 'bromix'
  2.  
  3. import re
  4.  
  5. from resources.lib.kodion.utils import FunctionCache
  6. from resources.lib.kodion.items import DirectoryItem, AudioItem
  7. from resources.lib import kodion
  8. from resources.lib.soundcloud.client import ClientException
  9. from .client import Client
  10.  
  11.  
  12. class Provider(kodion.AbstractProvider):
  13.     SETTINGS_USER_ID = 'soundcloud.user.id'
  14.  
  15.     def __init__(self):
  16.         kodion.AbstractProvider.__init__(self)
  17.  
  18.         self._is_logged_in = False
  19.         self._client = None
  20.         self._local_map = {'soundcloud.explore': 30500,
  21.                            'soundcloud.music.trending': 30501,
  22.                            'soundcloud.audio.trending': 30502,
  23.                            'soundcloud.music.genre': 30503,
  24.                            'soundcloud.audio.genre': 30504,
  25.                            'soundcloud.stream': 30505,
  26.                            'soundcloud.playlists': 30506,
  27.                            'soundcloud.following': 30507,
  28.                            'soundcloud.follow': 30508,
  29.                            'soundcloud.follower': 30509,
  30.                            'soundcloud.likes': 30510,
  31.                            'soundcloud.like': 30511,
  32.                            'soundcloud.tracks': 30512,
  33.                            'soundcloud.unfollow': 30513,
  34.                            'soundcloud.unlike': 30514,
  35.                            'soundcloud.people': 30515, }
  36.         pass
  37.  
  38.     def get_client(self, context):
  39.         access_manager = context.get_access_manager()
  40.         access_token = access_manager.get_access_token()
  41.         if access_manager.is_new_login_credential() or not access_token:
  42.             access_manager.update_access_token('')  # in case of an old access_token
  43.             self._client = None
  44.             pass
  45.  
  46.         if not self._client:
  47.             if access_manager.has_login_credentials():
  48.                 username, password = access_manager.get_login_credentials()
  49.                 access_token = access_manager.get_access_token()
  50.  
  51.                 # create a new access_token
  52.                 if not access_token:
  53.                     self._client = Client(username=username, password=password, access_token='')
  54.                     access_token = self._client.update_access_token()
  55.                     access_manager.update_access_token(access_token)
  56.                     pass
  57.  
  58.                 self._is_logged_in = access_token != ''
  59.                 self._client = Client(username=username, password=password, access_token=access_token)
  60.             else:
  61.                 self._client = Client()
  62.                 pass
  63.             pass
  64.  
  65.         return self._client
  66.  
  67.     def handle_exception(self, context, exception_to_handle):
  68.         if isinstance(exception_to_handle, ClientException):
  69.             if exception_to_handle.get_status_code() == 401:
  70.                 context.get_access_manager().update_access_token('')
  71.                 context.get_ui().show_notification('Login Failed')
  72.                 context.get_ui().open_settings()
  73.                 return False
  74.             pass
  75.  
  76.         return True
  77.  
  78.     def get_alternative_fanart(self, context):
  79.         return self.get_fanart(context)
  80.  
  81.     def get_fanart(self, context):
  82.         """
  83.            This will return a darker and (with blur) fanart
  84.            :return:
  85.            """
  86.         return context.create_resource_path('media', 'fanart.jpg')
  87.  
  88.     @kodion.RegisterProviderPath('^/play/$')
  89.     def _play(self, context, re_match):
  90.         params = context.get_params()
  91.         track_id = params.get('id', '')
  92.         if not track_id:
  93.             raise kodion.KodimonException('Missing if for audio file')
  94.  
  95.         json_data = self.get_client(context).get_track_url(track_id)
  96.         location = json_data.get('location')
  97.         if not location:
  98.             raise kodion.KodimonException("Could not get url for trask '%s'" % track_id)
  99.  
  100.         item = AudioItem(track_id, location)
  101.         return item
  102.  
  103.     def _do_mobile_collection(self, context, json_data, path, params):
  104.         result = []
  105.  
  106.         # this result is not quite the collection we expected, but with some conversion we can use our
  107.         # main routine for that.
  108.         collection = json_data.get('collection', [])
  109.         for collection_item in collection:
  110.             # move user
  111.             user = collection_item.get('_embedded', {}).get('user', {})
  112.             collection_item['user'] = user
  113.  
  114.             # create track id of urn
  115.             track_id = collection_item['urn'].split(':')[2]
  116.             collection_item['id'] = track_id
  117.  
  118.             # is always a track
  119.             collection_item['kind'] = 'track'
  120.  
  121.             track_item = self._do_item(context, collection_item, path)
  122.             if track_item is not None:
  123.                 result.append(track_item)
  124.             pass
  125.  
  126.         # test for next page
  127.         page = int(params.get('page', 1))
  128.         next_href = json_data.get('_links', {}).get('next', {}).get('href', '')
  129.         if next_href and len(result) > 0:
  130.             next_page_item = kodion.items.create_next_page_item(context, page)
  131.             next_page_item.set_fanart(self.get_fanart(context))
  132.             result.append(next_page_item)
  133.             pass
  134.  
  135.         return result
  136.  
  137.     @kodion.RegisterProviderPath('^\/explore\/trending\/((?P<category>\w+)/)?$')
  138.     def _on_explore_trending(self, context, re_match):
  139.         result = []
  140.         category = re_match.group('category')
  141.         params = context.get_params()
  142.         page = int(params.get('page', 1))
  143.         json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_trending,
  144.                                                      category=category, page=page)
  145.         path = context.get_path()
  146.         result = self._do_mobile_collection(context, json_data, path, params)
  147.  
  148.         return result
  149.  
  150.     @kodion.RegisterProviderPath('^\/explore\/genre\/((?P<category>\w+)\/)((?P<genre>.+)\/)?$')
  151.     def _on_explore_genre(self, context, re_match):
  152.         result = []
  153.  
  154.         genre = re_match.group('genre')
  155.         if not genre:
  156.             json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_categories)
  157.             category = re_match.group('category')
  158.             genres = json_data.get(category, [])
  159.             for genre in genres:
  160.                 title = genre['title']
  161.                 genre_item = DirectoryItem(title,
  162.                                            context.create_uri(['explore', 'genre', category, title]))
  163.                 genre_item.set_fanart(self.get_fanart(context))
  164.                 result.append(genre_item)
  165.                 pass
  166.         else:
  167.             params = context.get_params()
  168.             page = int(params.get('page', 1))
  169.             json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_genre,
  170.                                                          genre=genre,
  171.                                                          page=page)
  172.  
  173.             path = context.get_path()
  174.             result = self._do_mobile_collection(context, json_data, path, params)
  175.             pass
  176.  
  177.         return result
  178.  
  179.     @kodion.RegisterProviderPath('^\/explore\/?$')
  180.     def _on_explore(self, context, re_match):
  181.         result = []
  182.  
  183.         # trending music
  184.         music_trending_item = DirectoryItem(context.localize(self._local_map['soundcloud.music.trending']),
  185.                                             context.create_uri(['explore', 'trending', 'music']),
  186.                                             image=context.create_resource_path('media', 'music.png'))
  187.         music_trending_item.set_fanart(self.get_fanart(context))
  188.         result.append(music_trending_item)
  189.  
  190.         # trending audio
  191.         audio_trending_item = DirectoryItem(context.localize(self._local_map['soundcloud.audio.trending']),
  192.                                             context.create_uri(['explore', 'trending', 'audio']),
  193.                                             image=context.create_resource_path('media', 'audio.png'))
  194.         audio_trending_item.set_fanart(self.get_fanart(context))
  195.         result.append(audio_trending_item)
  196.  
  197.         # genre music
  198.         music_genre_item = DirectoryItem(context.localize(self._local_map['soundcloud.music.genre']),
  199.                                          context.create_uri(['explore', 'genre', 'music']),
  200.                                          image=context.create_resource_path('media', 'music.png'))
  201.         music_genre_item.set_fanart(self.get_fanart(context))
  202.         result.append(music_genre_item)
  203.  
  204.         # genre audio
  205.         audio_genre_item = DirectoryItem(context.localize(self._local_map['soundcloud.audio.genre']),
  206.                                          context.create_uri(['explore', 'genre', 'audio']),
  207.                                          image=context.create_resource_path('media', 'audio.png'))
  208.         audio_genre_item.set_fanart(self.get_fanart(context))
  209.         result.append(audio_genre_item)
  210.  
  211.         return result
  212.  
  213.     @kodion.RegisterProviderPath('^\/stream\/$')
  214.     def _on_stream(self, context, re_match):
  215.         result = []
  216.  
  217.         params = context.get_params()
  218.         cursor = params.get('cursor', None)
  219.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 5, self.get_client(context).get_stream,
  220.                                                      page_cursor=cursor)
  221.         path = context.get_path()
  222.         result = self._do_collection(context, json_data, path, params)
  223.         return result
  224.  
  225.     @kodion.RegisterProviderPath('^\/user/tracks\/(?P<user_id>.+)/$')
  226.     def _on_tracks(self, context, re_match):
  227.         result = []
  228.  
  229.         user_id = re_match.group('user_id')
  230.         params = context.get_params()
  231.         page = int(params.get('page', 1))
  232.  
  233.         json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_user, user_id)
  234.         user_image = json_data.get('avatar_url', '')
  235.         user_image = self._get_hires_image(user_image)
  236.  
  237.         if page == 1:
  238.             # playlists
  239.             playlists_item = DirectoryItem(context.localize(self._local_map['soundcloud.playlists']),
  240.                                            context.create_uri(['user/playlists', user_id]),
  241.                                            image=user_image)
  242.             playlists_item.set_fanart(self.get_fanart(context))
  243.             result.append(playlists_item)
  244.  
  245.             # likes
  246.             likes_item = DirectoryItem(context.localize(self._local_map['soundcloud.likes']),
  247.                                        context.create_uri(['user/favorites', user_id]),
  248.                                        image=user_image)
  249.             likes_item.set_fanart(self.get_fanart(context))
  250.             result.append(likes_item)
  251.  
  252.             # following
  253.             following_item = DirectoryItem(context.localize(self._local_map['soundcloud.following']),
  254.                                            context.create_uri(['user/following', user_id]),
  255.                                            image=user_image)
  256.             following_item.set_fanart(self.get_fanart(context))
  257.             result.append(following_item)
  258.  
  259.             # follower
  260.             follower_item = DirectoryItem(context.localize(self._local_map['soundcloud.follower']),
  261.                                           context.create_uri(['user/follower', user_id]),
  262.                                           image=user_image)
  263.             follower_item.set_fanart(self.get_fanart(context))
  264.             result.append(follower_item)
  265.             pass
  266.  
  267.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 10, self.get_client(context).get_tracks,
  268.                                                      user_id,
  269.                                                      page=page)
  270.         path = context.get_path()
  271.         result.extend(self._do_collection(context, json_data, path, params))
  272.         return result
  273.  
  274.     @kodion.RegisterProviderPath('^\/playlist\/(?P<playlist_id>.+)/$')
  275.     def _on_playlist(self, context, re_match):
  276.         result = []
  277.  
  278.         playlist_id = re_match.group('playlist_id')
  279.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).get_playlist,
  280.                                                      playlist_id)
  281.         tracks = json_data['tracks']
  282.         track_number = 1
  283.         for track in tracks:
  284.             path = context.get_path()
  285.             track_item = self._do_item(context, track, path)
  286.  
  287.             # set the name of the playlist for the albumname
  288.             track_item.set_album_name(json_data['title'])
  289.  
  290.             # based on the position in the playlist we add a track number
  291.             track_item.set_track_number(track_number)
  292.             result.append(track_item)
  293.             track_number += 1
  294.             pass
  295.  
  296.         return result
  297.  
  298.     @kodion.RegisterProviderPath('^\/user/playlists\/(?P<user_id>.+)/$')
  299.     def _on_playlists(self, context, re_match):
  300.         user_id = re_match.group('user_id')
  301.         params = context.get_params()
  302.         page = params.get('page', 1)
  303.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).get_playlists,
  304.                                                      user_id,
  305.                                                      page=page)
  306.         path = context.get_path()
  307.         return self._do_collection(context, json_data, path, params)
  308.  
  309.     @kodion.RegisterProviderPath('^\/user/following\/(?P<user_id>.+)/$')
  310.     def _on_following(self, context, re_match):
  311.         user_id = re_match.group('user_id')
  312.         params = context.get_params()
  313.         page = params.get('page', 1)
  314.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).get_following,
  315.                                                      user_id,
  316.                                                      page=page)
  317.         path = context.get_path()
  318.         return self._do_collection(context, json_data, path, params)
  319.  
  320.     @kodion.RegisterProviderPath('^\/user/follower\/(?P<user_id>.+)/$')
  321.     def _on_follower(self, context, re_match):
  322.         user_id = re_match.group('user_id')
  323.         params = context.get_params()
  324.         page = params.get('page', 1)
  325.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).get_follower,
  326.                                                      user_id,
  327.                                                      page=page)
  328.         path = context.get_path()
  329.         return self._do_collection(context, json_data, path, params)
  330.  
  331.     @kodion.RegisterProviderPath('^\/follow\/(?P<user_id>.+)/$')
  332.     def _on_follow(self, context, re_match):
  333.         user_id = re_match.group('user_id')
  334.         params = context.get_params()
  335.         follow = params.get('follow', '') == '1'
  336.         json_data = self.get_client(context).follow_user(user_id, follow)
  337.  
  338.         return True
  339.  
  340.     @kodion.RegisterProviderPath('^\/like\/(?P<category>\w+)\/(?P<content_id>.+)/$')
  341.     def _on_like(self, context, re_match):
  342.         content_id = re_match.group('content_id')
  343.         category = re_match.group('category')
  344.         params = context.get_params()
  345.         like = params.get('like', '') == '1'
  346.  
  347.         if category == 'track':
  348.             json_data = self.get_client(context).like_track(content_id, like)
  349.         elif category == 'playlist':
  350.             json_data = self.get_client(context).like_playlist(content_id, like)
  351.         else:
  352.             raise kodion.KodimonException("Unknown category '%s' in 'on_like'" % category)
  353.  
  354.         if not like:
  355.             context.get_ui().refresh_container()
  356.             pass
  357.  
  358.         return True
  359.  
  360.     @kodion.RegisterProviderPath('^\/user/favorites\/(?P<user_id>.+)/$')
  361.     def _on_favorites(self, context, re_match):
  362.         user_id = re_match.group('user_id')
  363.  
  364.         # We use an API of th APP, this API only work with an user id. In the case of 'me' we gave to get our own
  365.         # user id to use this function.
  366.         if user_id == 'me':
  367.             json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 10,
  368.                                                          self.get_client(context).get_user,
  369.                                                          'me')
  370.             user_id = json_data['id']
  371.             pass
  372.  
  373.         params = context.get_params()
  374.         page = params.get('page', 1)
  375.         # do not cache: in case of adding or deleting content
  376.         json_data = self.get_client(context).get_likes(user_id, page=page)
  377.         path = context.get_path()
  378.         return self._do_collection(context, json_data, path, params)
  379.  
  380.     def on_search(self, search_text, context, re_match):
  381.         result = []
  382.         params = context.get_params()
  383.         page = int(params.get('page', 1))
  384.         category = params.get('category', 'sounds')
  385.  
  386.         path = context.get_path()
  387.         if page == 1 and category == 'sounds':
  388.             people_params = {}
  389.             people_params.update(params)
  390.             people_params['category'] = 'people'
  391.             people_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.people']) + '[/B]',
  392.                                         context.create_uri(path, people_params),
  393.                                         image=context.create_resource_path('media', 'users.png'))
  394.             people_item.set_fanart(self.get_fanart(context))
  395.             result.append(people_item)
  396.  
  397.             playlist_params = {}
  398.             playlist_params.update(params)
  399.             playlist_params['category'] = 'sets'
  400.             playlist_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.playlists']) + '[/B]',
  401.                                           context.create_uri(path, playlist_params),
  402.                                           image=context.create_resource_path('media', 'playlists.png'))
  403.             playlist_item.set_fanart(self.get_fanart(context))
  404.             result.append(playlist_item)
  405.             pass
  406.  
  407.         json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).search,
  408.                                                      search_text,
  409.                                                      category=category, page=page)
  410.         result.extend(self._do_collection(context, json_data, path, params))
  411.         return result
  412.  
  413.     def on_root(self, context, re_match):
  414.         path = context.get_path()
  415.         result = []
  416.  
  417.         self.get_client(context)
  418.  
  419.         # is logged in?
  420.         if self._is_logged_in:
  421.             # track
  422.             json_data = self.get_client(context).get_user('me')
  423.             me_item = self._do_item(context, json_data, path)
  424.             result.append(me_item)
  425.  
  426.             # stream
  427.             stream_item = DirectoryItem(context.localize(self._local_map['soundcloud.stream']),
  428.                                         context.create_uri(['stream']),
  429.                                         image=context.create_resource_path('media', 'stream.png'))
  430.             stream_item.set_fanart(self.get_fanart(context))
  431.             result.append(stream_item)
  432.             pass
  433.  
  434.         # search
  435.         search_item = DirectoryItem(context.localize(kodion.constants.localize.SEARCH),
  436.                                     context.create_uri([kodion.constants.paths.SEARCH, 'list']),
  437.                                     image=context.create_resource_path('media', 'search.png'))
  438.         search_item.set_fanart(self.get_fanart(context))
  439.         result.append(search_item)
  440.  
  441.         # explore
  442.         explore_item = DirectoryItem(context.localize(self._local_map['soundcloud.explore']),
  443.                                      context.create_uri('explore'),
  444.                                      image=context.create_resource_path('media', 'explore.png'))
  445.         explore_item.set_fanart(self.get_fanart(context))
  446.         result.append(explore_item)
  447.  
  448.         return result
  449.  
  450.     def _do_collection(self, context, json_data, path, params):
  451.         context.set_content_type(kodion.constants.content_type.SONGS)
  452.  
  453.         """
  454.            Helper function to display the items of a collection
  455.            :param json_data:
  456.            :param path:
  457.            :param params:
  458.            :return:
  459.            """
  460.         result = []
  461.  
  462.         collection = json_data.get('collection', [])
  463.         for collection_item in collection:
  464.             # test if we have an 'origin' tag. If so we are in the activities
  465.             item = collection_item.get('origin', collection_item)
  466.             base_item = self._do_item(context, item, path)
  467.             if base_item is not None:
  468.                 result.append(base_item)
  469.                 pass
  470.             pass
  471.  
  472.         # test for next page
  473.         next_href = json_data.get('next_href', '')
  474.         re_match = re.match('.*cursor\=(?P<cursor>[a-z0-9-]+).*', next_href)
  475.         if re_match:
  476.             params['cursor'] = re_match.group('cursor')
  477.             pass
  478.  
  479.         page = int(params.get('page', 1))
  480.         if next_href and len(collection) > 0:
  481.             next_page_item = kodion.items.create_next_page_item(context, page)
  482.             next_page_item.set_fanart(self.get_fanart(context))
  483.             result.append(next_page_item)
  484.             pass
  485.  
  486.         return result
  487.  
  488.     def _get_hires_image(self, url):
  489.         return re.sub('(.*)(-large.jpg\.*)(\?.*)?', r'\1-t500x500.jpg', url)
  490.  
  491.     def _do_item(self, context, json_item, path):
  492.         def _get_track_year(collection_item_json):
  493.             # this would be the default info, but is mostly not set :(
  494.             year = collection_item_json.get('release_year', '')
  495.             if year:
  496.                 return year
  497.  
  498.             # we use a fallback.
  499.             # created_at=2013/03/24 00:32:01 +0000
  500.             re_match = re.match('(?P<year>\d{4})(.*)', collection_item_json.get('created_at', ''))
  501.             if re_match:
  502.                 year = re_match.group('year')
  503.                 if year:
  504.                     return year
  505.                 pass
  506.  
  507.             return ''
  508.  
  509.         def _get_image(json_data):
  510.             image_url = json_data.get('artwork_url', '')
  511.  
  512.             # test avatar image
  513.             if not image_url:
  514.                 image_url = json_data.get('avatar_url', '')
  515.  
  516.             # test tracks (used for playlists)
  517.             if not image_url:
  518.                 tracks = json_data.get('tracks', [])
  519.                 if len(tracks) > 0:
  520.                     return _get_image(tracks[0])
  521.  
  522.                 # fall back is the user avatar (at least)
  523.                 image_url = json_data.get('user', {}).get('avatar_url', '')
  524.                 pass
  525.  
  526.             # try to convert the image to 500x500 pixel
  527.             return self._get_hires_image(image_url)
  528.  
  529.         kind = json_item.get('kind', '')
  530.         if kind == 'playlist':
  531.             playlist_item = DirectoryItem(json_item['title'],
  532.                                           context.create_uri(['playlist', unicode(json_item['id'])]),
  533.                                           image=_get_image(json_item))
  534.             playlist_item.set_fanart(self.get_fanart(context))
  535.  
  536.             if path == '/user/favorites/me/':
  537.                 context_menu = [(context.localize(self._local_map['soundcloud.unlike']),
  538.                                  'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])],
  539.                                                                       {'like': '0'}))]
  540.             else:
  541.                 context_menu = [(context.localize(self._local_map['soundcloud.like']),
  542.                                  'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])],
  543.                                                                       {'like': '1'}))]
  544.  
  545.             playlist_item.set_context_menu(context_menu)
  546.             return playlist_item
  547.         elif kind == 'user':
  548.             username = json_item['username']
  549.             user_id = unicode(json_item['id'])
  550.             if path == '/':
  551.                 user_id = 'me'
  552.                 username = '[B]' + username + '[/B]'
  553.                 pass
  554.             user_item = DirectoryItem(username,
  555.                                       context.create_uri(['user/tracks', user_id]),
  556.                                       image=_get_image(json_item))
  557.             user_item.set_fanart(self.get_fanart(context))
  558.  
  559.             if path == '/user/following/me/':
  560.                 context_menu = [(context.localize(self._local_map['soundcloud.unfollow']),
  561.                                  'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])],
  562.                                                                       {'follow': '0'}))]
  563.                 pass
  564.             else:
  565.                 context_menu = [(context.localize(self._local_map['soundcloud.follow']),
  566.                                  'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])],
  567.                                                                       {'follow': '1'}))]
  568.                 pass
  569.             user_item.set_context_menu(context_menu)
  570.             return user_item
  571.         elif kind == 'track':
  572.             title = json_item['title']
  573.             track_item = AudioItem(title,
  574.                                    context.create_uri('play', {'id': unicode(json_item['id'])}),
  575.                                    image=_get_image(json_item))
  576.             track_item.set_fanart(self.get_fanart(context))
  577.  
  578.             # title
  579.             track_item.set_title(title)
  580.  
  581.             # genre
  582.             track_item.set_genre(json_item.get('genre', ''))
  583.  
  584.             # duration
  585.             track_item.set_duration_from_milli_seconds(json_item.get('duration', 0))
  586.  
  587.             # artist
  588.             track_item.set_artist_name(json_item.get('user', {}).get('username', ''))
  589.  
  590.             # year
  591.             track_item.set_year(_get_track_year(json_item))
  592.  
  593.             if path == '/user/favorites/me/':
  594.                 context_menu = [(context.localize(self._local_map['soundcloud.unlike']),
  595.                                  'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])],
  596.                                                                       {'like': '0'}))]
  597.                 pass
  598.             else:
  599.                 context_menu = [(context.localize(self._local_map['soundcloud.like']),
  600.                                  'RunPlugin(%s)' % context.create_uri(['like/track', unicode(json_item['id'])],
  601.                                                                       {'like': '1'}))]
  602.             track_item.set_context_menu(context_menu)
  603.  
  604.             return track_item
  605.         elif kind == 'like':
  606.             # A like has 'playlist' or 'track' so we find one of them and call this routine again, because the
  607.             # data is same.
  608.             test_playlist = json_item.get('playlist', None)
  609.             if test_playlist is not None:
  610.                 return self._do_item(context, test_playlist, path)
  611.  
  612.             test_track = json_item.get('track', None)
  613.             if test_track is not None:
  614.                 return self._do_item(context, test_track, path)
  615.             pass
  616.         elif kind == 'group':
  617.             # at the moment we don't support groups
  618.             """
  619.            group_item = DirectoryItem('Group-Dummy',
  620.                                       '')
  621.            return group_item
  622.            """
  623.             return None
  624.  
  625.         raise kodion.KodimonException("Unknown kind of item '%s'" % kind)
  626.  
  627.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement