feed: always downloads with resume

what if the server doesn't support range? we don't support it!
This commit is contained in:
boyska 2020-11-12 01:07:31 +01:00
parent a0b6d77927
commit eb5b04393b

14
feed
View file

@ -396,6 +396,18 @@ def get_parser():
return p
def downloader(url, dest):
headers = {}
if os.path.exists(dest):
headers["Range"] = "bytes=%d-" % os.stat(dest).st_size
r = requests.get(url, stream=True, headers=headers)
if r.status_code == 416: # range not satisfiable
return
with open(dest, "ab") as f:
for chunk in r.iter_content(chunk_size=2 << 15):
f.write(chunk)
def put(audio, copy=False):
if not copy:
for url in audio.urls:
@ -411,7 +423,7 @@ def put(audio, copy=False):
).rstrip()
dest = os.path.join(destdir, fname)
os.makedirs(destdir, exist_ok=True)
fname, headers = urllib.request.urlretrieve(url, dest)
downloader(url, dest)
print("file://%s" % os.path.realpath(fname))
else:
# FIXME: file:// urls are just copied