[BUG] on_progress_callback & on_complete_callback arguments
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay that’s not something I did wrong 😃 Thx!
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