Exemplo n.º 1
0
    async def add_spotify_playlist(self, url):
        urls = []
        data = spotify_tools.fetch_playlist(url)
        urls.append(data['name'])
        tracks = data['tracks']
        while True:
            for item in tracks['items']:
                if 'track' in item:
                    track = item['track']
                else:
                    track = item
                try:
                    track_url = track['external_urls']['spotify']
                    #log.debug(track_url)
                    #print(track_url)
                    urls.append(track_url)
                    #self.add_spotify_track(track_url)
                    #track_urls.append(track_url)
                except KeyError:
                    pass
                    #log.warning(u'Skipping track {0} by {1} (local only?)'.format(
                    #track['name'], track['artists'][0]['name']))
            # 1 page = 50 results
            # check if there are more pages
            if tracks['next']:
                tracks = spotify.next(tracks)
            else:
                break

        return urls
Exemplo n.º 2
0
    async def add_spotify_playlist(self, url):
        urls = []
        data = spotify_tools.fetch_playlist(url)
        urls.append(data['name'])
        tracks = data['tracks']
        while True:
            for item in tracks['items']:
                if 'track' in item:
                    track = item['track']
                else:
                    track = item
                try:
                    track_url = track['external_urls']['spotify']
                    urls.append(track_url)
                except KeyError:
                    pass
            if tracks['next']:
                # TODO
                # tracks = spotify.next(tracks)
                pass
            else:
                break

        return urls