diff --git a/feed b/feed index c96ebc1..25e473d 100755 --- a/feed +++ b/feed @@ -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