forked from tuomaskivioja/3-Simple-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytDownloader.py
70 lines (62 loc) · 1.7 KB
/
ytDownloader.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
from pytube import YouTube
import os, time
def home():
print("\033[31mYoutube Video Downloader\033[0m")
print("1. Download Video \n2. See Download History")
inpt = input("> ").strip().lower()
if inpt == "1":
download()
elif inpt == "2":
history()
else:
print("Input not valid. You will directed to download.")
time.sleep(2)
os.system("clear")
download()
def download():
os.system("clear")
try:
url = input("Enter the YouTube Video URL: ")
yt = YouTube(url)
os.system("clear")
print("Video URL :", url)
print("Video Title:", yt.title)
print("Video Views:", yt.views)
print()
print("\033[32mVideo caught. Request the highest resolution...\033[0m")
yd = yt.streams.get_highest_resolution()
os.system("clear")
print("Video URL :", url)
print("Video Title:", yt.title)
print("Video Views:", yt.views)
print()
print(
"\033[32mThe highest resolution video has been obtained. Downloading Videos...\033[0m"
)
yd.download()
os.system("clear")
print("\033[32mDownload complete.\033[0m")
f = open("history.yt", "a+")
f.write(
f"\nVideo URL: {url}\nVideo Title: {yt.title}\nVideo Views: {yt.views}"
)
f.write("\n-----------------")
f.close()
time.sleep(2)
os.system("clear")
home()
except Exception as e:
print("An error occurred:", str(e))
time.sleep(2)
os.system("clear")
home()
def history():
os.system("clear")
f = open("history.yt", "r")
data = f.read()
print(data)
print()
exit = input("Press enter to exit. ")
os.system("clear")
home()
home()