def fetch_album_from_artist(artist_url, album_type="album"):
    """
    This funcction returns all the albums from a give artist_url using the US
    market
    :param artist_url - spotify artist url
    :param album_type - the type of album to fetch (ex: single) the default is
                        a standard album
    :param return - the album from the artist
    """

    # fetching artist's albums limitting the results to the US to avoid duplicate
    # albums from multiple markets
    artist_id = internals.extract_spotify_id(artist_url)
    results = spotify.artist_albums(artist_id,
                                    album_type=album_type,
                                    country="US")

    albums = results["items"]

    # indexing all pages of results
    while results["next"]:
        results = spotify.next(results)
        albums.extend(results["items"])

    return albums
Example #2
0
def fetch_playlist(playlist):
    try:
        playlist_id = internals.extract_spotify_id(playlist)
    except IndexError:
        # Wrong format, in either case
        log.error("The provided playlist URL is not in a recognized format!")
        sys.exit(10)
    try:
        results = spotify.user_playlist(
            user=None, playlist_id=playlist_id, fields="tracks,next,name"
        )
    except spotipy.client.SpotifyException:
        log.error("Unable to find playlist")
        log.info("Make sure the playlist is set to publicly visible and then try again")
        sys.exit(11)

    return results
Example #3
0
def clear_playlist(playlist):
    try:
        playlist_id = internals.extract_spotify_id(playlist)
    except IndexError:
        # Wrong format, in either case
        log.error("The provided playlist URL is not in a recognized format!")
        sys.exit(10)
    try:
        results = spotify.user_playlist_replace_tracks(user=None,
                                                       playlist_id=playlist_id,
                                                       tracks=[])
    except spotipy.client.SpotifyException as e:
        log.info(repr(e))
        log.error("Unable to clear/modify playlist")
        log.info(
            "Make sure the playlist is set to publicly visible and can be edited"
        )
        sys.exit(11)

    return results
Example #4
0
def test_extract_spotify_id(input_str, expected_spotify_id):
    spotify_id = internals.extract_spotify_id(input_str)
    assert spotify_id == expected_spotify_id
def fetch_album(album):
    album_id = internals.extract_spotify_id(album)
    album = spotify.album(album_id)
    return album