From a87017fd3d91535309fc27c63c147af86657a425 Mon Sep 17 00:00:00 2001 From: Martin Schubinski Date: Wed, 14 Dec 2022 17:44:43 +0100 Subject: [PATCH] fix abort of stream read to avoid to short tracks --- zspotify/podcast.py | 4 +++- zspotify/track.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/zspotify/podcast.py b/zspotify/podcast.py index 7b692f39..c75a0f99 100644 --- a/zspotify/podcast.py +++ b/zspotify/podcast.py @@ -118,8 +118,10 @@ def download_episode(episode_id) -> None: unit_divisor=1024 ) as p_bar: prepare_download_loader.stop() - for _ in range(int(total_size / ZSpotify.CONFIG.get_chunk_size()) + 1): + last_read = 1 + while(downloaded < total_size and last_read): data = stream.input_stream.stream().read(ZSpotify.CONFIG.get_chunk_size()) + last_read = len(data) p_bar.update(file.write(data)) downloaded += len(data) if ZSpotify.CONFIG.get_download_real_time(): diff --git a/zspotify/track.py b/zspotify/track.py index e4f4b47c..799b5c6a 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -199,8 +199,10 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba unit_divisor=1024, disable=disable_progressbar ) as p_bar: - for _ in range(int(total_size / ZSpotify.CONFIG.get_chunk_size()) + 1): + last_read = 1 + while(downloaded < total_size and last_read): data = stream.input_stream.stream().read(ZSpotify.CONFIG.get_chunk_size()) + last_read = len(data) p_bar.update(file.write(data)) downloaded += len(data) if ZSpotify.CONFIG.get_download_real_time():