Example #1
0
def playlist_add_tracks_uri(playlist_id, list_of_track_uri):
    print(
        f"playlist_add_tracks_uri: {playlist_id} - length of list uri: {len(list_of_track_uri)}"
    )
    for i in range(0, len(list_of_track_uri), 100):
        results = SPOTIFY_API.user_playlist_add_tracks(
            SPOTIFY_DATA['username'], playlist_id,
            list_of_track_uri[i:i + 100])
Example #2
0
def playlist_get_all():
    try:
        limit = 50
        count = 0
        playlists = SPOTIFY_API.user_playlists(SPOTIFY_DATA['username'],
                                               limit=limit,
                                               offset=0)
        while len(playlists['items']) != 0:
            for playlist in playlists['items']:
                SPOTIFY_PLAYLISTS[playlist['name']] = playlist['id']
            count += 1
            playlists = SPOTIFY_API.user_playlists(SPOTIFY_DATA['username'],
                                                   limit=limit,
                                                   offset=count * limit)
    except Exception as e:
        print(e)
        return None
Example #3
0
def spotify_get_artist_top_tracks(artist_uri):
    artist = SPOTIFY_API.artist_top_tracks(artist_uri)

    tracks = []

    for track in artist['tracks'][:10]:
        tracks.append(track['uri'])

    return tracks
Example #4
0
def playlist_create(p_name):
    try:
        playlist = SPOTIFY_API.user_playlist_create(SPOTIFY_DATA['username'],
                                                    p_name, True)
        print(f'playlist created: ({p_name})')
        return playlist['id']
    except Exception as e:
        print(f'playlist created: ({p_name}) was not created due to exception')
        return None
Example #5
0
def spotify_find_track(artist, title):
    artist = prepare_string_for_search(artist)
    title = prepare_string_for_search(title)

    search_str = 'artist:"' + str(artist) + '" track:"' + str(title) + '"'
    results = SPOTIFY_API.search(q=search_str, limit=1, type='track')

    try:
        track = results['tracks']['items'][0]
        # print(f"Track found on Spotify: {artist} - {title}")
        return track
    except:
        print(f"\nTrack NOT found on Spotify: {artist} - {title}\n")
        return None
Example #6
0
def spotify_get_artist(artist_name):
    results = SPOTIFY_API.search(q='artist:' + artist_name,
                                 limit=10,
                                 type='artist')

    try:
        for artist in results['artists']['items']:
            if artist['name'].lower() == artist_name.lower():
                return artist

        print(f"\nArtist NOT found on Spotify: {artist_name}\n")
        return None
    except:
        print(f"\nArtist NOT found on Spotify: {artist_name}\n")
        return None
Example #7
0
def spotify_get_recommended_tracks_list(tracks, end_date='3000-01-01'):
    # print(f'lastfm_get_recommended_tracks_list: {end_date}')

    list_of_tracks = []

    tracks_uri = spotify_find_list_of_tracks(tracks)
    for track in tracks_uri:
        tracks_recommended = SPOTIFY_API.recommendations(seed_tracks=[track],
                                                         limit=5)
        for rec_track in tracks_recommended['tracks']:
            if not database_find_track_interval(
                    rec_track['artists'][0]['name'], rec_track['name'],
                    end_date):
                list_of_tracks.append(rec_track['uri'])

    return list_of_tracks