Skip to content

Instantly share code, notes, and snippets.

@17183248569
Created November 3, 2020 02:09
Show Gist options
  • Save 17183248569/74de919e4d92accc9577f072f163fde1 to your computer and use it in GitHub Desktop.
Save 17183248569/74de919e4d92accc9577f072f163fde1 to your computer and use it in GitHub Desktop.
import requests,math
import syntax_sugar
def down(url,cp=40):
ls=int((requests.get(url,headers={"range":"bytes=0-0"}).headers["Content-Range"]).split("/")[1])
lp=math.ceil(ls/cp)
print(len(range(0,ls,lp)))
parts=[[i,i+lp-1] for i in range(0,ls,lp)]
parts[-1][-1]=""
def try_down(se):
while 1:
try:
return requests.get(url,headers={"range":f"bytes={se[0]}-{se[1]}"}).content
except Exception:
pass
return (syntax_sugar.pipe(parts)|[try_down]*cp|b"".join|syntax_sugar.END)
with open("out","wb") as f:
f.write(down(input()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment