Pytube: any example for on_progress

Created on 17 Oct 2018  路  3Comments  路  Source: pytube/pytube

Thanks for Pytube ,

I am abit stuck about using on_progress

Could you give me a simple example ?

Thanks in Advance

All 3 comments

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)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stdedos picture stdedos  路  24Comments

ajayrandhawa picture ajayrandhawa  路  20Comments

waterholic picture waterholic  路  24Comments

walpolsh picture walpolsh  路  44Comments

haroldfry picture haroldfry  路  58Comments