added progress bar for album download

This commit is contained in:
Raju komati 2021-10-22 20:44:13 +05:30
parent fb52d653a5
commit 16ecf274b5

View File

@ -27,7 +27,6 @@ from tqdm import tqdm
SESSION: Session = None
sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
# Hardcoded variables that adjust the core functionality of ZSpotify
ROOT_PATH = "ZSpotify Music/"
ROOT_PODCAST_PATH = "ZSpotify Podcasts/"
@ -45,6 +44,7 @@ ANTI_BAN_WAIT_TIME = 1
OVERRIDE_AUTO_WAIT = False
CHUNK_SIZE = 50000
# miscellaneous functions for general use
@ -421,7 +421,7 @@ def get_song_info(song_id):
token = SESSION.tokens().get("user-read-email")
info = json.loads(requests.get("https://api.spotify.com/v1/tracks?ids=" + song_id +
'&market=from_token', headers={"Authorization": "Bearer %s" % token}).text)
'&market=from_token', headers={"Authorization": "Bearer %s" % token}).text)
artists = []
for data in info['tracks'][0]['artists']:
@ -588,7 +588,7 @@ def get_saved_tracks(access_token):
# Functions directly related to downloading stuff
def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value=''):
def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value='', disable_progressbar=False):
""" Downloads raw song audio from Spotify """
global ROOT_PATH, SKIP_EXISTING_FILES, MUSIC_FORMAT, RAW_AUDIO_AS_IS, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT
try:
@ -631,7 +631,8 @@ def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value
total=total_size,
unit='B',
unit_scale=True,
unit_divisor=1024
unit_divisor=1024,
disable=disable_progressbar
) as bar:
for _ in range(int(total_size / CHUNK_SIZE) + 1):
bar.update(file.write(
@ -657,9 +658,8 @@ def download_album(album):
token = SESSION.tokens().get("user-read-email")
artist, album_name = get_album_name(token, album)
tracks = get_album_tracks(token, album)
for n, track in enumerate(tracks, start=1):
download_track(track['id'], f'{artist}/{album_name}', prefix=True, prefix_value=str(n))
print("\n")
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)
def download_playlist(playlists, playlist_choice):