-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathyoutube.py
More file actions
33 lines (27 loc) · 918 Bytes
/
youtube.py
File metadata and controls
33 lines (27 loc) · 918 Bytes
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
30
31
32
33
from pytube import YouTube
import tkinter as tk
from tkinter import filedialog
def download_video(url, save_path):
try:
yt = YouTube(url)
streams = yt.streams.filter(progressive=True, file_extension="mp4")
highest_res_stream = streams.get_highest_resolution()
highest_res_stream.download(output_path=save_path)
print("Video downloaded successfully!")
except Exception as e:
print(e)
def open_file_dialog():
folder = filedialog.askdirectory()
if folder:
print(f"Selected folder: {folder}")
return folder
if __name__ == "__main__":
root = tk.Tk()
root.withdraw()
video_url = input("Please enter a YouTube url: ")
save_dir = open_file_dialog()
if save_dir:
print("Started download...")
download_video(video_url, save_dir)
else:
print("Invalid save location.")