def get_song_spotify(app_token):
    global attempts
    spotify = Spotify(app_token)
    playlist_id_spotify = input("Enter the spotify playlist id")
    playlist = spotify.playlist_items(playlist_id_spotify, as_tracks=True)
    print(playlist)
    playlist = playlist["items"]
    print(playlist)
    try:
        i = 0
        songIds = []
        whileLoop = True

        # Gets the song ids from the returned dictionary
        while whileLoop:
            subPlaylist = playlist[i]
            subPlaylist.pop("added_at", None)
            subPlaylist.pop("added_by", None)
            subPlaylist.pop("is_local", None)
            subPlaylist.pop("primary_color", None)
            subPlaylist = subPlaylist["track"]
            subPlaylist.pop("album", None)
            subPlaylist.pop("artists", None)
            subPlaylist.pop("available_markets", None)
            subPlaylist = subPlaylist["id"]
            print(subPlaylist)
            songIds.append(subPlaylist)
            i += 1

    except IndexError:
        pass

    for i in range(len(songIds)):
        track = spotify.track(songIds[i], market=None)
        artist = track.artists
        artist = artist[0]
        print(f"{track.name} by {artist.name}")
        get_song_youtube(f"{track.name} by {artist.name}")
Ejemplo n.º 2
0
 def test_request_with_closed_client_raises(self):
     client = Spotify()
     client.close()
     with pytest.raises(RuntimeError):
         client.track('id')