|
1 | 1 | from yt_dlp import YoutubeDL |
2 | 2 |
|
3 | | -# with YoutubeDL() as ydl: |
4 | | -# info_dict = ydl.extract_info('https://www.youtube.com/watch?v=BaW_jenozKc', download=False) |
5 | | -# video_title = info_dict.get('title', None) |
6 | | -# print(f"The title of the video is: {video_title}") |
7 | 3 |
|
8 | 4 | print(f" ==========================\n Python YouTube Downloader \n==========================\n") |
9 | 5 |
|
10 | 6 | # videoURL = str(input("Enter Video Link : ")) |
11 | | -videoURL = 'https://www.youtube.com/watch?v=HE7ViC-n25g' |
| 7 | +videoURL = 'https://www.youtube.com/watch?v=5cCaU6T1yFE' |
12 | 8 |
|
13 | 9 | ydl_opts = { |
14 | 10 | "quiet": True, |
15 | 11 | 'outtmpl': "%(title)s_%(id)s.%(ext)s" |
16 | 12 | } |
17 | 13 |
|
| 14 | +print("Fetching the info...") |
18 | 15 |
|
19 | 16 | with YoutubeDL( ydl_opts ) as ydl: |
20 | 17 | vidInfo = ydl.extract_info(videoURL, download=False) |
21 | 18 |
|
22 | 19 | print("\n🔹 Title:", vidInfo.get('title', None)) |
23 | | - print("🔹 Views:", vidInfo.get('view_count', None), "views") |
24 | | - print("🔹 Size:", vidInfo.get('filesize', None)) |
| 20 | + print("🔹 Duration:", vidInfo.get('duration', None)) |
| 21 | + print("🔹 Size:", vidInfo.get('filesize_approx', None) // 1048576, "MB") |
25 | 22 |
|
26 | | - print("\n CHOOSE YOUR RESOLUTION \n--------------------------") |
| 23 | +print("Downloading...") |
27 | 24 |
|
28 | | - for format in vidInfo['formats']: |
29 | | - print(f"{format['format_id']} - {format['format']} - {format['ext']}") |
30 | | - |
| 25 | +ydl.download(videoURL) |
31 | 26 |
|
| 27 | +print("Video is Downloaded Successfully!") |
32 | 28 |
|
33 | 29 |
|
| 30 | + |
34 | 31 |
|
| 32 | + |
| 33 | + # usrChosenFormat = input("Enter Your Format number: ") |
35 | 34 |
|
36 | | - |
37 | | -# from yt_dlp import YoutubeDL |
38 | | - |
39 | | -# ydl = YoutubeDL({'listformats': True}) |
40 | | -# ytlink = "https://www.youtube.com/watch?v=HE7ViC-n25g" |
41 | | -# info = ydl.extract_info(ytlink, download=False) |
42 | | - |
43 | | - |
44 | | - |
45 | | -# for format in info['formats']: |
46 | | -# print(f"{format['format_id']} - {format['format']} - {format['ext']}") |
47 | | - |
48 | | -# usrChosenFormat = str(input("Choose Format: ")) |
49 | | - |
50 | | -# ydl = YoutubeDL({'format': usrChosenFormat}) |
51 | | -# ydl.download([ytlink]) |
52 | | - |
53 | | -#give a specific no to each specific format, so i can choose them in the userChosenFormat and download the exact format i want. also make the output more organized for better user experience. |
54 | | - |
55 | | - |
56 | | -# from yt_dlp import YoutubeDL |
57 | | - |
58 | | -# ydl = YoutubeDL() |
59 | | -# ytlink = "https://www.youtube.com/watch?v=HE7ViC-n25g" |
60 | | -# info = ydl.extract_info(ytlink, download=False) |
61 | | - |
62 | | -# # Print out a numbered list of available formats |
63 | | -# for i, format in enumerate(info['formats']): |
64 | | -# print(f"{i+1}. {format['format_id']} - {format['format']} - {format['ext']}") |
65 | | - |
66 | | -# # Get user input and validate it |
67 | | -# while True: |
68 | | -# try: |
69 | | -# usrChosenFormat = int(input("Choose Format: ")) - 1 |
70 | | -# if usrChosenFormat < 0 or usrChosenFormat >= len(info['formats']): |
71 | | -# raise ValueError() |
72 | | -# break |
73 | | -# except ValueError: |
74 | | -# print("Invalid input. Please enter a number corresponding to a format.") |
75 | | - |
76 | | -# # Download the chosen format |
77 | | -# ydl = YoutubeDL({'format': info['formats'][usrChosenFormat]['format_id']}) |
78 | | -# ydl.download([ytlink]) |
79 | | - |
| 35 | + # ydl = YoutubeDL({'format': usrChosenFormat}) |
| 36 | + # ydl.download([videoURL]) |
0 commit comments