-
Notifications
You must be signed in to change notification settings - Fork 0
/
Youtube_downloader.py
80 lines (65 loc) · 2.16 KB
/
Youtube_downloader.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
# YouTube video/audio/thumbnail downloader
from pytube import YouTube
# Video downloading code section
def download_vid(yt_1):
# filter() give some specific options to download video
videos = yt_1.streams.filter(progressive=True)
# make together all the streams by enumerate keyword
vid = list(enumerate(videos))
for i in vid:
print(i)
# code for selecting video quality on the bases of px
st_1 = int(input("please provide your index you want to download : "))
if st_1 == 1 or st_1 == 2 or st_1 == 0:
videos[st_1].download()
print("\n successfully downloaded !")
else:
return
# Audio downloading code section
def download_aud(yt_2):
audio = yt_2.streams.filter(only_audio=True)
aud = list(enumerate(audio))
for i in aud:
print(i)
st_2 = int(input("\n please type index that want to download : "))
if st_2 <= 0:
audio[st_2].download()
print("\n Successfully download Audio")
else:
return
# thumbnail downloading code section
def download_thumbnail(yt_3):
thumbnail = yt_3.thumbnail_url
print("thumbnail url : ", thumbnail)
# Convert the bytes into megabytes section
def byte_to_megabyte(size):
megabytes = size / (1024 * 1024)
return megabytes
# Main section code
link = input("provide link here : ")
youtube_0 = YouTube(link)
size = youtube_0.streams.get_highest_resolution().filesize
# size = size of the YouTube video
# new_size = size.to_bytes()
print("Size : ", size)
size = byte_to_megabyte(size)
print("Download size : ", size, "MB")
print("Title : ", youtube_0.title)
print('\n')
print("Choose from the following options ")
print("Press 1 for Download Video ")
print("Press 2 for Download Audio ")
print("Press 3 for Download Thumbnail ")
print("Press 4 for Print Channel Name ")
check = int(input(""))
if check == 1:
youtube_1 = YouTube(link)
download_vid(youtube_1)
elif check == 2:
youtube_2 = YouTube(link)
download_aud(youtube_2)
elif check == 3:
youtube_3 = YouTube(link)
download_thumbnail(youtube_3)
else:
youtube_4 = YouTube(link)