-
Notifications
You must be signed in to change notification settings - Fork 0
/
YouTube Download.py
94 lines (75 loc) · 2.22 KB
/
YouTube Download.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#importing pafy for youtube download
import pafy
import math
#importing pretty table for table design
from prettytable import PrettyTable
#taking url as input
url =input("enter youtube url:")
#line break
print('\n')
#assigning main module to yt variable
yt=pafy.new(url)
audio=yt.audiostreams
video=yt.streams
all=yt.allstreams
#printing
print(yt)
#line break
print('\n')
#Taking input for selecting media type
type=input('audio/video:')
#line break
print('\n')
#creating table for audio
x = PrettyTable()
x.field_names = ["Index","bitrate","extension","file size"]
for i in audio:
p=str(math.ceil(i.get_filesize()/1024/1024))+' mb'
x.add_row([audio.index(i),i.bitrate,i.extension,p])
#creating table for video
y = PrettyTable()
y.field_names=["Index","resolution","extension","file size"]
for j in video:
q=str(math.ceil(j.get_filesize()/1024/1024))+' mb'
y.add_row([video.index(j),j.resolution,j.extension,q])
#creating table for all
z= PrettyTable()
z.field_names=["Index","media type","extension","quality"]
for k in all:
r=str(math.ceil(k.get_filesize()/1024/1024))+" mb"
z.add_row([all.index(k),k.mediatype,k.extension,r])
print('select a file:')
#conditions for media type
if type=='audio':
print(x)
a=int(input("type index no. of your file:"))
l=audio[a].get_filesize()
print("your file size is" ,math.ceil(l/1024/1024),"mb")
d=input("Do you want to download the file?(y/n)")
if d=='y':
print(audio[a].download())
print("your audio is downloaded")
else:
print("select again")
elif type=='video':
print(y)
b=int(input("type index no.of your file:"))
m=video[b].get_filesize()
print("your file size is" ,math.ceil(m/1024/1024),"mb")
e=input("Do you want to download the file?(y/n)")
if e=='y':
print(video[b].download())
print("your video is downloaded")
else:
print("select again")
else:
print(z)
c=int(input("type index no. of your file:"))
n=all[c].get_filesize()
print("your file size is" ,math.ceil(n/1024/1024),"mb")
f=input("Do you want to download the file?(y/n)")
if f=='y':
print(all[c].download())
print("your video is downloaded")
else:
print("select again")