1
mirror of https://github.com/Footsiefat/zspotify synced 2021-12-21 22:06:14 +01:00

added progress bar for download

we can set the chunk size using constnat `CHUNK_SIZE` default value 50000 bytes
This commit is contained in:
Raju komati 2021-10-22 08:04:20 +05:30
parent aeec7c8fc4
commit 67183a8b62
2 changed files with 13 additions and 5 deletions

View File

@ -2,3 +2,4 @@ git+https://github.com/kokarare1212/librespot-python
music_tag
pydub
Pillow
tqdm

View File

@ -20,6 +20,7 @@ from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
from librespot.core import Session
from librespot.metadata import TrackId, EpisodeId
from pydub import AudioSegment
from tqdm import tqdm
SESSION: Session = None
sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
@ -40,7 +41,7 @@ FORCE_PREMIUM = False # set to True if not detecting your premium account autom
ANTI_BAN_WAIT_TIME = 1
# Set this to True to not wait at all between tracks and just go balls to the wall
OVERRIDE_AUTO_WAIT = False
CHUNK_SIZE = 50000
# miscellaneous functions for general use
def clear():
@ -590,10 +591,16 @@ def download_track(track_id_str: str, extra_paths=""):
if not os.path.isdir(ROOT_PATH + extra_paths):
os.makedirs(ROOT_PATH + extra_paths)
with open(filename, 'wb') as file:
# Try's to download the entire track at once now to be more efficient.
byte = stream.input_stream.stream().read(-1)
file.write(byte)
total_size = stream.input_stream.size
with open(filename, 'wb') as file, tqdm(
desc=song_name,
total=total_size,
unit='B',
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)))
if not RAW_AUDIO_AS_IS:
convert_audio_format(filename)