-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
114 lines (87 loc) · 2.87 KB
/
main.py
File metadata and controls
114 lines (87 loc) · 2.87 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from pytube import YouTube, Playlist
import os
VIDEO = 1
PLAYLIST = 2
def progress_function(stream, chunk, remaining):
percent = (100 * (file_size - remaining))/file_size
print("{:00.0f}% downloaded".format(percent))
#Grabs the file path for Download
def file_path():
home = os.path.expanduser('~')
download_path = os.path.join(home, 'Downloads')
return download_path
def get_resolution(the_video):
the_video = the_video.streams.filter(progressive = True)
list_quality = [stream.resolution for stream in the_video]
return list_quality
def videoDownload():
#Input
yt_url = input("Copy dan paste Youtube URL Mu: ")
print(yt_url)
print ("Mengakses URL Video di YouTube ...")
# Cari video dan akses callback didalamnya
try:
video = YouTube(yt_url, on_progress_callback=progress_function)
except:
print("ERROR. Check your:\n -connection\n -url is a YouTube url\n\nTry again.")
redo = main()
# Get the quality
list_quality = get_resolution(video)
for idx, ps in enumerate(list_quality):
print((idx + 1),".", ps)
# Ambil List Kualitas Video nya.
try:
print("Pilih Kualitas Video")
quality = int(input("Input nomornya aja : ")) - 1
except:
quality = 0
# Ambil Video Untuk Didownload
video_type = video.streams.filter(progressive = True, res=list_quality[quality]).first()
# Ambil Judul Video
title = video.title
# Menyiapkan Video untuk didownload
print ("Fetching: {}...".format(title))
global file_size
file_size = video_type.filesize
# Mulai Download Process
video_type.download(file_path())
print ("Siap Untuk Mendownload Video Berikutnya!.\n\n")
again = main()
def playlistDownload():
#Input
yt_url = input("Copy dan paste Playlist URL Mu: ")
print(yt_url)
print ("Mengakses URL PlayLIst di YouTube ...")
# Cari video dan akses callback didalamnya
try:
playlist = Playlist(yt_url)
except:
print("ERROR. Check your:\n -connection\n -url is a YouTube url\n\nTry again.")
redo = main()
for video in playlist:
# Ambil Judul Video
title = video.title
# Mulai Download Process
video.download(file_path())
print ("Siap Untuk Mendownload Video Berikutnya!.\n\n")
again = main()
def main():
print("Mau download video atau playlist?")
print("1. Video")
print("2. Playlist")
try:
select = int(input("Masukkan Nomor : "))
except:
print("Kamu salah pilih!")
main()
print("Video akan di save di : {}".format(file_path()))
if select == VIDEO:
videoDownload()
elif select == PLAYLIST:
playlistDownload()
else:
print("Kamu Salah pilih!")
main()
file_size = 0
if __name__ == "__main__":
main()