-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyt.py
More file actions
40 lines (30 loc) · 874 Bytes
/
yt.py
File metadata and controls
40 lines (30 loc) · 874 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
34
35
36
37
38
39
40
import yt_dlp
import yt_dlp
import tkinter as tk
from tkinter import filedialog
def download_video(url, save_path):
try:
ydl_opts = {
"format": "mp4",
"outtmpl": save_path + "/%(title)s.%(ext)s"
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
print("Video downloaded successfully!")
except Exception as e:
print("Error:", 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("Start download....")
download_video(video_url, save_dir)
else:
print("Invalid save location.")