def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):
global file_size
#Gets the percentage of the file that has been downloaded.
percent = (100*(file_size-remaining))/file_size
print("{:00.0f}% downloaded".format(percent))
When calling the above function for returning download percentage from
yt = YouTube(link,on_progress_callback=progress_Check)
But I'm getting an error like can't subtract integer and None, So What are the function parameters/how to get them ?
Any Idea ??
progress_Check
requires only 3 arguments: stream
, chunk
, and remaining
since only 3 arguments are needed, the 4th one isn't assigned to anything, therefore remaining
would be set to None
and would result in the error during the calculation
you also don't need to set each argument's default as None
since those would get overriden anyways
here's the fixed code:
def progress_Check(stream, chunk, remaining):
global file_size
#Gets the percentage of the file that has been downloaded.
percent = (100 * (file_size - remaining)) / file_size
print("{:00.0f}% downloaded".format(percent))