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