|
1 | | -import pytube |
| 1 | +from y2mate_api import Handler |
2 | 2 | import os , sys |
3 | 3 | from tabulate import tabulate |
4 | | - |
5 | 4 | # Custom Modules |
6 | | -from modules import vidmerge, progressBar, banner |
| 5 | +from modules import banner, cmds |
7 | 6 |
|
| 7 | +# Clear the previous output from the terminal. |
| 8 | +cmds.clear() |
8 | 9 | # print Welcome Banner |
9 | 10 | banner.WelcomeBanner() |
| 11 | + |
10 | 12 | videoURL = str(input("Enter Video Link : ")) |
11 | 13 |
|
12 | 14 | # Don't Enable if you're don't know what it does. |
13 | 15 | # videoURL = 'https://www.youtube.com/watch?v=mDTMBdYAjHI' |
14 | 16 |
|
15 | | -os.system('cls') |
| 17 | +cmds.clear() |
16 | 18 | banner.WelcomeBanner() |
17 | 19 | print("Looking for Available Qualities..") |
18 | 20 |
|
| 21 | +api = Handler(videoURL) |
| 22 | + |
| 23 | +q_list = ['4k', '1080p', '720p', '480p', '360p', '240p'] |
| 24 | +q_list.reverse() |
| 25 | + |
| 26 | +urlList = {} |
| 27 | + |
| 28 | + |
| 29 | +def getVidInfo(r): |
| 30 | + for video_metadata in api.run(quality=r): |
| 31 | + |
| 32 | + quality = video_metadata.get("q") |
| 33 | + vidLink = video_metadata.get("dlink") |
| 34 | + |
| 35 | + if vidLink == None: |
| 36 | + pass |
| 37 | + else: |
| 38 | + urlList.update({quality : vidLink}) |
| 39 | + # print(r, " fetched") |
| 40 | + |
| 41 | +# Iterate over q_list to check if res quality exist on that video |
| 42 | +for count, r in enumerate(q_list): |
| 43 | + getVidInfo(r) |
| 44 | + |
| 45 | +# print qualities to the terminal |
| 46 | +showList = {} |
| 47 | +for count, q in enumerate(urlList, 1): |
| 48 | + showList.update({count: q}) |
| 49 | + |
| 50 | +print(tabulate(showList.items(), headers=["Q-No", "Quality"], tablefmt="heavy_grid")) |
19 | 51 |
|
20 | | -yt = pytube.YouTube(videoURL, on_progress_callback=progressBar.progress_hook) |
21 | 52 |
|
22 | | -streams = yt.streams.filter(only_video=True, mime_type="video/mp4") |
23 | | -streamsData = [] |
| 53 | +userInput = int(input("Enter the your Q-No: ")) |
| 54 | +cmds.clear() |
| 55 | +print("Downloading...Please wait!") |
24 | 56 |
|
25 | 57 | mediaPath = f"{os.getcwd()}/vids" |
26 | 58 |
|
27 | | -# -------VIDEOS------- |
28 | | - |
29 | | -for count, stream in enumerate(streams, start=1): |
30 | | - # print(f"{count}. Res: {stream.resolution} | Size:{stream.filesize_mb} mb") |
31 | | - # print(stream) |
32 | | - streamsData.append([count, stream.resolution, stream.filesize_mb]) |
33 | | - |
34 | | -streamsDataTable = tabulate(streamsData, headers=["No", "Resolution", "Size (MB)"], tablefmt='rounded_outline') |
35 | | - |
36 | | -# Clear the terminal |
37 | | -os.system('cls') |
38 | | - |
39 | | -# Print the Table of Stream Data |
40 | | -print(streamsDataTable) |
41 | | - |
42 | | -try: |
43 | | - userInput = int(input("Enter the Res Number: ")) - 1 |
44 | | - streams[userInput].download(filename=f"{yt.title}.mp4", output_path=mediaPath) |
45 | | - print("Video Downloaded. ✔") |
46 | | - |
47 | | -except: |
48 | | - print("Wrong Input! Try Again!") |
49 | | - sys.exit() |
50 | | - |
51 | | -# -------AUDIOS------- |
52 | | - |
53 | | -for stream in yt.streams.filter(only_audio=True, abr="128kbps"): |
54 | | - stream.download(filename=f"{yt.title}.mp3", output_path=mediaPath) |
55 | | - print("Audio Downloaded. ✔") |
| 59 | +# Download the video using user's input |
| 60 | +for video_metadata in api.run(quality=showList[userInput]): |
| 61 | + # print(video_metadata) |
| 62 | + |
| 63 | + if not os.path.exists(mediaPath): |
| 64 | + os.makedirs(mediaPath) |
56 | 65 |
|
| 66 | + api.save(third_dict=video_metadata, dir="vids", progress_bar=True) |
57 | 67 |
|
58 | | -videoID = pytube.extract.video_id(videoURL) |
59 | | -videoFileName = f"{yt.title}_{videoID}" |
| 68 | + vidFileName = f"{video_metadata["title"]} {video_metadata["vid"]}_{video_metadata["fquality"]}.{video_metadata["ftype"]}" |
| 69 | + print("Downloading:", vidFileName) |
| 70 | + # Delete your file automatically after it downloaded. |
| 71 | + # os.remove(f"{mediaPath}/{vidFileName}") |
60 | 72 |
|
61 | | -# Merge the Audio & Video File |
62 | | -vidmerge.merge(title=f"{yt.title}", outVidTitle=videoFileName) |
63 | 73 |
|
64 | | -# Remove Seperate Media Files |
65 | | -os.remove(f"{mediaPath}/{yt.title}.mp4") |
66 | | -os.remove(f"{mediaPath}/{yt.title}.mp3") |
67 | 74 |
|
68 | | -os.system('cls') |
| 75 | +cmds.clear() |
69 | 76 | banner.WelcomeBanner() |
70 | | -print("Download Completed! ✔") |
71 | | -print(f"\nCheck the 'vid' Folder for your files!\n") |
| 77 | +print(f"\nPlease Check the 'vid' Folder for your files!\n") |
| 78 | +print("Download Completed! ✅") |
72 | 79 |
|
73 | 80 |
|
74 | 81 |
|
|
0 commit comments