-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
48 lines (40 loc) · 1.72 KB
/
demo.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
from pytube import YouTube
from colorama import init, Fore
def on_complete(stream, filepath):
print('download complete')
print(filepath)
def on_progress(stream, chunk, bytes_remaining ):
progress_str = f'{round( 100 - (bytes_remaining / stream.filesize * 100),2)}%'
print(progress_str)
init()
#link = input('Youtube link: ')
link = 'https://www.youtube.com/watch?v=3_CpaZfn-mI'
video_obj = YouTube(link, on_complete_callback = on_complete, on_progress_callback = on_progress)
# video information
print(Fore.RED + f'title: \033[39m {video_obj.title}')
print(Fore.RED + f'length: \033[39m {(video_obj.length / 60.2)} minutes ')
print(Fore.RED + f'views: \033[39m {(video_obj.views / 1000000)} milion' )
print(Fore.RED + f'author: \033[39m n {video_obj.author}')
# download
print(Fore.RED + 'download:' +
Fore.GREEN + '(b)est \033[39m| ' +
Fore.YELLOW + '(w)orst \033[39m| ' +
Fore.BLUE + '(a)udio \033[39m| (e)xit')
download_choice = input('Choice: ')
#
#match download_choice:
# case 'b':
# video_obj.streams.get_highest_resolution().download(r'\home\egmj\Projects\youtube-download')
# case 'w':
# video_obj.streams.get_worst_resolution().download(r'\home\egmj\Projects\youtube-download')
# case 'a':
# video_obj.streams.get_audio_only().download(r'\home\egmj\Projects\youtube-download')
#
if download_choice == 'b':
video_obj.streams.get_highest_resolution().download(r'/home/egmj/Projects/youtube-download')
elif download_choice == 'w':
video_obj.streams.get_lowest_resolution().download(r'/home/egmj/Projects/youtube-download')
elif download_choice == 'a':
video_obj.streams.get_audio_only().download(r'/home/egmj/Projects/youtube-download')
elif download_choice == 'e':
quit()