Skip to content

Instantly share code, notes, and snippets.

@vehrka
Created August 12, 2018 21:38
Show Gist options
  • Save vehrka/38ff1b20cb59c1a1f1c6a38d4ed5bd42 to your computer and use it in GitHub Desktop.
Save vehrka/38ff1b20cb59c1a1f1c6a38d4ed5bd42 to your computer and use it in GitHub Desktop.
# coding: utf-8
import requests
import json
import os
base_url = 'https://www.humblebundle.com/api/v1/order/{download_key}'
# Get this one from the bundle page url
download_key = ''
# Get this one inspecting the headers of the bundle page
cookie_auth = {'_simpleauth_sess': ''}
url = base_url.format(download_key=download_key)
os.makedirs(download_key, exist_ok=False)
r = requests.get(url, cookies=cookie_auth)
data = json.loads(r.text)
subproducts = [sub for sub in data['subproducts'] if len(sub['downloads']) > 0]
for subp in subproducts:
for book in subp['downloads']:
book_name = book['machine_name']
print(book_name)
for struct in book['download_struct']:
try:
url_down = struct['url']['web']
file_name = url_down.split('?')[0].split('/')[-1]
comp_file_name = os.path.join(download_key, file_name)
r_pdf = requests.get(url_down, stream=True)
handle = open(comp_file_name, 'wb')
for chunk in r_pdf.iter_content(chunk_size=512):
if chunk: # filter out keep-alive new chunks
handle.write(chunk)
except KeyError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment