From bf45889e6ae2a9291241d28bf1e118d7ffd7295b Mon Sep 17 00:00:00 2001 From: KDalu <71458929+KDalu@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:32:29 -0500 Subject: [PATCH] Cleaned up download real time feature implementation. --- zotify/playable.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zotify/playable.py b/zotify/playable.py index 425baa3..083ba3d 100644 --- a/zotify/playable.py +++ b/zotify/playable.py @@ -215,6 +215,8 @@ class Track(PlayableContentFeeder.LoadedStream, Playable): """ if not isinstance(output, Path): output = Path(output).expanduser() + if not real_time: + return super().write_audio_stream(output) file = f"{output}.ogg" time_start = time() downloaded = 0 @@ -223,12 +225,11 @@ class Track(PlayableContentFeeder.LoadedStream, Playable): while chunk != b"": chunk = self.input_stream.stream().read(1024) p_bar.update(f.write(chunk)) - if real_time: - downloaded += len(chunk) - delta_current = time() - time_start - delta_required = (downloaded / self.input_stream.size) * (self.duration/1000) - if delta_required > delta_current: - sleep(delta_required - delta_current) + downloaded += len(chunk) + delta_current = time() - time_start + delta_required = (downloaded / self.input_stream.size) * (self.duration/1000) + if delta_required > delta_current: + sleep(delta_required - delta_current) return LocalFile(Path(file), AudioFormat.VORBIS)