-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (70 loc) · 2.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytube, os
from prettytable import PrettyTable
from pytube.cli import on_progress
def main():
os.system("cls")
link = input("Please paste the youtube link here: ")
yvideo = pytube.YouTube(url=link, on_progress_callback=on_progress)
yvideo.check_availability()
print(f"\n{yvideo.title}\n")
print("1 -> just audio\n2 -> video with no sound\n3 -> video with sound\n")
while True:
try:
choice = int(input("What number do you choose ? "))
if choice in range(1, 4):
break
else:
print("Invalid number")
except ValueError:
print("This is not a number")
print("Getting Data ..")
if get_data(yvideo.streams, choice):
print(":)\nDownload complete\nFind the downloaded file in the same folder of this app.")
else:
print("Apologies, an error occurred")
os.system("pause")
def get_data(streams, choice: int) -> bool:
if choice == 1:
data = PrettyTable(["itag", "mime_type", "bitrate", "size (MB)"])
for stream in streams.filter(only_audio=True).order_by("abr").desc():
data.add_row([stream.itag, stream.mime_type, stream.abr, stream.filesize_mb])
print(data)
elif choice == 2:
data = PrettyTable(["itag", "mime_type", "resolution", "fps", "size (MB)"])
for stream in streams.filter(only_video=True).order_by("resolution").desc():
data.add_row([stream.itag, stream.mime_type, stream.resolution, stream.fps, stream.filesize_mb])
print(data)
elif choice == 3:
data = PrettyTable(["itag", "mime_type", "resolution", "fps", "size (MB)"])
# first I'll try no to use ffmpeg
# just show the progressive tracks only
for stream in streams.filter(progressive=True).order_by("resolution").desc():
data.add_row([stream.itag, stream.mime_type, stream.resolution, stream.fps, stream.filesize_mb])
print(data)
done = False
while not done:
try:
itag = int(input("Enter the itag of the chosen format: "))
chosen = streams.get_by_itag(itag)
assert chosen is not None
print("Downloading ..")
chosen.download(filename=chosen.default_filename)
except ValueError:
print("This is not a number")
except AssertionError:
print("This itag does not exist")
else:
done = True
return done
main()
'''random thoughts:
pyscript
GUI
cmd - no colors .. why ?
install ffmpeg for the user before running
config.json file for your app
make the app open itself in maximized window
I need to make much more apps than this - one per week
'''
# TODO: merge the audio and video
# TODO: make it verbose or simple (choice)