Merge pull request #59 from komatiraju032/main

added album download to separated folder
This commit is contained in:
Footsiefat 2021-10-23 12:49:10 +13:00 committed by GitHub
commit 42a92fdebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

3
.gitignore vendored
View File

@ -146,3 +146,6 @@ credentials.json
#Download Folder #Download Folder
ZSpotify\ Music/ ZSpotify\ Music/
ZSpotify\ Podcasts/ ZSpotify\ Podcasts/
# Intellij
.idea

View File

@ -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
@ -615,7 +615,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=""): 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:
@ -623,7 +623,9 @@ def download_track(track_id_str: str, extra_paths=""):
track_id_str) track_id_str)
song_name = artists[0] + " - " + name song_name = artists[0] + " - " + name
filename = ROOT_PATH + extra_paths + song_name + '.' + MUSIC_FORMAT 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)
except Exception as e: except Exception as e:
print("### SKIPPING SONG - FAILED TO QUERY METADATA ###") print("### SKIPPING SONG - FAILED TO QUERY METADATA ###")
# print(e) # print(e)
@ -656,7 +658,8 @@ def download_track(track_id_str: str, extra_paths=""):
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(
@ -682,9 +685,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 track in tracks: for n, track in tqdm(enumerate(tracks, start=1), unit_scale=True, unit='Song', total=len(tracks)):
download_track(track['id'], artist + " - " + album_name + "/") download_track(track['id'], f'{artist}/{album_name}', prefix=True, prefix_value=str(n), disable_progressbar=True)
print("\n")
def download_artist_albums(artist): def download_artist_albums(artist):
""" Downloads albums of an artist """ """ Downloads albums of an artist """
@ -727,7 +729,7 @@ def download_from_user_playlist():
download_playlist(playlists, playlist_choices[0]) download_playlist(playlists, playlist_choices[0])
else: else:
start = int(playlist_choices[0]) start = int(playlist_choices[0])
end = int(playlist_choices[1])+1 end = int(playlist_choices[1]) + 1
print(f"Downloading from {start} to {end}...") print(f"Downloading from {start} to {end}...")