Created
January 3, 2018 13:21
-
-
Save tkjaer/693e4d4fdf9ef98c7f4dfe87450c620f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# get "gamekey" (bundle id) from: | |
# - https://www.humblebundle.com/api/v1/user/order | |
# | |
# then get the json file containing the bundle details from: | |
# - https://www.humblebundle.com/api/v1/order/$gamekey | |
# | |
# Save that file as 'books.json' and run: | |
# $ python3 humble_download.py books.json | |
import json | |
import re | |
import os | |
import requests | |
with open("books.json", "r") as books: | |
book_data = json.load(books) | |
# Iterate over the individual books | |
for book in book_data['subproducts']: | |
# Iterate over the books different file types | |
for download in book['downloads']: | |
book_name = book['human_name'] | |
# Create a directory to contain the file types | |
if not os.path.exists(book_name): | |
os.makedirs(book_name) | |
# Download each individual file | |
for file_type in download['download_struct']: | |
f_url = file_type['url']['web'] | |
f_name = re.match('^https://dl.humble.com/(.*)\?.*$', f_url).group(1) | |
r = requests.get(f_url, stream=True) | |
with open(book_name + '/' + f_name, 'wb') as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
# Print a status message | |
print("Done downloading {}/{}".format(book_name, f_name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the banana approves