Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress emulation in Windows 10 (doesnt work) #207

Closed
ilwsm opened this issue Sep 15, 2019 · 4 comments
Closed

Progress emulation in Windows 10 (doesnt work) #207

ilwsm opened this issue Sep 15, 2019 · 4 comments

Comments

@ilwsm
Copy link

ilwsm commented Sep 15, 2019

This code not update text in console

All time this: N/A% | | 0.0 s/B 0.0 B/300.0 B Elapsed Time: 0:00:00 ETA: --:--:--

import collections
import time
import progressbar

struct = collections.namedtuple

def get_progress_info():
    """Return a function callback to update the progressbar."""
    progressinfo = struct("ProgressInfo", ["callback", "finish"])

    if progressbar:
        bar = progressbar.ProgressBar(widgets=[
            progressbar.Percentage(),
            ' ', progressbar.Bar(),
            ' ', progressbar.FileTransferSpeed(),
            ' ', progressbar.DataSize(), '/', progressbar.DataSize('max_value'),
            ' ', progressbar.Timer(),
            ' ', progressbar.AdaptiveETA(),
        ])

        def _callback(total_size, completed):
            if not hasattr(bar, "next_update"):
                if hasattr(bar, "maxval"):
                    bar.maxval = total_size
                else:
                    bar.max_value = total_size
                bar.start()
            bar.update(completed)

        def _finish():
            if hasattr(bar, "next_update"):
                return bar.finish()

        return progressinfo(callback=_callback, finish=_finish)
    else:
        return progressinfo(callback=None, finish=lambda: True)

def upload(progress_callback):

    for x in range(0, 300):
        time.sleep(1)
        progress_callback(300, x)


progress = get_progress_info()
upload(progress.callback)

https://github.com/tokland/youtube-upload/blob/master/youtube_upload/main.py#L63
https://github.com/tokland/youtube-upload/blob/master/youtube_upload/upload_video.py#L22

@wolph
Copy link
Owner

wolph commented Sep 17, 2019

Not sure how or where it broke, but something is indeed not updating correctly there. I'm investigating the issue :)

@wolph
Copy link
Owner

wolph commented Sep 17, 2019

Looking more closely at the code, the issue is that it's using next_update to decide what to do. That variable has been removed along the versions... I never expected anyone to depend on that but I'll add it again :)

For the time being the code should be fixable by simplifying it a bit:

import collections
import time
import progressbar

struct = collections.namedtuple

def get_progress_info():
    """Return a function callback to update the progressbar."""
    progressinfo = struct("ProgressInfo", ["callback", "finish"])

    if progressbar:
        bar = progressbar.ProgressBar(widgets=[
            progressbar.Percentage(),
            ' ', progressbar.Bar(),
            ' ', progressbar.FileTransferSpeed(),
            ' ', progressbar.DataSize(), '/', progressbar.DataSize('max_value'),
            ' ', progressbar.Timer(),
            ' ', progressbar.AdaptiveETA(),
        ])

        def _callback(total_size, completed):
            bar.max_value = total_size
            bar.update(completed)

        def _finish():
            return bar.finish()

        return progressinfo(callback=_callback, finish=_finish)
    else:
        return progressinfo(callback=None, finish=lambda: True)


def upload(progress_callback):
    for x in range(0, 300):
        time.sleep(1)
        progress_callback(300, x)


progress = get_progress_info()
upload(progress.callback)

@ilwsm
Copy link
Author

ilwsm commented Sep 17, 2019

Big thanks 👍 🥇

@wolph wolph closed this as completed in 2c47c93 Sep 17, 2019
@wolph
Copy link
Owner

wolph commented Sep 17, 2019

I've got a working patch ready on develop, I'm planning to put out a new release within the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants