Exemplo n.º 1
0
def get_name_for_list_widget(category_list, url):
    "This function get the album/song/playlist/artist name from url"
    try:
        if category_list == 'playlist':
            playlist = spotify_tools.fetch_playlist(url)
            name = playlist['name']
            text_file = "Playlist:  " + name
        elif category_list == 'track':
            track = spotify_tools.generate_metadata(url)
            name = track['name']
            artist_name = track['album']['artists'][0]['name']
            text_file = 'Song:  ' + name + ' - ' + artist_name
        elif category_list == 'artist':
            artist = spotify_tools.fetch_albums_from_artist(url)
            name = artist[0]['artists'][0]['name']
            text_file = u"Complete albums of " + artist[0]['artists'][0]['name']
        elif category_list == 'album':
            album = spotify_tools.fetch_album(url)
            name = u"{0}".format(slugify(album["name"], ok="-_()[]{}"))
            text_file = 'Album:  ' + name + ' - ' + album['artists'][0]['name']
        else:
            text_file = 'Not Found name'
            name = ''
    except Exception as e:
        print(
            "{} name not found! Setting standard name.".format(category_list))
        text_file = str(category_list) + url[31:-1]
        name = ' '

    return text_file, name
Exemplo n.º 2
0
def match_args():
    # Todo major changing here, I shall probably change everything,
    # I add operation variable, for now it is a patch
    operation = ''
    text_file = ''
    tracks_url = []

    if const.args.song:
        for track in const.args.song:
            track_dl = EnhancedDownloader(raw_song=track)
            track_dl.download_single()
        operation = 'list'

    elif const.args.playlist:
        tracks_url = spotify_tools.write_playlist(
            playlist_url=const.args.playlist, text_file=const.args.write_to)

        playlist = spotify_tools.fetch_playlist(const.args.playlist)
        text_file = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}"))
        operation = 'playlist'

    elif const.args.album:
        tracks_url = spotify_tools.write_album(album_url=const.args.album,
                                               text_file=const.args.write_to)
        album = spotify_tools.fetch_album(const.args.album)
        text_file = u"{0}.txt".format(slugify(album["name"], ok="-_()[]{}"))
        operation = 'album'

    elif const.args.all_albums:
        spotify_tools.write_all_albums_from_artist(
            artist_url=const.args.all_albums, text_file=const.args.write_to)
        albums = spotify_tools.fetch_albums_from_artist(const.args.all_albums,
                                                        album_type=None)
        text_file = albums[0]["artists"][0]["name"] + ".txt"
        operation = 'all_album'

    # Todo: the user playlist require user input in cmd. I will exclude it for now.

    elif const.args.username:
        spotify_tools.write_user_playlist(username=const.args.username,
                                          text_file=const.args.write_to)
        # playlist = spotify_tools.fetch_playlist(const.args.playlist)
        # text_file = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}"))
        # operation = 'username'
        #

    return operation, text_file, tracks_url
def get_artist_albums_metadata(artist_link, small=False):
    """
    Get all artist's albums metadata
    :param artist_link: Artist link on Spotify
    :param small: Indicating if the metadata should be small or whole
    :return: Array of dictionaries of albums metadata in following format (If small is True):
            [ { name: % album name %, count: % number of tracks %, link: % album link % } ]
            Otherwise, it contains the full album object as Spotify API show here:
            https://developer.spotify.com/documentation/web-api/reference/albums/get-album/
    """
    album_base_url = 'https://open.spotify.com/album/'
    fetched_albums = spotify_tools.fetch_albums_from_artist(artist_link)
    albums = []

    for album in fetched_albums:
        albums.append(
            get_small_metadata(album)
            if small else get_album_metadata(album_base_url + album['id']))

    return albums
 def albums_from_artist_fixture(self):
     albums = spotify_tools.fetch_albums_from_artist(
         "https://open.spotify.com/artist/7oPftvlwr6VrsViSDV7fJY")
     return albums