Thanks for Pytube ,
I am abit stuck about using on_progress
Could you give me a simple example ?
Thanks in Advance
Here is a simple example
def progress_callback(self, stream, chunk, file_handle, bytes_remaining):
pass
yt = YouTube(url)
yt.register_on_progress_callback(self.progress_callback)
yt.streams.first().download()
Thanks a lot
I write a progress_callback function,but it doesn't work, don't print anything , show_complete can work normal ,i don't know why , could you help me ?
This is the code锛寀se django's model
def download_call(downurl, down_path):
def show_progress_bar(stream, chunk, file_handle, bytes_remaining):
print(bytes_remaining)
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
percentage_of_completion = bytes_downloaded / total_size * 100
new.size = total_size
new.progress = percentage_of_completion
new.save()
def show_complete(steam, file_path):
new.filepath = file_path
new.save()
Ytdownload.objects.create(durl=downurl)
new = Ytdownload.objects.get(durl=downurl)
yt = YouTube(downurl, on_progress_callback=show_progress_bar, on_complete_callback=show_complete)
new.filename = yt.title
yt.streams.filter(progressive=True).filter(subtype='mp4').order_by('resolution')[-1].download(down_path)
.........
download_call(downurl,down_path)