Created
April 12, 2021 10:13
-
-
Save alrafiabdullah/6fd66a71d43099e5ff37d9cd6396be3c to your computer and use it in GitHub Desktop.
A command line YouTube video downloader using pytube library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install git+https://github.com/nficano/pytube@5d2c1a4e756cd8bac373867bf673155e691f1e04 | |
from pytube import YouTube | |
import time | |
start_time = time.time() | |
previous = 0 | |
def progress_function(stream, chunk, bytes_remaining, self=previous): | |
contentsize = stream.filesize | |
size = contentsize - bytes_remaining | |
end_time = time.time() | |
print( | |
f"\r[Download progress]: %.2f%% - %.0f MB/ %.2f GB at %.2f/mbps" % (float(size/contentsize*100), float(size/1024/1024), float(contentsize/1024/1024/1024), float(((size-self)/1024/1024)/(end_time-start_time))), end='') | |
previous = size | |
if __name__ == "__main__": | |
links = [""] # Add your links here | |
for link in links: | |
previous_size = 0 | |
yt = YouTube(link, on_progress_callback=progress_function) | |
ys = yt.streams.get_highest_resolution() | |
print(f"Downloading - {yt.title}") | |
ys.download() | |
print(f"Download completed!\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment