question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] on_progress_callback & on_complete_callback arguments

See original GitHub issue

Hi,

I’m using the 10.1.0 version of pytube.

When I try to add progress callback, it takes 3 args : chunk: bytes, file_handler: BinaryIO, bytes_remaining: int. However, the three args i’m using have types Stream, bytes, int and they are passed from the YoutTube object.

Moreover, the on_complete callback is not working, the app crashes with a random negative exit code.

Here is my code :

# This works good but not coherant with doc
def progress_function(stream, chunk, bytes_remaining):
    total_size = stream.filesize
    bytes_downloaded = total_size - bytes_remaining
    percentage_of_completion = bytes_downloaded / total_size * 100
    window.ui.progressBar.setValue(int(percentage_of_completion))

# This makes the app crash. The print is not even written on the console.
def completed_function():
    print("download conmpleted")
    window.ui.progressBar.setVisible(False)
    window.ui.info_text.setText("Téléchargement terminé !")
 
youtube = pytube.YouTube(self.url_link)
# Set callbacks for on going download and completed download
youtube.register_on_progress_callback(progress_function) # warning Expected type 'OnProgress', got (stream: {filesize}, chunk: Any, bytes_remaining: Any) -> None instead
youtube.register_on_complete_callback(completed_function) # warning Expected type 'OnComplete', got () -> None instead
video = youtube.streams.get_highest_resolution()
dir_path = QFileDialog().getExistingDirectory(self, 'Save MP4 ...', expanduser('~'), QFileDialog.ShowDirsOnly)
print("Download will start...")
video.download(dir_path)

I’m using python 3.9 and installed pytube from the UI of PyCharm.

EDIT : It looks like I messed up with the on_progress method on the Stream Object and the register_on_progress_callback method on the Youtube Object ! However, would you please explain to me how to fix the warnings described above ?

Thanks a lot !

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
maxouillecommented, Dec 14, 2020

Okay that’s not something I did wrong 😃 Thx!

0reactions
tfdahlincommented, Dec 14, 2020

Ah, I know why that’s happening actually. The type hints in the code must be incorrect. I’ll try to fix that later, but in the meantime, you can disable type hints in pycharm: https://stackoverflow.com/a/45671046

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] animation.onComplete callback has no param passed ...
The passed parameter is undefined. Possible Solution. Haven't looked into fixing it. Steps to Reproduce (for bugs). Open up Chart.js> ...
Read more >
ProcessDdpParameters - Nintex help documentation
Provides parameters and options for the Process DocGen Package ... onCompleteCallback property, Gets or sets the callback method to be invoked on completion ......
Read more >
Asynchronous JavaScript - Discover three.js!
This method takes two arguments, a callback function, and the amount of time we want to wait (in milliseconds) before executing the callback...
Read more >
Problem With Onprogresscallback Of Python Module Pytube
onCompleteCallback property Gets or sets the callback method to be invoked on completion of the DocGen Package run. Syntax. String onProgressCallback. Feel free ......
Read more >
txt-reader - npm
TxtReader is a JavaScript library to read text file in browsers based on FileReader API. It can read very large, huge, giant files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found