def display_summary():
        global start_time
        if start_time:
            elapsed = time.time() - start_time
            fasts = ProgressTracker.download_size_current / elapsed
            remaining = (ProgressTracker.download_size_total -
                         ProgressTracker.download_size_current) / fasts
        else:
            start_time = time.time()
            remaining = None
            fasts = 1024**2

        progress_message = "%d/%d DL: %s/%s (%s, %s)" % (
            ProgressTracker.item_count_current,
            ProgressTracker.item_count_total,
            ProgressTracker.format_filesize(
                ProgressTracker.download_size_current),
            ProgressTracker.format_filesize(
                ProgressTracker.download_size_total),
            ProgressTracker.format_percentage(
                ProgressTracker.download_size_current,
                ProgressTracker.download_size_total),
            ProgressTracker.format_seconds(
                remaining, ProgressTracker.download_size_total, fasts))

        logger.display_message(False, "Progress", progress_message)
        logger.display_message(
            True, "Progress",
            "%s: %s: %s" % (ProgressTracker.current_product,
                            ProgressTracker.current_subproduct,
                            ProgressTracker.current_download))
Example #2
0
    def display_summary():
        progress_message = "%d/%d DL: %s/%s (%s)" % (ProgressTracker.item_count_current,
            ProgressTracker.item_count_total,
            ProgressTracker.format_filesize(ProgressTracker.download_size_current),
            ProgressTracker.format_filesize(ProgressTracker.download_size_total),
            ProgressTracker.format_percentage(ProgressTracker.download_size_current,
                                              ProgressTracker.download_size_total))

        logger.display_message(False, "Progress", progress_message)
        logger.display_message(True, "Progress", "%s: %s: %s" % (ProgressTracker.current_product, ProgressTracker.current_subproduct, ProgressTracker.current_download))
Example #3
0
    def batch_download(hapi, game_keys):
        ProgressTracker.reset()
        ProgressTracker.item_count_total = len(game_keys)
        download_size_total = 0
        item_count_total = 0
        key_downloads = dict()
        # Create initial list of Humble Downloads.
        # Platforms that are turned off are filtered here, and the download
        # size is computed. Checksums are also calculated for finished
        # downloads. This initial query could be paralelized for speed gains
        for key in game_keys:
            ProgressTracker.item_count_current += 1
            logger.display_message(
                False, "Processing",
                "Retrieving order details for order %s (%d/%d)." %
                (key, ProgressTracker.item_count_current,
                 ProgressTracker.item_count_total))

            humble_downloads = HumbleDownload.needed_downloads_from_key(
                hapi, key)
            item_count_total += len(humble_downloads)
            download_size_total += sum(dl.humble_file_size
                                       for dl in humble_downloads)
            logger.display_message(
                False, "Processing", "Added %d downloads for order %s" %
                (len(humble_downloads), key))

            if len(humble_downloads) > 0:
                key_downloads[key] = humble_downloads

        ProgressTracker.reset()
        ProgressTracker.item_count_total = item_count_total
        ProgressTracker.download_size_total = download_size_total

        # Now, download the files after updating the url in case they expired
        for key in key_downloads:
            HumbleDownload.update_download_list_url(hapi,
                                                    key_downloads.get(key))
            for hd in key_downloads.get(key):
                ProgressTracker.assign_download(hd)
                ProgressTracker.display_summary()
                logger.display_message(False, "Download", hd.status_message)
                logger.display_message(
                    False, "Download",
                    "Downloading %s." % hd.humble_file_size_human)
                hd.download_file()

                if hd.humble_file_size is not None:
                    ProgressTracker.download_size_current += (
                        hd.humble_file_size)
                ProgressTracker.item_count_current += 1

        logger.display_message(False, "Processing", "Finished.")
    def dump_configuration():
        """
            Dumps the current configuration to the log when debug mode is
            activated
            :return: None
        """
        # Shortcut the process if debugging is not turned on.
        if not ConfigData.debug:
            return

        logger.display_message(True, "Config",
                               "write_md5=%s" % ConfigData.write_md5)
        logger.display_message(True, "Config",
                               "read_md5=%s" % ConfigData.read_md5)
        logger.display_message(True, "Config",
                               "force_md5=%s" % ConfigData.force_md5)
        logger.display_message(True, "Config",
                               "ignore_md5=%s" % ConfigData.ignore_md5)
        logger.display_message(True, "Config", "debug=%s" % ConfigData.debug)
        logger.display_message(
            True, "Config",
            "download_location=%s" % ConfigData.download_location)
        logger.display_message(True, "Config",
                               "chunksize=%s" % ConfigData.chunk_size)
        logger.display_message(
            True, "Config",
            "resume_downloads=%s" % ConfigData.resume_downloads)

        for platform in list(ConfigData.download_platforms.keys()):
            logger.display_message(
                True, "Config", "Platform %s=%s" %
                (platform, ConfigData.download_platforms[platform]))
print("Humble Bundle Downloader v%s" % ConfigData.VERSION)
print("This program is not affiliated nor endorsed by Humble Bundle, Inc.")
print("For any suggestion or bug report, please create an issue at:\n%s" %
      ConfigData.BUG_REPORT_URL)
print("")

# Load the configuration from the YAML file...
Configuration.load_configuration("hb-downloader-settings.yaml")
Configuration.parse_command_line()
Configuration.dump_configuration()
Configuration.push_configuration()

validation_status, message = Configuration.validate_configuration()
if not validation_status:
    logger.display_message(False, "Error", message)
    exit("Invalid configuration.  Please check your command line arguments and"
         "hb-downloader-settings.yaml.")

# Initialize the event handlers.
EventHandler.initialize()

hapi = HumbleApi(ConfigData.auth_sess_cookie)

if not hapi.check_login():
        exit("Login to humblebundle.com failed."
             "  Please verify your authentication cookie")

logger.display_message(False, "Processing", "Downloading order list.")
game_keys = hapi.get_gamekeys()
logger.display_message(False, "Processing", "%s orders found." %
Example #6
0
print("The Clown's Humble Bundle Downloader v%.2f" % ConfigData.VERSION)
print("")
print("This downloader includes MIT licensed code from Joel Pedraza.")
print("https://github.com/saik0/humblebundle-python")
print("")

# Load the configuration from the YAML file...
Configuration.load_configuration("hb-downloader-settings.yaml")
Configuration.parse_command_line()
Configuration.dump_configuration()
Configuration.push_configuration()

validation_status, message = Configuration.validate_configuration()
if not validation_status:
    logger.display_message(False, "Error", message)
    exit("Invalid configuration.  Please check your command line arguments and hb-downloader-settings.yaml.")

# Initialize the event handlers.
EventHandler.initialize()

hapi = HumbleApi(ConfigData.cookie_filename, ConfigData.auth_sess_cookie)

if not hapi.check_login():
    ConfigData.authy_token = input("Enter your Authy token: ")
    try:
        hapi.login(ConfigData.username, ConfigData.password, ConfigData.authy_token)
    except HumbleCredentialException as hce:
        logger.display_message(False, "Login", "Failed to login.  %s" % hce.message)
        exit("Login to humblebundle.com failed.  Please verify credentials and token.")
Example #7
0
 def print_download_start(filename):
     logger.display_message(False, "Download", "%s: " % filename, False)
     sys.stdout.flush()
Example #8
0
 def print_md5_start(filename):
     logger.display_message(False, "Checksum", "%s: " % filename, False)
     sys.stdout.flush()
Example #9
0
    def dump_configuration():
        """
            Dumps the current configuration to the log.  Username and password are not dumped to
            allow logs or output to be posted without fear of personal information.

            :return: None
        """
        # Shortcut the process if debugging is not turned on.
        if not ConfigData.debug:
            return

        logger.display_message(True, "Config",
                               "write_md5=%s" % ConfigData.write_md5)
        logger.display_message(True, "Config",
                               "read_md5=%s" % ConfigData.read_md5)
        logger.display_message(True, "Config",
                               "force_md5=%s" % ConfigData.force_md5)
        logger.display_message(True, "Config",
                               "ignore_md5=%s" % ConfigData.ignore_md5)
        logger.display_message(True, "Config", "debug=%s" % ConfigData.debug)
        logger.display_message(
            True, "Config",
            "download_location=%s" % ConfigData.download_location)
        logger.display_message(
            True, "Config", "cookie_filename=%s" % ConfigData.cookie_filename)
        logger.display_message(True, "Config",
                               "chunksize=%s" % ConfigData.chunk_size)
        logger.display_message(
            True, "Config",
            "resume_downloads=%s" % ConfigData.resume_downloads)

        for platform in list(ConfigData.download_platforms.keys()):
            logger.display_message(
                True, "Config", "Platform %s=%s" %
                (platform, ConfigData.download_platforms[platform]))
Example #10
0
 def print_download_start(filename):
     logger.display_message(False, "Download",
                            "{0}: {1:7.2f}% ".format(filename, 0), False)
     sys.stdout.flush()
Example #11
0
 def print_md5_start(filename):
     logger.display_message(False, "Checksum",
                            "{0}: {1:7.2f}% ".format(filename, 0), False)
     sys.stdout.flush()