mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2025-07-01 15:23:15 +00:00
Support subfolders for each disc.
Must be enabled manually in zs_config.json
This commit is contained in:
parent
e75ea14faa
commit
8770de741d
@ -7,5 +7,6 @@
|
|||||||
"FORCE_PREMIUM": false,
|
"FORCE_PREMIUM": false,
|
||||||
"ANTI_BAN_WAIT_TIME": 1,
|
"ANTI_BAN_WAIT_TIME": 1,
|
||||||
"OVERRIDE_AUTO_WAIT": false,
|
"OVERRIDE_AUTO_WAIT": false,
|
||||||
"CHUNK_SIZE": 50000
|
"CHUNK_SIZE": 50000,
|
||||||
|
"SPLIT_ALBUM_DISCS": false
|
||||||
}
|
}
|
107
zspotify.py
107
zspotify.py
@ -118,20 +118,46 @@ def client():
|
|||||||
print("[ DETECTED FREE ACCOUNT - USING HIGH QUALITY ]\n\n")
|
print("[ DETECTED FREE ACCOUNT - USING HIGH QUALITY ]\n\n")
|
||||||
QUALITY = AudioQuality.HIGH
|
QUALITY = AudioQuality.HIGH
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
while True:
|
||||||
if sys.argv[1] == "-p" or sys.argv[1] == "--playlist":
|
if len(sys.argv) > 1:
|
||||||
download_from_user_playlist()
|
if sys.argv[1] == "-p" or sys.argv[1] == "--playlist":
|
||||||
elif sys.argv[1] == "-ls" or sys.argv[1] == "--liked-songs":
|
download_from_user_playlist()
|
||||||
for song in get_saved_tracks(token):
|
elif sys.argv[1] == "-ls" or sys.argv[1] == "--liked-songs":
|
||||||
if not song['track']['name']:
|
for song in get_saved_tracks(token):
|
||||||
print(
|
if not song['track']['name']:
|
||||||
"### SKIPPING: SONG DOES NOT EXISTS ON SPOTIFY ANYMORE ###")
|
print(
|
||||||
else:
|
"### SKIPPING: SONG DOES NOT EXISTS ON SPOTIFY ANYMORE ###")
|
||||||
download_track(song['track']['id'], "Liked Songs/")
|
else:
|
||||||
print("\n")
|
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, artist_id_str = regex_input_for_urls(
|
||||||
|
sys.argv[1])
|
||||||
|
|
||||||
|
if track_id_str is not None:
|
||||||
|
download_track(track_id_str)
|
||||||
|
elif artist_id_str is not None:
|
||||||
|
download_artist_albums(artist_id_str)
|
||||||
|
elif album_id_str is not None:
|
||||||
|
download_album(album_id_str)
|
||||||
|
elif playlist_id_str is not None:
|
||||||
|
playlist_songs = get_playlist_songs(token, playlist_id_str)
|
||||||
|
name, creator = get_playlist_info(token, playlist_id_str)
|
||||||
|
for song in playlist_songs:
|
||||||
|
download_track(song['track']['id'],
|
||||||
|
sanitize_data(name) + "/")
|
||||||
|
print("\n")
|
||||||
|
elif episode_id_str is not None:
|
||||||
|
download_episode(episode_id_str)
|
||||||
|
elif show_id_str is not None:
|
||||||
|
for episode in get_show_episodes(token, show_id_str):
|
||||||
|
download_episode(episode)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
search_text = input("Enter search or URL: ")
|
||||||
|
|
||||||
track_id_str, album_id_str, playlist_id_str, episode_id_str, show_id_str, artist_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])
|
search_text)
|
||||||
|
|
||||||
if track_id_str is not None:
|
if track_id_str is not None:
|
||||||
download_track(track_id_str)
|
download_track(track_id_str)
|
||||||
@ -151,34 +177,9 @@ def client():
|
|||||||
elif show_id_str is not None:
|
elif show_id_str is not None:
|
||||||
for episode in get_show_episodes(token, show_id_str):
|
for episode in get_show_episodes(token, show_id_str):
|
||||||
download_episode(episode)
|
download_episode(episode)
|
||||||
|
else:
|
||||||
else:
|
search(search_text)
|
||||||
search_text = input("Enter search or URL: ")
|
# wait()
|
||||||
|
|
||||||
track_id_str, album_id_str, playlist_id_str, episode_id_str, show_id_str, artist_id_str = regex_input_for_urls(
|
|
||||||
search_text)
|
|
||||||
|
|
||||||
if track_id_str is not None:
|
|
||||||
download_track(track_id_str)
|
|
||||||
elif artist_id_str is not None:
|
|
||||||
download_artist_albums(artist_id_str)
|
|
||||||
elif album_id_str is not None:
|
|
||||||
download_album(album_id_str)
|
|
||||||
elif playlist_id_str is not None:
|
|
||||||
playlist_songs = get_playlist_songs(token, playlist_id_str)
|
|
||||||
name, creator = get_playlist_info(token, playlist_id_str)
|
|
||||||
for song in playlist_songs:
|
|
||||||
download_track(song['track']['id'],
|
|
||||||
sanitize_data(name) + "/")
|
|
||||||
print("\n")
|
|
||||||
elif episode_id_str is not None:
|
|
||||||
download_episode(episode_id_str)
|
|
||||||
elif show_id_str is not None:
|
|
||||||
for episode in get_show_episodes(token, show_id_str):
|
|
||||||
download_episode(episode)
|
|
||||||
else:
|
|
||||||
search(search_text)
|
|
||||||
# wait()
|
|
||||||
|
|
||||||
|
|
||||||
def regex_input_for_urls(search_input):
|
def regex_input_for_urls(search_input):
|
||||||
@ -310,7 +311,8 @@ def download_episode(episode_id_str):
|
|||||||
# print("### DOWNLOADING '" + podcast_name + " - " +
|
# print("### DOWNLOADING '" + podcast_name + " - " +
|
||||||
# episode_name + "' - THIS MAY TAKE A WHILE ###")
|
# episode_name + "' - THIS MAY TAKE A WHILE ###")
|
||||||
|
|
||||||
os.makedirs(ZS_CONFIG["ROOT_PODCAST_PATH"] + extra_paths, exist_ok=True)
|
os.makedirs(ZS_CONFIG["ROOT_PODCAST_PATH"] +
|
||||||
|
extra_paths, exist_ok=True)
|
||||||
|
|
||||||
total_size = stream.input_stream.size
|
total_size = stream.input_stream.size
|
||||||
with open(ZS_CONFIG["ROOT_PODCAST_PATH"] + extra_paths + filename + ".wav", 'wb') as file, tqdm(
|
with open(ZS_CONFIG["ROOT_PODCAST_PATH"] + extra_paths + filename + ".wav", 'wb') as file, tqdm(
|
||||||
@ -455,7 +457,8 @@ def convert_audio_format(filename):
|
|||||||
bitrate = "320k"
|
bitrate = "320k"
|
||||||
else:
|
else:
|
||||||
bitrate = "160k"
|
bitrate = "160k"
|
||||||
raw_audio.export(filename, format=ZS_CONFIG["MUSIC_FORMAT"], bitrate=bitrate)
|
raw_audio.export(
|
||||||
|
filename, format=ZS_CONFIG["MUSIC_FORMAT"], bitrate=bitrate)
|
||||||
|
|
||||||
|
|
||||||
def set_audio_tags(filename, artists, name, album_name, release_year, disc_number, track_number):
|
def set_audio_tags(filename, artists, name, album_name, release_year, disc_number, track_number):
|
||||||
@ -608,10 +611,15 @@ def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value
|
|||||||
|
|
||||||
song_name = artists[0] + " - " + name
|
song_name = artists[0] + " - " + name
|
||||||
if prefix:
|
if prefix:
|
||||||
song_name = f'{prefix_value.zfill(2)}-{song_name}' if prefix_value.isdigit(
|
song_name = f'{prefix_value.zfill(2)} - {song_name}' if prefix_value.isdigit(
|
||||||
) else f'{prefix_value}-{song_name}'
|
) else f'{prefix_value} - {song_name}'
|
||||||
filename = os.path.join(ZS_CONFIG["ROOT_PATH"], extra_paths,
|
|
||||||
song_name + '.' + ZS_CONFIG["MUSIC_FORMAT"])
|
if ZS_CONFIG["SPLIT_ALBUM_DISCS"]:
|
||||||
|
filename = os.path.join(ZS_CONFIG["ROOT_PATH"], extra_paths, "Disc " + str(
|
||||||
|
disc_number) + '/' + song_name + '.' + ZS_CONFIG["MUSIC_FORMAT"])
|
||||||
|
else:
|
||||||
|
filename = os.path.join(ZS_CONFIG["ROOT_PATH"], extra_paths,
|
||||||
|
song_name + '.' + ZS_CONFIG["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)
|
||||||
@ -635,7 +643,12 @@ def download_track(track_id_str: str, extra_paths="", prefix=False, prefix_value
|
|||||||
track_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
track_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
||||||
# print("### DOWNLOADING RAW AUDIO ###")
|
# print("### DOWNLOADING RAW AUDIO ###")
|
||||||
|
|
||||||
os.makedirs(ZS_CONFIG["ROOT_PATH"] + extra_paths, exist_ok=True)
|
if ZS_CONFIG["SPLIT_ALBUM_DISCS"]:
|
||||||
|
os.makedirs(
|
||||||
|
ZS_CONFIG["ROOT_PATH"] + extra_paths + "/Disc " + str(disc_number) + '/', exist_ok=True)
|
||||||
|
else:
|
||||||
|
os.makedirs(ZS_CONFIG["ROOT_PATH"] +
|
||||||
|
extra_paths, exist_ok=True)
|
||||||
|
|
||||||
total_size = stream.input_stream.size
|
total_size = stream.input_stream.size
|
||||||
with open(filename, 'wb') as file, tqdm(
|
with open(filename, 'wb') as file, tqdm(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user