mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-29 19:24:34 +01:00
Added progress bar to podcats and simplified output
This commit is contained in:
parent
bb2b9880ed
commit
61f55449ad
38
zspotify.py
38
zspotify.py
@ -44,6 +44,8 @@ OVERRIDE_AUTO_WAIT = False
|
|||||||
CHUNK_SIZE = 50000
|
CHUNK_SIZE = 50000
|
||||||
|
|
||||||
# miscellaneous functions for general use
|
# miscellaneous functions for general use
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
""" Clear the console window """
|
""" Clear the console window """
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
@ -70,7 +72,7 @@ def sanitize_data(value):
|
|||||||
def splash():
|
def splash():
|
||||||
""" Displays splash screen """
|
""" Displays splash screen """
|
||||||
print("=================================\n"
|
print("=================================\n"
|
||||||
"| Spotify Downloader |\n"
|
"| ZSpotify |\n"
|
||||||
"| |\n"
|
"| |\n"
|
||||||
"| by Footsiefat/Deathmonger |\n"
|
"| by Footsiefat/Deathmonger |\n"
|
||||||
"=================================\n\n\n")
|
"=================================\n\n\n")
|
||||||
@ -167,7 +169,7 @@ def client():
|
|||||||
download_episode(episode)
|
download_episode(episode)
|
||||||
else:
|
else:
|
||||||
search(search_text)
|
search(search_text)
|
||||||
wait()
|
# wait()
|
||||||
|
|
||||||
|
|
||||||
def regex_input_for_urls(search_input):
|
def regex_input_for_urls(search_input):
|
||||||
@ -278,7 +280,7 @@ def download_episode(episode_id_str):
|
|||||||
if podcast_name is None:
|
if podcast_name is None:
|
||||||
print("### SKIPPING: (EPISODE NOT FOUND) ###")
|
print("### SKIPPING: (EPISODE NOT FOUND) ###")
|
||||||
else:
|
else:
|
||||||
filename = podcast_name + " - " + episode_name + ".wav"
|
filename = podcast_name + " - " + episode_name
|
||||||
|
|
||||||
episode_id = EpisodeId.from_base62(episode_id_str)
|
episode_id = EpisodeId.from_base62(episode_id_str)
|
||||||
stream = SESSION.content_feeder().load(
|
stream = SESSION.content_feeder().load(
|
||||||
@ -289,12 +291,17 @@ def download_episode(episode_id_str):
|
|||||||
if not os.path.isdir(ROOT_PODCAST_PATH + extra_paths):
|
if not os.path.isdir(ROOT_PODCAST_PATH + extra_paths):
|
||||||
os.makedirs(ROOT_PODCAST_PATH + extra_paths)
|
os.makedirs(ROOT_PODCAST_PATH + extra_paths)
|
||||||
|
|
||||||
with open(ROOT_PODCAST_PATH + extra_paths + filename, 'wb') as file:
|
total_size = stream.input_stream.size
|
||||||
while True:
|
with open(ROOT_PODCAST_PATH + extra_paths + filename + ".wav", 'wb') as file, tqdm(
|
||||||
byte = stream.input_stream.stream().read(1024 * 1024)
|
desc=filename,
|
||||||
if byte == b'':
|
total=total_size,
|
||||||
break
|
unit='B',
|
||||||
file.write(byte)
|
unit_scale=True,
|
||||||
|
unit_divisor=1024
|
||||||
|
) as bar:
|
||||||
|
for _ in range(int(total_size / CHUNK_SIZE) + 1):
|
||||||
|
bar.update(file.write(
|
||||||
|
stream.input_stream.stream().read(CHUNK_SIZE)))
|
||||||
|
|
||||||
# related functions that do stuff with the spotify API
|
# related functions that do stuff with the spotify API
|
||||||
|
|
||||||
@ -416,7 +423,7 @@ def check_premium():
|
|||||||
def convert_audio_format(filename):
|
def convert_audio_format(filename):
|
||||||
""" Converts raw audio into playable mp3 or ogg vorbis """
|
""" Converts raw audio into playable mp3 or ogg vorbis """
|
||||||
global MUSIC_FORMAT
|
global MUSIC_FORMAT
|
||||||
print("### CONVERTING TO " + MUSIC_FORMAT.upper() + " ###")
|
# print("### CONVERTING TO " + MUSIC_FORMAT.upper() + " ###")
|
||||||
raw_audio = AudioSegment.from_file(filename, format="ogg",
|
raw_audio = AudioSegment.from_file(filename, format="ogg",
|
||||||
frame_rate=44100, channels=2, sample_width=2)
|
frame_rate=44100, channels=2, sample_width=2)
|
||||||
if QUALITY == AudioQuality.VERY_HIGH:
|
if QUALITY == AudioQuality.VERY_HIGH:
|
||||||
@ -428,7 +435,7 @@ def convert_audio_format(filename):
|
|||||||
|
|
||||||
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):
|
||||||
""" sets music_tag metadata """
|
""" sets music_tag metadata """
|
||||||
print("### SETTING MUSIC TAGS ###")
|
# print("### SETTING MUSIC TAGS ###")
|
||||||
tags = music_tag.load_file(filename)
|
tags = music_tag.load_file(filename)
|
||||||
tags['artist'] = conv_artist_format(artists)
|
tags['artist'] = conv_artist_format(artists)
|
||||||
tags['tracktitle'] = name
|
tags['tracktitle'] = name
|
||||||
@ -441,7 +448,7 @@ def set_audio_tags(filename, artists, name, album_name, release_year, disc_numbe
|
|||||||
|
|
||||||
def set_music_thumbnail(filename, image_url):
|
def set_music_thumbnail(filename, image_url):
|
||||||
""" Downloads cover artwork """
|
""" Downloads cover artwork """
|
||||||
print("### SETTING THUMBNAIL ###")
|
# print("### SETTING THUMBNAIL ###")
|
||||||
img = requests.get(image_url).content
|
img = requests.get(image_url).content
|
||||||
tags = music_tag.load_file(filename)
|
tags = music_tag.load_file(filename)
|
||||||
tags['artwork'] = img
|
tags['artwork'] = img
|
||||||
@ -582,11 +589,11 @@ def download_track(track_id_str: str, extra_paths=""):
|
|||||||
track_id_str = scraped_song_id
|
track_id_str = scraped_song_id
|
||||||
|
|
||||||
track_id = TrackId.from_base62(track_id_str)
|
track_id = TrackId.from_base62(track_id_str)
|
||||||
print("### FOUND SONG:", song_name, " ###")
|
# print("### FOUND SONG:", song_name, " ###")
|
||||||
|
|
||||||
stream = SESSION.content_feeder().load(
|
stream = SESSION.content_feeder().load(
|
||||||
track_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
track_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
||||||
print("### DOWNLOADING RAW AUDIO ###")
|
# print("### DOWNLOADING RAW AUDIO ###")
|
||||||
|
|
||||||
if not os.path.isdir(ROOT_PATH + extra_paths):
|
if not os.path.isdir(ROOT_PATH + extra_paths):
|
||||||
os.makedirs(ROOT_PATH + extra_paths)
|
os.makedirs(ROOT_PATH + extra_paths)
|
||||||
@ -600,7 +607,8 @@ def download_track(track_id_str: str, extra_paths=""):
|
|||||||
unit_divisor=1024
|
unit_divisor=1024
|
||||||
) 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(stream.input_stream.stream().read(CHUNK_SIZE)))
|
bar.update(file.write(
|
||||||
|
stream.input_stream.stream().read(CHUNK_SIZE)))
|
||||||
|
|
||||||
if not RAW_AUDIO_AS_IS:
|
if not RAW_AUDIO_AS_IS:
|
||||||
convert_audio_format(filename)
|
convert_audio_format(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user