Arun Suryan
Arun Suryan

Reputation: 1695

Error while implementing progress_bar in pytube3

I am implementing a youtube video downloader using pytube3. In the following progress_bar() function I am getting an positional argument missing error.

My progress_bar() function:

def progress_bar(stream, chunk, file_handle, bytes_remaining):
    file_downloaded = file_size - bytes_remaining
    percentage = (file_downloaded / file_size) * 100
    print(f'{percentage :00.0f}% done...')

My YouTube() object:

yt_object = YouTube(url, on_progress_callback=progress_bar)

I am getting the following error while displaying or printing the progress

progress_bar() missing 1 required positional argument: 'bytes_remaining'

The file is being downloaded successfully if I do remove the progress_bar reference in YouTube object i.e. yt_object, but I am facing the error in implementing progress_bar().

Upvotes: 3

Views: 83

Answers (1)

T'East
T'East

Reputation: 79

Got the same problem. Solved it by this way:

from pytube import YouTube
from pytube.cli import on_progress

def download_video(url):
    yt = YouTube(url, on_progress_callback=on_progress)
    stream = yt.streams.first()
    print("start to download url: " + url)
    print(stream.title)
    stream.download(DOWNLOAD_DIR)

Upvotes: 1

Related Questions