comparison kemonopartydownloader.py @ 53:ae64a0c8831b

Update kemonopartydownloader.py committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Sat, 31 Jul 2021 03:11:58 -0400
parents 6eb6c657c7eb
children 5a5d47a795c6
comparison
equal deleted inserted replaced
52:3857b2919db0 53:ae64a0c8831b
17 if os.path.exists(filename): 17 if os.path.exists(filename):
18 filesize = os.stat(filename).st_size 18 filesize = os.stat(filename).st_size
19 else: 19 else:
20 filesize = 0 20 filesize = 0
21 if str(filesize) != req.head(f"https://data.kemono.party{x['path']}").headers["Content-Length"]: 21 if str(filesize) != req.head(f"https://data.kemono.party{x['path']}").headers["Content-Length"]:
22 print("unfinished download")
23 with req.get(f"https://data.kemono.party{x['path']}", stream=True, headers={"Range": f"bytes={filesize}-"}) as r: 22 with req.get(f"https://data.kemono.party{x['path']}", stream=True, headers={"Range": f"bytes={filesize}-"}) as r:
24 r.raise_for_status() 23 r.raise_for_status()
25 with open(filename, "ab") as f: 24 with open(filename, "ab") as f:
26 for chunk in r.iter_content(chunk_size=4096): 25 for chunk in r.iter_content(chunk_size=4096):
27 f.write(chunk) 26 f.write(chunk)
40 args = parser.parse_args() 39 args = parser.parse_args()
41 40
42 req = requests.Session() 41 req = requests.Session()
43 42
44 if args.proxy: 43 if args.proxy:
44 req.proxies = {}
45 if args.proxy[:6] == "socks5": 45 if args.proxy[:6] == "socks5":
46 httpproxy = args.proxy 46 httpproxy = args.proxy
47 httpsproxy = args.proxy 47 httpsproxy = args.proxy
48 elif args.proxy[0:5] == "https": 48 elif args.proxy[:5] == "https":
49 httpsproxy = args.proxy 49 httpsproxy = args.proxy
50 elif args.proxy[0:4] == "http": 50 elif args.proxy[:4] == "http":
51 httpproxy = args.proxy 51 httpproxy = args.proxy
52 else: 52 else:
53 print("unknown proxy format! defaulting to HTTP...") 53 print("unknown proxy format! defaulting to HTTP...")
54 httpproxy = args.proxy 54 httpproxy = args.proxy
55 if httpproxy: 55 if httpproxy:
56 req.proxies = { 56 req.proxies["http"] = httpproxy
57 "http": httpproxy,
58 }
59 if httpsproxy: 57 if httpsproxy:
60 req.proxies["https"] = httpsproxy 58 req.proxies["https"] = httpsproxy
61 59
62 cj = http.cookiejar.MozillaCookieJar(args.cookies) 60 cj = http.cookiejar.MozillaCookieJar(args.cookies)
63 cj.load(ignore_expires=True) 61 cj.load(ignore_expires=True)