src package

Submodules

src.Artist module

class src.Artist.Artist(name, oauth=None)

Bases: object

src.Artist.get_album_data_by_artist(artist_id, oauth, country='US', limit=50)

Gets a list of artist’s albums

Parameters
  • artist_id (str) – Artist’s name / title

  • oauth (str) – OAuth Token retrieved from Spotify

  • country (str (default is “US”)) – Country code from within search should be executed

  • limit (int (default is 50)) – Limit of albums to search; current max is 50

Returns

List of album names for artist

Return type

list of str

src.Artist.get_artist_external_url(artist_name, oauth)

Gets the external_url for a specified artist

Parameters
  • artist_name (str) – Artist’s name / title

  • oauth (str) – OAuth Token retrieved from Spotify

Returns

External Spotify URL for artist

Return type

str

src.Artist.get_artist_id(artist_name, oauth)

Returns the id for a specified artist

Parameters
  • artist_name (str) – Artist’s name / title

  • oauth (str) – OAuth Token retrieved from Spotify

Returns

Spotify ID for artist

Return type

str

src.Artist.query_artist(artist_name, oauth)

Gets Spotify data of an artist in json format

Parameters
  • artist_name (str) – Artist’s name / title

  • oauth (str) – OAuth Token retrieved from Spotify

Returns

Contains artist data returned from Spotify API

Return type

dict

src.Exceptions module

Defines specific exceptions to throw

exception src.Exceptions.PlaylistNotInitializedError(msg=None)

Bases: Exception

Exception to raise if a playlist cannot be created in Spotify

exception src.Exceptions.UnsuccessfulGetRequest(msg=None)

Bases: Exception

Exception to raise if a GET request to the API fails

src.Playlist module

Class for interacting with Playlists through the Spotify API

class src.Playlist.Playlist(name='Unnamed Playlist', tracks=None, playlist_id=None)

Bases: object

spotify_add_track(oauth, track_id, quiet=False)

Adds a track to a playlist on Spotify via the Track ID

Parameters
  • oauth (str) – OAuth Token retrieved from Spotify

  • track_id (str) – ID corresponding to track to add to Playlist

  • quiet (bool (default is False)) – If true, suppress output; no functional difference

Returns

True upon success, else False

Return type

bool

spotify_add_tracks(oauth_token, quiet=False)

Adds tracks in self.tracks to the playlist in Spotify. If any tracks are missed, append them to the missed_tracks list

Parameters
  • oauth_token (str) – OAuth Token retrieved from Spotify

  • quiet (bool (default is False)) – If true, suppress output; no functional difference

Returns

List includes Tracks unable to be added to the playlist

Return type

list(Tracks)

spotify_init(oauth, description='Playlist generated from Spotify API')

Creates a new playlist for the logged-in user on Spotify and updates the Playlist object attributes accordingly

Parameters
  • oauth (str) – OAuth Token retrieved from Spotify

  • description (str) – Playlist description

Raises

PlaylistNotInitializedError – Raised if Playlist cannot be created in Spotify

Returns

True if playlist was created, else False

Return type

bool

src.Track module

Class for interacting with Tracks through the Spotify API

class src.Track.Track(song, artist, href=None, external_url=None, track_id=None)

Bases: object

spotify_query(oauth, lev_partial_ratio=75, market='US', limit=10)

Finds a track via a Spotify search

Parameters
  • oauth (str) – OAuth Token retrieved from Spotify

  • lev_partial_ratio (int [0-100]) – Levenshtein distance ratio

  • market (str (default is “US”)) – Country market

  • limit (int (default is 10)) – Limit of tracks to query; max is 10 as of v1 of API

Returns

True if track is found, else False; mutates Track object with Spotify data if found

Return type

bool

view_top_results(oauth, market='US', limit=10)

Prints a track’s top search results from a Spotify query

Parameters
  • oauth (str) – OAuth Token retrieved from Spotify

  • market (str (default is “US”)) – Country market

  • limit (int (default is 10)) – Limit of tracks to query; max is 10 as of v1 of API

Returns

Prints results to stdout

Return type

None

src.general_functions module

Functions supporting use of the Spotify API

src.general_functions.generate_random_string(length)
src.general_functions.get_json_response_dict(oauth, search_url)

Returns a json dict from a REST GET request

Parameters
  • oauth (str) – OAuth Token retrieved from Spotify

  • search_url (str) – URL to query

Returns

Data returned from search_url GET request

Return type

dict

src.general_functions.get_random_character()
src.general_functions.print_pretty_json(json_data_loads)

Prints a formatted json to stdout

Parameters

json_data_loads (dict) – json formatted as a dict by json library

Returns

Prints to stdout

Return type

None

src.parse_file_into_tracks module

Parses a file containing a list of delimited tracks into a list of Track objects

src.parse_file_into_tracks.parse_file_playlist(fname, delimiter=', ')

Generates a list of Tracks from a list delimited as [artist, song]

Parameters
  • fname (str) – file name to parse into list

  • delimiter (str (default is “,”)) – string which splits artist and song name

Returns

Return type

list of Tracks

src.parse_file_into_tracks.parse_string_playlist(content, delimiter=', ')

Generates a list of Tracks from a block of text delimited as [artist, song]

Parameters
  • content (str) – Text containing tracks separated by new lines

  • delimiter (str (default is “,”)) – string which splits artist and song name

Returns

Return type

list of Tracks

Module contents