Search code examples
pythondownloadyoutubeprogress-barpytube

Youtube Downloading Progress bar issue


I am trying to add download progress while dowloading a Youtube video, However every method I try, something weird issue comes up. Can anyone help?

Issue is TypeError: progress_func() missing 2 required positional arguments: 'file_handle' and 'bytes_remaining'

I have tried supplying None value to each but then it goes on to saying that bytes_remaining & size are not of the same type.

Thank you

def progress_func(self, stream, chunk, file_handle,bytes_remaining):
  size = self.video.filesize
  progress = (float(abs(bytes_remaining-size)/size))*float(100)
  self.loadbar.setValue(progress)

yurl = input("VURL here: ")
yt = YouTube(yurl, on_progress_callback=progress_func)

Solution

  • The on_progress_callback function just needs 3 parameters: stream, chunk and bytes_remaining. Also, it looks like that function is a method inside a class: in that case, you have to manually pass the "self" argument using a lambda function, so your code should look like this:

    yt = YouTube(yurl, on_progress_callback=lambda stream, chunk, bytes_remaining: self.progress_func(self, stream, chunk, bytes_remaining))
    

    I ran into the same issue a while ago and this is how I fixed it. Hope this will be your solution aswell!