Skip to content

Instantly share code, notes, and snippets.

@theappleman
Last active December 30, 2023 05:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theappleman/d10eff1ee9c9ea79ed3941a651b8607a to your computer and use it in GitHub Desktop.
Save theappleman/d10eff1ee9c9ea79ed3941a651b8607a to your computer and use it in GitHub Desktop.
Humble Bundle/Store torrent downloader
#!/bin/bash
find "$1" -iname "*.pdf.torrent" -type f | while read torrent; do
echo -e "$torrent\n dir=.download/$(dirname $torrent)"
done | aria2c --seed-time=1 --input-file -
#!/bin/bash
find . -iname "*$1.torrent" -type f | while read torrent; do
echo -e "$torrent\n dir=.download/$(dirname $torrent)"
done | aria2c --seed-time=1 --input-file -
#!/usr/bin/env python
import os
import sys
import json
import requests as r
from pprint import pprint as pp
with open(os.path.expanduser("~/.humble.py"), "r") as cookie_file:
for line in cookie_file:
if line != "":
cookie = line[:-1]
headers = {
"Cookie": cookie,
}
library_html = r.get("https://www.humblebundle.com/home/library", headers=headers).text
keys = None
for line in library_html.split("\n"):
if "is_logged_in" in line:
#print("gamekeys: {}".format(line))
try:
account = json.loads(line)
keys = account['gamekeys']
break
except json.decoder.JSONDecodeError:
pass
#bad = set(['"','[',']',';',','])
#keys = filter(lambda x: x not in bad, line).split(" ")[6:]
#print("got gamekeys: {}".format(keys))
orders = []
oa = orders.append
if keys is not None:
for key in keys:
oa(
r.get("https://www.humblebundle.com/api/v1/order/{}?all_tpkds=true".format(key),
headers=headers).json()
)
def savef(fname, data):
if isinstance(data, bytes):
mode = 'wb'
elif isinstance(data, str):
mode = 'w'
with open(fname, mode) as save_file:
save_file.write(data)
if orders is not None and orders:
for o in orders:
p = o['product']
#print(p['machine_name'])
try:
os.makedirs(p['category'])
except OSError:
pass
try:
os.makedirs(os.path.join(p['category'], p['machine_name']))
except OSError:
pass
if 'tpkd_dict' in o and 'all_tpks' in o['tpkd_dict']:
for tpk in o['tpkd_dict']['all_tpks']:
if 'redeemed_key_val' in tpk and 'machine_name' in tpk:
keyfile = "{}/{}/{}.{}.txt".format(p['category'], p['machine_name'], tpk['machine_name'], tpk['key_type'])
try:
with open(keyfile) as kn:
pass
except IOError:
print(keyfile)
savef(keyfile, tpk['redeemed_key_val'])
for s in o['subproducts']:
try:
os.makedirs(os.path.join(p['category'], p['machine_name'], s['machine_name']))
except OSError:
pass
for d in s['downloads']:
try:
os.makedirs(os.path.join(p['category'], p['machine_name'], s['machine_name'], d['machine_name']))
except OSError:
pass
for ds in d['download_struct']:
if 'url' in ds and 'bittorrent' in ds['url']:
fname = "{}/{}/{}/{}/{}".format(
p['category'],
p['machine_name'],
s['machine_name'],
d['machine_name'],
os.path.basename(
ds['url']['bittorrent'].split("?")[0]
)
)
try:
with open(fname) as fdata:
pass
except IOError:
print(fname)
savef(fname, r.get(ds['url']['bittorrent']).content)
elif False and 'url' in ds and 'web' in ds['url']:
fname = "{}/{}/{}/{}/{}".format(
p['category'],
p['machine_name'],
s['machine_name'],
d['machine_name'],
os.path.basename(
ds['url']['web'].split("?")[0]
)
)
savef(fname, r.get(ds['url']['web']).content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment