Example #1
0
File: yt.py Project: mig2902/ytmdl
def progress_handler(d):
    d_obj = Download('', '')

    if d['status'] == 'downloading':
        length = d_obj._get_terminal_length()
        time_left = d['eta']
        f_size_disp, dw_unit = d_obj._format_size(d['downloaded_bytes'])
        percent = d['downloaded_bytes'] / d['total_bytes'] * 100
        speed, s_unit, time_left, time_unit = d_obj._get_speed_n_time(
                    d['downloaded_bytes'],
                    0,
                    cur_time=d['elapsed'] - 6
                )

        status = r"%-7s" % ("%s %s" % (round(f_size_disp), dw_unit))
        if d['speed'] is not None:
            speed, s_unit = d_obj._format_speed(d['speed'] / 1000)
            status += r"| %-3s " % ("%s %s" % (round(speed), s_unit))

        status += r"|| ETA: %-4s " % (
                                    "%s %s" %
                                    (round(time_left), time_unit))

        status = d_obj._get_bar(status, length, percent)
        status += r" %-4s" % ("{}%".format(round(percent)))

        stdout.write('\r')
        stdout.write(status)
        stdout.flush()
Example #2
0
def test__format_size():
    """
    Test the function that formats the size
    """
    download = Download(TEST_URL)

    size, unit = download._format_size(255678999)

    # Size should be 243.83449459075928
    # and unit should be `MB`
    size = int(size)

    assert size == 243, "Should be 243"
    assert unit == "MB", "Should be MB"