-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (62 loc) · 2.26 KB
/
Copy pathmain.py
File metadata and controls
78 lines (62 loc) · 2.26 KB
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
'''
YouTube video or audio downloader using command line input
-by Mohammed Saad
Credits: https://pypi.org/project/pytube/
Installations:
pip install pytube
pip install clint
pip install terminaltables
'''
from pytube import YouTube
from pyfiglet import Figlet # Intro text
from clint.textui import puts, colored, indent, progress # Colored text
from clint.arguments import Args
from terminaltables import SingleTable # Table view
global MaxFileSize, fileSizeInBytes
f = Figlet(font='slant')
inroText = f.renderText('YT Downloader')
print(inroText)
link = input(colored.green('Enter link to download: '))
print()
def progress(stream=None, chunk=None, file_handle=None, remaining=None):
# Gets the percentage of the file that has been downloaded.
percent = (100 * (fileSizeInBytes - remaining)) / fileSizeInBytes
print("\r{:00.0f}% downloaded".format(percent), end='')
# creating object of class YouTube @param video link @param download progress status
youtube = YouTube(link, on_progress_callback=progress)
print(colored.yellow("\tSELECT THE FORMAT TO DOWNLOAD"))
table_data = [
['Format ID', 'VIDEO', '', 'Format ID', 'AUDIO'],
['1', '1080p', ' ', '4', '128kbps'],
['2', '720p', ' ', '5', '70kbps'],
['3', '480p', ' ', '6', '50kbps']
]
table = SingleTable(table_data)
print(colored.cyan(table.table))
downloadType = input(colored.green('Enter format id: '))
print()
# checking if the input entered is int
try:
val = int(downloadType)
if val == 1:
selectedVideo = youtube.streams.get_by_itag(137)
elif val == 2:
selectedVideo = youtube.streams.get_by_itag(22)
elif val == 3:
selectedVideo = youtube.streams.get_by_itag(135)
elif val == 4:
selectedVideo = youtube.streams.get_by_itag(140)
elif val == 5:
selectedVideo = youtube.streams.get_by_itag(250)
elif val == 6:
selectedVideo = youtube.streams.get_by_itag(249)
except ValueError:
print(colored.red('INVALID INPUT'))
exit()
print(colored.yellow('Title = ' + youtube.title))
fileSizeInBytes = selectedVideo.filesize
MaxFileSize = fileSizeInBytes/1024000
MB = str(MaxFileSize) + " MB"
print(colored.yellow("File Size = {:00.00f} MB".format(MaxFileSize)))
selectedVideo.download()
print(colored.green('\rVIDEO DOWNLOADED!!'))