|
1 | | -from pytube import YouTube |
2 | | -import os |
| 1 | +import pytube |
| 2 | +import os , sys |
3 | 3 | from tabulate import tabulate |
4 | 4 |
|
5 | 5 | # Custom Modules |
6 | | -from modules import vidmerge |
| 6 | +from modules import vidmerge, progressBar, banner |
7 | 7 |
|
| 8 | +# print Welcome Banner |
| 9 | +banner.WelcomeBanner() |
| 10 | +videoURL = str(input("Enter Video Link : ")) |
8 | 11 |
|
9 | | -print(f"===============================\n Python YouTube Downloader v2.0\n===============================\n") |
| 12 | +os.system('cls') |
| 13 | +banner.WelcomeBanner() |
| 14 | +print("Looking for Available Qualities..") |
10 | 15 |
|
11 | | -# videoURL = str(input("Enter Video Link : ")) |
12 | | -print("\nLooking for Available Qualities..") |
13 | | -videoURL = 'https://www.youtube.com/watch?v=mDTMBdYAjHI' |
| 16 | +# Only Enable for dev. purposes. |
| 17 | +# videoURL = 'https://www.youtube.com/watch?v=mDTMBdYAjHI' |
14 | 18 |
|
15 | | -yt = YouTube(videoURL) |
16 | | - |
17 | | -mediaPath = f"{os.getcwd()}/vids" |
| 19 | +yt = pytube.YouTube(videoURL, on_progress_callback=progressBar.progress_hook) |
18 | 20 |
|
| 21 | +streams = yt.streams.filter(only_video=True, mime_type="video/mp4") |
19 | 22 | streamsData = [] |
20 | 23 |
|
| 24 | +mediaPath = f"{os.getcwd()}/vids" |
| 25 | + |
21 | 26 | # print("-------VIDEOS-------") |
22 | | -for count, stream in enumerate(yt.streams.filter(only_video=True, mime_type="video/mp4"), start=1): |
| 27 | + |
| 28 | +for count, stream in enumerate(streams, start=1): |
23 | 29 | # print(f"{count}. Res: {stream.resolution} | Size:{stream.filesize_mb} mb") |
24 | 30 | # print(stream) |
25 | 31 | streamsData.append([count, stream.resolution, stream.filesize_mb]) |
26 | 32 |
|
27 | 33 | streamsDataTable = tabulate(streamsData, headers=["No", "Resolution", "Size (MB)"], tablefmt='rounded_outline') |
| 34 | + |
| 35 | +# Clear the terminal |
| 36 | +os.system('cls') |
| 37 | + |
28 | 38 | # Print the Table of Stream Data |
29 | 39 | print(streamsDataTable) |
30 | 40 |
|
31 | | -userInput = input(str("Enter the Res Number: ")) |
| 41 | +try: |
| 42 | + userInput = int(input("Enter the Res Number: ")) - 1 |
| 43 | + streams[userInput].download(filename=f"{yt.title}.mp4", output_path=mediaPath) |
| 44 | + print("Video Downloaded. ✔") |
32 | 45 |
|
33 | | -for stream in yt.streams.filter(only_video=True, mime_type="video/mp4", res=userInput): |
34 | | - stream.download(filename=f"{yt.title}.mp4", output_path=mediaPath) |
35 | | - print(userInput, ": MP4 Downloaded.✔") |
| 46 | +except: |
| 47 | + print("Wrong Input! Try Again!") |
| 48 | + sys.exit() |
| 49 | + |
| 50 | +# for stream in streams: |
| 51 | +# stream.download(filename=f"{yt.title}.mp4", output_path=mediaPath) |
| 52 | +# print("Resolution_code : MP4 Downloaded.✔") |
36 | 53 |
|
37 | 54 |
|
38 | 55 |
|
39 | 56 | # print("-------AUDIOS-------") |
40 | 57 | for stream in yt.streams.filter(only_audio=True, abr="128kbps"): |
41 | 58 | stream.download(filename=f"{yt.title}.mp3", output_path=mediaPath) |
42 | | - print(stream.abr,": MP3 Downloaded. ✔") |
| 59 | + print("Audio Downloaded. ✔") |
| 60 | + |
43 | 61 |
|
| 62 | +videoID = pytube.extract.video_id(videoURL) |
| 63 | +videoFileName = f"{yt.title}_{videoID}" |
44 | 64 |
|
45 | 65 | # Merge the Audio & Video File |
46 | | -vidmerge.merge(title=yt.title) |
| 66 | +vidmerge.merge(title=f"{yt.title}", outVidTitle=f"{videoFileName}_{videoID}") |
47 | 67 |
|
48 | 68 | # Remove Seperate Media Files |
49 | 69 | os.remove(f"{mediaPath}/{yt.title}.mp4") |
50 | 70 | os.remove(f"{mediaPath}/{yt.title}.mp3") |
51 | 71 |
|
| 72 | +os.system('cls') |
| 73 | +banner.WelcomeBanner() |
52 | 74 | print("Download Completed! ✔") |
| 75 | +print(f"\nCheck the 'vid' Folder for your files!\n") |
53 | 76 |
|
54 | 77 |
|
55 | 78 |
|
|
0 commit comments