Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active January 1, 2024 04:28
Show Gist options
  • Save blha303/a455de4451d42b77aedb6320bea8ad9a to your computer and use it in GitHub Desktop.
Save blha303/a455de4451d42b77aedb6320bea8ad9a to your computer and use it in GitHub Desktop.
Humble Bundle: save all torrents
# pypi:humblebundle has to deal with captchas. I can't be bothered.
import requests
import json
import subprocess
keys = [k["gamekey"] for k in json.loads(""" #paste contents of https://www.humblebundle.com/api/v1/user/order here
""")
# Open your browser's Network console while going to the above url, find the headers, paste them below
headers = {"Cookie": "", "User-Agent": ""}
# stackoverflow is the best
def execute(cmd):
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
def get(key):
return requests.get("https://www.humblebundle.com/api/v1/order/{}".format(key), headers=headers).json()
for k in keys:
resp = get(k)
if not resp["subproducts"]:
continue
for sp in resp["subproducts"]:
for dl in sp["downloads"]:
if dl.get("download_struct", []) and dl["download_struct"][0].get("url", {}).get("bittorrent", ""):
try:
for line in execute(["mkdir", dl["platform"]]):
pass
url = dl["download_struct"][0]["url"]["bittorrent"]
for line in execute(["wget", url, "-O", "{}/{}".format(dl["platform"], url.split("/")[-1].split("?")[0])]):
print(line, end="")
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment