From d9d18020d0f217009c5a0463a821f243381ebf81 Mon Sep 17 00:00:00 2001 From: Logykk <35679186+logykk@users.noreply.github.com> Date: Sat, 23 Oct 2021 13:00:46 +1300 Subject: [PATCH] Fixed bug preventing downloading with artist url --- zspotify.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/zspotify.py b/zspotify.py index bb7957e..a91e11a 100755 --- a/zspotify.py +++ b/zspotify.py @@ -143,7 +143,7 @@ def client(): download_track(song['track']['id'], "Liked Songs/") print("\n") else: - track_id_str, album_id_str, playlist_id_str, episode_id_str, show_id_str = regex_input_for_urls( + track_id_str, album_id_str, playlist_id_str, episode_id_str, show_id_str, artist_id_str = regex_input_for_urls( sys.argv[1]) if track_id_str is not None: @@ -237,7 +237,6 @@ def regex_input_for_urls(search_input): search_input, ) - if track_uri_search is not None or track_url_search is not None: track_id_str = (track_uri_search if track_uri_search is not None else @@ -275,8 +274,8 @@ def regex_input_for_urls(search_input): if artist_uri_search is not None or artist_url_search is not None: artist_id_str = (artist_uri_search - if artist_uri_search is not None else - artist_url_search).group("ArtistID") + if artist_uri_search is not None else + artist_url_search).group("ArtistID") else: artist_id_str = None @@ -585,6 +584,8 @@ def get_album_name(access_token, album_id): return resp['artists'][0]['name'], sanitize_data(resp['name']) # Extra functions directly related to spotify artists + + def get_artist_albums(access_token, artist_id): """ Returns artist's albums """ headers = {'Authorization': f'Bearer {access_token}'} @@ -594,6 +595,8 @@ def get_artist_albums(access_token, artist_id): return [resp['items'][i]['id'] for i in range(len(resp['items']))] # Extra functions directly related to our saved tracks + + def get_saved_tracks(access_token): """ Returns user's saved tracks """ songs = [] @@ -624,8 +627,10 @@ def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value song_name = artists[0] + " - " + name if prefix: - song_name = f'{prefix_value.zfill(2)}-{song_name}' if prefix_value.isdigit() else f'{prefix_value}-{song_name}' - filename = os.path.join(ROOT_PATH, extra_paths, song_name + '.' + MUSIC_FORMAT) + song_name = f'{prefix_value.zfill(2)}-{song_name}' if prefix_value.isdigit( + ) else f'{prefix_value}-{song_name}' + filename = os.path.join(ROOT_PATH, extra_paths, + song_name + '.' + MUSIC_FORMAT) except Exception as e: print("### SKIPPING SONG - FAILED TO QUERY METADATA ###") # print(e) @@ -686,7 +691,9 @@ def download_album(album): artist, album_name = get_album_name(token, album) tracks = get_album_tracks(token, album) for n, track in tqdm(enumerate(tracks, start=1), unit_scale=True, unit='Song', total=len(tracks)): - download_track(track['id'], f'{artist}/{album_name}', prefix=True, prefix_value=str(n), disable_progressbar=True) + download_track(track['id'], f'{artist}/{album_name}', + prefix=True, prefix_value=str(n), disable_progressbar=True) + def download_artist_albums(artist): """ Downloads albums of an artist """ @@ -695,6 +702,7 @@ def download_artist_albums(artist): for album_id in albums: download_album(album_id) + def download_playlist(playlists, playlist_choice): """Downloads all the songs from a playlist""" token = SESSION.tokens().get("user-read-email")