spotify_assistant.User

Module Contents

Classes

User

class spotify_assistant.User.User(client_credentials)[source]
classmethod get_map()[source]

Gets continent to country map

Returns:

A hashmap

Return type:

Dict

__get_releases(continent: str, limit: int = 5)

Gets the top new releases

Parameters:
  • continent (str) – The continent where the new releases were published

  • limit (int) – Number of new releases to return

Returns:

A list of dictionaries. Each dictionary contains metadata of 1 new release.

Return type:

List

classmethod extract_albums(all_releases)[source]

Extracts the album names and the corresponding artists

Parameters:

all_releases (list) – A list of dictionaries. Each dictionary contains metadata for 1 new release.

Returns:

A list of dictionaries. Each dictionary contains metadata for 1 new release.

Return type:

List

get_new_releases_by_continent(continent: str, limit: int = 5)[source]

Gets the new releases by continent

Usually the style of music from the same continent are similar, and this helps users find and explore songs similar to their taste.

Parameters:

continent (str) – continent name (i.e. Asia, Europe, Oceania, Americas, Africa)

Returns:

A list of titles of new releases in String from the corresponding continent

Return type:

List

Examples

>>> User.get_new_releases_by_continent("Asia")
__get_saved_track()

Returns the user’s saved tracks

Returns:

A list of dictionaries. Each dictionary contains metadata of 1 track.

Return type:

List

__get_artists(artists)

Returns the metadata of a list of artists

Parameters:

artists (list) – list of artist IDs (strings)

Returns:

A list of dictionaries. Each dictionary contains metadata of 1 artist.

Return type:

List

classmethod get_top_genres(artist_information)[source]

Returns the most commonly occuring genres among different artists

Parameters:

artist_information (list) – list of dictionaries containing artist metadata

Returns:

A list of most common genres

Return type:

List

get_users_top_genres()[source]

Finds the top 5 genres from a user’s saved tracks

Returns:

A list of the top 5 genres that a user likes

Return type:

List

Examples

>>> credentials = {}
>>> RandomUser = User(credentials)
>>> RandomUser.get_users_top_genres()
__get_all_playlists()

Calls the spotify api and returns the current user’s saved/owned playlists

Returns:

A list of spotify responses containing information about a user’s playlists

Return type:

list

classmethod filter_playlists(playlist_response, playlists=None)[source]

Filters a spotify playlist response for specified playlists

Parameters:
  • playlist_response (list) – list of spotify responses containing information about playlists

  • playlists (list) – list of playlist names (strings) to get songs from, defaults to all

Returns:

A dictionary with the names of playlists as keys, and the playlist id as the value

Return type:

dict

__get_one_playlists_songs(playlist_id)

Calls the spotify api and returns the all the songs in a playlist

Returns:

A list of spotify responses containing all the songs in a playlist

Return type:

list

classmethod format_songs(song_response)[source]

Formats a spotify response into just song names

Parameters:
  • playlist_response (list) – list of spotify responses containing information about playlists

  • playlists (list) – list of playlist names (strings) to get songs from, defaults to all

Returns:

A dictionary with the names of playlists as keys, and the playlist id as the value

Return type:

dict

get_users_playlists_songs(playlists=None)[source]

Gets all of the song titles within a user’s owned and followed playlists

Playlists from which to retrieve songs can be specified by name as a list, but by default all songs from all of a user’s owned and followed playlists will be retrieved. Due to access restrictions, non-collaborative, private playlists cannot be retrieved.

Parameters:

playlists (list) – list of playlist names (strings) to get songs from, defaults to all

Returns:

A dictionary with the names of playlists as keys, and a list of song titles contained in the playlist as values

Return type:

dict

Examples

>>> credentials = {}
>>> Caroline = User(credentials)
>>> Caroline.get_playlists_songs()
__get_top_artists()

Returns the current user’s top artists from Spotify.

Returns:

A list of artist information.

Return type:

list

classmethod extract_artist_id(artists)[source]

Extracts Returns the current user’s top artists from Spotify.

Parameters:

artists (list) – A list of artist information (name, ID, etc.).

Returns:

A list of artist id’s.

Return type:

list

__get_genre_seeds()

Returns 5 genre seeds from Spotify.

Returns:

A list of genre seeds.

Return type:

list

Returns a specified number of recommended songs from Spotify.

Parameters:
  • seed_type (str) – Either ‘artists’ or ‘genres’. Default is ‘artists’.

  • seeds (list) – A list of artist or track ID’s.

  • num_songs (int) – The number of recommended songs to return. Must be between 1 and 100 (inclusive).

Returns:

A list of track uri’s for identifying specific tracks.

Return type:

list

__create_playlist(playlist_name)

Creates a new, empty playlist for the user on Spotify.

Parameters:

playlist_name (str) – The name of the new playlist.

Returns:

A tuple containing the url and playlist id for the new playlist.

Return type:

(str, str)

__add_songs_to_playlist(playlist_id, new_songs)

Adds songs to a specified user playlist on Spotify.

Parameters:
  • playlist_id (str) – The id of the new playlist.

  • new_songs (list) – List of track ID’s corresponding to songs to add to the playlist.

get_song_recommendations(playlist_name=None, num_songs=10)[source]

Creates a playlist containing recommended songs based on the user’s top 3 artists. If there are not yet any top artists for the user’s account, use genres instead.

Prints a url link to the new playlist on Spotify.

Parameters:
  • playlist_name (str) – The name of the newly created playlist. Defaults to ‘Recommended Songs’ with the current date (i.e. “2023-01-14 Recommended Songs”).

  • num_songs (int) – The number of songs to recommend. Must be between 1 and 100 (inclusive).

Examples

>>> credentials = {}
>>> RandomUser = User(credentials)
>>> RandomUser.get_song_recommendations("Recommended Songs")