feed: always downloads with resume
what if the server doesn't support range? we don't support it!
This commit is contained in:
parent
a0b6d77927
commit
eb5b04393b
1 changed files with 13 additions and 1 deletions
14
feed
14
feed
|
@ -396,6 +396,18 @@ def get_parser():
|
||||||
return p
|
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):
|
def put(audio, copy=False):
|
||||||
if not copy:
|
if not copy:
|
||||||
for url in audio.urls:
|
for url in audio.urls:
|
||||||
|
@ -411,7 +423,7 @@ def put(audio, copy=False):
|
||||||
).rstrip()
|
).rstrip()
|
||||||
dest = os.path.join(destdir, fname)
|
dest = os.path.join(destdir, fname)
|
||||||
os.makedirs(destdir, exist_ok=True)
|
os.makedirs(destdir, exist_ok=True)
|
||||||
fname, headers = urllib.request.urlretrieve(url, dest)
|
downloader(url, dest)
|
||||||
print("file://%s" % os.path.realpath(fname))
|
print("file://%s" % os.path.realpath(fname))
|
||||||
else:
|
else:
|
||||||
# FIXME: file:// urls are just copied
|
# FIXME: file:// urls are just copied
|
||||||
|
|
Loading…
Reference in a new issue