-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.py
29 lines (22 loc) · 824 Bytes
/
youtube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pytube import YouTube
from sys import argv
def progress_function(stream, chunk, bytes_remaining):
size = stream.filesize
percent = round((1 - bytes_remaining / size) * 100, 2)
print(f"\rDownloading... {percent}%", end="")
try:
link = argv[1]
yt = YouTube(link, on_progress_callback=progress_function)
print("Title:", yt.title)
print("View:", yt.views)
# download
try:
print("Downloading... Wait")
yd = yt.streams.get_highest_resolution()
# PASS THE PATH WHERE YOU WANT SAVE THE DOWNLOADED VIDEOS
yd.download(r'C:\Users\Lucas\Documents\downloadsyoutube')
print("\nDownload successful")
except Exception as error:
print(f"Download failed: {error}")
except Exception as e:
print(f"Error: {e}")