mirror of
				https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
				synced 2025-11-03 21:10:34 +00:00 
			
		
		
		
	added progress bar for album download
This commit is contained in:
		
							parent
							
								
									fb52d653a5
								
							
						
					
					
						commit
						16ecf274b5
					
				
							
								
								
									
										14
									
								
								zspotify.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								zspotify.py
									
									
									
									
									
								
							@ -27,7 +27,6 @@ from tqdm import tqdm
 | 
				
			|||||||
SESSION: Session = None
 | 
					SESSION: Session = None
 | 
				
			||||||
sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
 | 
					sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
# Hardcoded variables that adjust the core functionality of ZSpotify
 | 
					# Hardcoded variables that adjust the core functionality of ZSpotify
 | 
				
			||||||
ROOT_PATH = "ZSpotify Music/"
 | 
					ROOT_PATH = "ZSpotify Music/"
 | 
				
			||||||
ROOT_PODCAST_PATH = "ZSpotify Podcasts/"
 | 
					ROOT_PODCAST_PATH = "ZSpotify Podcasts/"
 | 
				
			||||||
@ -45,6 +44,7 @@ ANTI_BAN_WAIT_TIME = 1
 | 
				
			|||||||
OVERRIDE_AUTO_WAIT = False
 | 
					OVERRIDE_AUTO_WAIT = False
 | 
				
			||||||
CHUNK_SIZE = 50000
 | 
					CHUNK_SIZE = 50000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# miscellaneous functions for general use
 | 
					# miscellaneous functions for general use
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -421,7 +421,7 @@ def get_song_info(song_id):
 | 
				
			|||||||
    token = SESSION.tokens().get("user-read-email")
 | 
					    token = SESSION.tokens().get("user-read-email")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    info = json.loads(requests.get("https://api.spotify.com/v1/tracks?ids=" + song_id +
 | 
					    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 = []
 | 
					    artists = []
 | 
				
			||||||
    for data in info['tracks'][0]['artists']:
 | 
					    for data in info['tracks'][0]['artists']:
 | 
				
			||||||
@ -588,7 +588,7 @@ def get_saved_tracks(access_token):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Functions directly related to downloading stuff
 | 
					# 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 """
 | 
					    """ 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
 | 
					    global ROOT_PATH, SKIP_EXISTING_FILES, MUSIC_FORMAT, RAW_AUDIO_AS_IS, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
@ -631,7 +631,8 @@ def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value
 | 
				
			|||||||
                            total=total_size,
 | 
					                            total=total_size,
 | 
				
			||||||
                            unit='B',
 | 
					                            unit='B',
 | 
				
			||||||
                            unit_scale=True,
 | 
					                            unit_scale=True,
 | 
				
			||||||
                            unit_divisor=1024
 | 
					                            unit_divisor=1024,
 | 
				
			||||||
 | 
					                            disable=disable_progressbar
 | 
				
			||||||
                    ) as bar:
 | 
					                    ) as bar:
 | 
				
			||||||
                        for _ in range(int(total_size / CHUNK_SIZE) + 1):
 | 
					                        for _ in range(int(total_size / CHUNK_SIZE) + 1):
 | 
				
			||||||
                            bar.update(file.write(
 | 
					                            bar.update(file.write(
 | 
				
			||||||
@ -657,9 +658,8 @@ def download_album(album):
 | 
				
			|||||||
    token = SESSION.tokens().get("user-read-email")
 | 
					    token = SESSION.tokens().get("user-read-email")
 | 
				
			||||||
    artist, album_name = get_album_name(token, album)
 | 
					    artist, album_name = get_album_name(token, album)
 | 
				
			||||||
    tracks = get_album_tracks(token, album)
 | 
					    tracks = get_album_tracks(token, album)
 | 
				
			||||||
    for n, track in enumerate(tracks, start=1):
 | 
					    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))
 | 
					        download_track(track['id'], f'{artist}/{album_name}', prefix=True, prefix_value=str(n), disable_progressbar=True)
 | 
				
			||||||
        print("\n")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def download_playlist(playlists, playlist_choice):
 | 
					def download_playlist(playlists, playlist_choice):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user