Last active 1670065447

Humble Bundle: save all torrents

hbget.py Raw
1# pypi:humblebundle has to deal with captchas. I can't be bothered.
2import requests
3import json
4import subprocess
5
6keys = [k["gamekey"] for k in json.loads(""" #paste contents of https://www.humblebundle.com/api/v1/user/order here
7""")
8
9# Open your browser's Network console while going to the above url, find the headers, paste them below
10headers = {"Cookie": "", "User-Agent": ""}
11
12# stackoverflow is the best
13def execute(cmd):
14 popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
15 for stdout_line in iter(popen.stdout.readline, ""):
16 yield stdout_line
17 popen.stdout.close()
18 return_code = popen.wait()
19 if return_code:
20 raise subprocess.CalledProcessError(return_code, cmd)
21
22def get(key):
23 return requests.get("https://www.humblebundle.com/api/v1/order/{}".format(key), headers=headers).json()
24
25for k in keys:
26 resp = get(k)
27 if not resp["subproducts"]:
28 continue
29 for sp in resp["subproducts"]:
30 for dl in sp["downloads"]:
31 if dl.get("download_struct", []) and dl["download_struct"][0].get("url", {}).get("bittorrent", ""):
32 try:
33 for line in execute(["mkdir", dl["platform"]]):
34 pass
35 url = dl["download_struct"][0]["url"]["bittorrent"]
36 for line in execute(["wget", url, "-O", "{}/{}".format(dl["platform"], url.split("/")[-1].split("?")[0])]):
37 print(line, end="")
38 except:
39 pass