Skip to content

Commit febdef7

Browse files
committed
Switched to Simatwa/y2mate-api and recoded the entire project (V3.0)
1 parent fd027f7 commit febdef7

File tree

5 files changed

+60
-93
lines changed

5 files changed

+60
-93
lines changed

downloader.py

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,81 @@
1-
import pytube
1+
from y2mate_api import Handler
22
import os , sys
33
from tabulate import tabulate
4-
54
# Custom Modules
6-
from modules import vidmerge, progressBar, banner
5+
from modules import banner, cmds
76

7+
# Clear the previous output from the terminal.
8+
cmds.clear()
89
# print Welcome Banner
910
banner.WelcomeBanner()
11+
1012
videoURL = str(input("Enter Video Link : "))
1113

1214
# Don't Enable if you're don't know what it does.
1315
# videoURL = 'https://www.youtube.com/watch?v=mDTMBdYAjHI'
1416

15-
os.system('cls')
17+
cmds.clear()
1618
banner.WelcomeBanner()
1719
print("Looking for Available Qualities..")
1820

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"))
1951

20-
yt = pytube.YouTube(videoURL, on_progress_callback=progressBar.progress_hook)
2152

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!")
2456

2557
mediaPath = f"{os.getcwd()}/vids"
2658

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)
5665

66+
api.save(third_dict=video_metadata, dir="vids", progress_bar=True)
5767

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}")
6072

61-
# Merge the Audio & Video File
62-
vidmerge.merge(title=f"{yt.title}", outVidTitle=videoFileName)
6373

64-
# Remove Seperate Media Files
65-
os.remove(f"{mediaPath}/{yt.title}.mp4")
66-
os.remove(f"{mediaPath}/{yt.title}.mp3")
6774

68-
os.system('cls')
75+
cmds.clear()
6976
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! ✅")
7279

7380

7481

modules/banner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def WelcomeBanner():
99
D O W N L O A D E R
1010
1111
-------------------------------
12-
Version: V2.0
13-
Credits: PyTube
12+
Version: V3.0
13+
Credits: Simatwa/y2mate-api
1414
Dev: @HansanaD
1515
-------------------------------
1616
""")

modules/cmds.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Clear the previous output from the terminal.
2+
import os
3+
4+
def clear():
5+
os.system('cls' if os.name == 'nt' else 'clear')

modules/progressBar.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

modules/vidmerge.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)