Last active 1440821890

Revision 25d7983e5053815c8e26ccfdae19404539a0e6e5

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 # https://pypi.python.org/pypi/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 f.write("{} *{}\n".format(info.md5, info.url.web.split("/")[-1].split("?")[0]))
31 if torrent and not info.url.bittorrent:
32 print("*** Url is not a torrent url: " + info.url.web, file=stderr)
33 print(info.url.bittorrent if torrent and info.url.bittorrent else info.url.web)
34
35if __name__ == "__main__":
36 retcode = main()
37 if retcode in ERRORS:
38 print(ERRORS[retcode], file=stderr)
39 exit(retcode)