From 7546e76865baa0a3601c782b9adba6dc3964fb4e Mon Sep 17 00:00:00 2001 From: Footsiefat <12180913+Footsiefat@users.noreply.github.com> Date: Tue, 19 Oct 2021 19:29:03 +1300 Subject: [PATCH] Made downloading more efficent --- zspotify.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/zspotify.py b/zspotify.py index b54a351f..19d96862 100644 --- a/zspotify.py +++ b/zspotify.py @@ -442,37 +442,13 @@ def download_track(track_id_str: str, extra_paths=""): os.makedirs(ROOT_PATH + extra_paths) with open(filename, 'wb') as file: - """ - chunk_size = 1024 * 16 - buffer = bytearray(chunk_size) - bpos = 0 - """ - - # With the updated version of librespot my faster download method broke so we are using the old fallback method while True: - byte = stream.input_stream.stream().read() + # Trys to read exactly 128kb at a time to be more efficient now + byte = stream.input_stream.stream().read(1024 * 128) + print(len(byte)) if byte == b'': break file.write(byte) - - """ - while True: - byte = stream.input_stream.stream().read() - - if byte == -1: - # flush buffer before breaking - if bpos > 0: - file.write(buffer[0:bpos]) - break - - print(bpos) - buffer[bpos] = byte - bpos += 1 - - if bpos == (chunk_size): - file.write(buffer) - bpos = 0 - """ try: convert_audio_format(filename) except: