Last active 1440821890

Revision be35b39b69cab00029137e1488a7884024a182bb

gethbdownloads.py Raw
1# Usage: gethbdownloads.py > filelist.txt
2# Then: wget --content-disposition --no-check-certificate -c -i filelist.txt
3# Defaults to returning torrent urls, easily configurable
4
5from __future__ import print_function
6from sys import stderr, exit
7from getpass import getpass
8import humblebundle
9
10ERRORS = {1: "Login failed, please check details"}
11
12def query(prompt=None, default=None):
13 if prompt:
14 stderr.write(str(prompt))
15 return raw_input() or default
16
17def main():
18 client = humblebundle.HumbleApi()
19 if not client.login(query("humblebundle.com email: "), getpass("humblebundle.com password: ", stderr)):
20 return 1
21 platform = query("Platform [windows]: ", "windows")
22 torrent = query("Bittorrent [true]: ", "true").lower()[0] in ['t', '1', 'y']
23 with open("HB-{}.md5".format(platform), "w") as f:
24 for order in [client.get_order(gamekey) for gamekey in client.get_gamekeys()]:
25 if order and order.subproducts:
26 for product in order.subproducts:
27 for dl in product.downloads:
28 if dl.platform == platform:
29 info = dl.download_struct[0]
30 if not info.url.web:
31 print("*** Url not found for {}: {}".format(info.machine_name, info.message), file=stderr)
32 continue
33 f.write("{} *{}\n".format(info.md5, info.url.web.split("/")[-1].split("?")[0]))
34 if torrent and not info.url.bittorrent:
35 print("*** Url is not a torrent url: " + info.url.web, file=stderr)
36 print(info.url.bittorrent if torrent and info.url.bittorrent else info.url.web)
37
38if __name__ == "__main__":
39 retcode = main()
40 if retcode in ERRORS:
41 print(ERRORS[retcode], file=stderr)
42 exit(retcode)
43