-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTubeDownloader.py
More file actions
77 lines (67 loc) · 2.66 KB
/
Copy pathYouTubeDownloader.py
File metadata and controls
77 lines (67 loc) · 2.66 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import yt_dlp
# Define the download folder
DOWNLOAD_FOLDER = "Video Downloaded"
os.makedirs(DOWNLOAD_FOLDER, exist_ok=True)
# Common yt-dlp options for best single stream (no ffmpeg required)
YDL_OPTS = {
'outtmpl': os.path.join(DOWNLOAD_FOLDER, '%(title)s.%(ext)s'),
'format': 'best', # Selects the best pre-merged video+audio stream
'merge_output_format': 'mp4',
'noplaylist': True,
}
def download_single_video():
url = input("\n📥 Enter YouTube video or Shorts URL: ")
with yt_dlp.YoutubeDL(YDL_OPTS) as ydl:
try:
ydl.download([url])
print(f"✅ Download complete ➜ Saved in '{DOWNLOAD_FOLDER}'\n")
except Exception as e:
print(f"❌ Error: {e}\n")
def download_multiple_videos():
print("\n📥 Paste each YouTube URL. Type 'done' when finished.")
urls = []
while True:
url = input("URL: ")
if url.strip().lower() == 'done':
break
urls.append(url.strip())
if not urls:
print("⚠️ No URLs entered.\n")
return
with yt_dlp.YoutubeDL(YDL_OPTS) as ydl:
for url in urls:
try:
ydl.download([url])
print(f"✅ Downloaded: {url}")
except Exception as e:
print(f"❌ Failed to download {url}: {e}")
print(f"✅ All downloads finished ➜ Saved in '{DOWNLOAD_FOLDER}'\n")
def download_profile_placeholder():
print("\n🚧 Full profile/channel download:")
print("To download an entire channel or playlist, uncomment the playlist option below.\n")
print("Example (uncomment `YDL_OPTS['noplaylist'] = False`):")
print(" YDL_OPTS['noplaylist'] = False")
print(" ydl.download(['https://www.youtube.com/c/YourChannel/videos'])\n")
print("Or just run:\n yt-dlp -o 'Video Downloaded/%(title)s.%(ext)s' -f best '<channel_or_playlist_URL>'\n")
def main():
while True:
print("\n==== yt-dlp YouTube Downloader ====")
print("1. Download Single Video or Short")
print("2. Download Multiple Videos")
print("3. Download The Whole Profile/Playlist (Instructions)")
print("0. Exit")
choice = input("Choose an option (0-3): ").strip()
if choice == "1":
download_single_video()
elif choice == "2":
download_multiple_videos()
elif choice == "3":
download_profile_placeholder()
elif choice == "0":
print("👋 Goodbye!")
break
else:
print("❌ Invalid choice. Please try again.\n")
if __name__ == "__main__":
main()