-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonvideodownloader.py
More file actions
83 lines (73 loc) · 2.4 KB
/
pythonvideodownloader.py
File metadata and controls
83 lines (73 loc) · 2.4 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
# import imp
from multiprocessing.connection import wait
import os
from pytube import Playlist, YouTube
import time
import shutil
def downloadplaylist():
link = input("\tEnter link: ")
try :
count = 0
p = Playlist(link)
print("\n\tFetching Details ...")
print("\t-----------------------------------\n")
# making a new folder with the title name
directory = p.title
parent_dir = "/home/teladmin/Desktop/Practice/Youtube Downloader"
path = os.path.join(parent_dir, directory)
if(os.path.exists(path)):
shutil.rmtree(path)
os.mkdir(path)
print("\tVideo Title : ", p.title)
ch = input("\tDo you wish to continue(y/n)? : ")
if(ch == 'y'):
for url in p.video_urls:
count = count+1
vid = YouTube(url)
vid = vid.streams.get_highest_resolution()
print("Downloading .. ", count," : ", YouTube(url).title)
vid.download(path)
print("\tDownload Complete !\n")
else:
return 0
except:
print("\n\nAn Error occured while connecting whith YouTube Servers", end="")
for i in range (0, 5):
time.sleep(1)
print(". ", end="")
def download():
link = input("\tEnter link: ")
try:
vid = YouTube(link)
print("\tVideo Title : ", vid.title)
ch = input("\tDo you wish to continue(y/n)? : ")
if(ch == 'y'):
vid = vid.streams.get_highest_resolution()
print("\tDownloading ", vid.title)
vid.download("/home/teladmin/Desktop/Practice/Youtube Downloader")
print("\tDownload Complete !")
return 0
else:
return 0
except:
print("\n\nAn Error occured while connecting whith YouTube Servers", end="")
for i in range (0, 3):
time.sleep(1)
print(". ", end="")
# driver code:
while(True):
choice = int(input('''\n\n
🆈 🆃 🅳 🅾 🆆 🅽 🅻 🅾 🅰 🅳 🅴 🆁
1. Download playlist
2. Download single video
0. Exit\n
Enter an option: '''))
if choice == 1:
downloadplaylist()
elif choice == 2:
download()
elif choice == 0:
print('\nThanks for using our services\n')
exit()
else:
print('\tInvalid choice')