Skip to content

Commit d375ea3

Browse files
committed
V2 Completed with all new features.
1 parent 99bc1d2 commit d375ea3

File tree

5 files changed

+76
-20
lines changed

5 files changed

+76
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ cython_debug/
163163
.mp3
164164
test.py
165165
/vids
166-
/outputs
166+
/outputs

downloader.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,78 @@
1-
from pytube import YouTube
2-
import os
1+
import pytube
2+
import os , sys
33
from tabulate import tabulate
44

55
# Custom Modules
6-
from modules import vidmerge
6+
from modules import vidmerge, progressBar, banner
77

8+
# print Welcome Banner
9+
banner.WelcomeBanner()
10+
videoURL = str(input("Enter Video Link : "))
811

9-
print(f"===============================\n Python YouTube Downloader v2.0\n===============================\n")
12+
os.system('cls')
13+
banner.WelcomeBanner()
14+
print("Looking for Available Qualities..")
1015

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'
1418

15-
yt = YouTube(videoURL)
16-
17-
mediaPath = f"{os.getcwd()}/vids"
19+
yt = pytube.YouTube(videoURL, on_progress_callback=progressBar.progress_hook)
1820

21+
streams = yt.streams.filter(only_video=True, mime_type="video/mp4")
1922
streamsData = []
2023

24+
mediaPath = f"{os.getcwd()}/vids"
25+
2126
# 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):
2329
# print(f"{count}. Res: {stream.resolution} | Size:{stream.filesize_mb} mb")
2430
# print(stream)
2531
streamsData.append([count, stream.resolution, stream.filesize_mb])
2632

2733
streamsDataTable = tabulate(streamsData, headers=["No", "Resolution", "Size (MB)"], tablefmt='rounded_outline')
34+
35+
# Clear the terminal
36+
os.system('cls')
37+
2838
# Print the Table of Stream Data
2939
print(streamsDataTable)
3040

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. ✔")
3245

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.✔")
3653

3754

3855

3956
# print("-------AUDIOS-------")
4057
for stream in yt.streams.filter(only_audio=True, abr="128kbps"):
4158
stream.download(filename=f"{yt.title}.mp3", output_path=mediaPath)
42-
print(stream.abr,": MP3 Downloaded. ✔")
59+
print("Audio Downloaded. ✔")
60+
4361

62+
videoID = pytube.extract.video_id(videoURL)
63+
videoFileName = f"{yt.title}_{videoID}"
4464

4565
# Merge the Audio & Video File
46-
vidmerge.merge(title=yt.title)
66+
vidmerge.merge(title=f"{yt.title}", outVidTitle=f"{videoFileName}_{videoID}")
4767

4868
# Remove Seperate Media Files
4969
os.remove(f"{mediaPath}/{yt.title}.mp4")
5070
os.remove(f"{mediaPath}/{yt.title}.mp3")
5171

72+
os.system('cls')
73+
banner.WelcomeBanner()
5274
print("Download Completed! ✔")
75+
print(f"\nCheck the 'vid' Folder for your files!\n")
5376

5477

5578

modules/banner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
def WelcomeBanner():
3+
print(f"""
4+
__ __ _____ _
5+
\ \ / /__ _ |_ _| _| |__ ___
6+
\ V / _ \ || || || || | '_ \/ -_)
7+
|_|\___/\_,_||_| \_,_|_.__/\___|
8+
9+
D O W N L O A D E R
10+
11+
-------------------------------
12+
Version: V2.0
13+
Credits: PyTube
14+
Dev: @HansanaD
15+
-------------------------------
16+
""")
17+
18+
# WelcomeBanner()

modules/progressBar.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
def progress_hook(stream, chunk, bytes_remaining):
3+
total_size = stream.filesize
4+
bytes_downloaded = total_size - bytes_remaining
5+
6+
percentage_of_completion = bytes_downloaded / total_size * 100
7+
num_chars = int(percentage_of_completion) // 2 # Scale to 0-50 for simplicity
8+
9+
# Create a string of '#' characters to represent the portion of the video that's been downloaded
10+
progress_bar = '█' * num_chars
11+
12+
# Create a string of ' ' characters to represent the portion of the video that hasn't been downloaded yet
13+
remaining_bar = ' ' * (50 - num_chars)
14+
15+
print(f'[{progress_bar}{remaining_bar}] {percentage_of_completion:.2f}% downloaded')

modules/vidmerge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from moviepy.editor import VideoFileClip, AudioFileClip
44

5-
def merge(title):
5+
def merge(title, outVidTitle):
66

77
input_video = os.path.join(os.getcwd(), "vids",f"{title}.mp4")
88
input_audio = os.path.join(os.getcwd(), "vids",f"{title}.mp3")
@@ -15,7 +15,7 @@ def merge(title):
1515
final_clip = video_clip.set_audio(audio_clip)
1616

1717
# Write the final clip to a new file
18-
final_clip.write_videofile(f"vids/{title} output.mp4", codec="libx264")
18+
final_clip.write_videofile(f"vids/{outVidTitle}.mp4", codec="libx264")
1919

2020

2121

0 commit comments

Comments
 (0)