Do not rely on reported file size when downloading stream (fixes #14)

This commit is contained in:
Frank de Lange 2022-07-20 15:33:32 +00:00
parent 50b545c8f8
commit baccdad43c
4 changed files with 5 additions and 3 deletions

Binary file not shown.

BIN
dist/spodcast-0.5.2.tar.gz vendored Normal file

Binary file not shown.

View file

@ -1,6 +1,6 @@
[metadata]
name = spodcast
version = 0.5.1
version = 0.5.2
description = A caching Spotify podcast to RSS proxy.
long_description = file:README.md
long_description_content_type = text/markdown

View file

@ -122,8 +122,10 @@ def download_stream(stream, filepath):
time_start = time.time()
downloaded = 0
with open(filepath, 'wb') as file:
for _ in range(int(size / Spodcast.CONFIG.get_chunk_size()) + 1):
data = stream.input_stream.stream().read(Spodcast.CONFIG.get_chunk_size())
data = b""
while data := stream.input_stream.stream().read(Spodcast.CONFIG.get_chunk_size()):
if data == b"":
break
file.write(data)
downloaded += len(data)
if Spodcast.CONFIG.get_download_real_time():