-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathscript.py
More file actions
57 lines (45 loc) · 1.27 KB
/
script.py
File metadata and controls
57 lines (45 loc) · 1.27 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
import os
import sys
import pafy
import requests
def get_inp():
url = input("Enter a YouTube video link: ")
try:
if (url[:24] != "https://www.youtube.com/") or requests.get(
url
).status_code != 200:
sys.exit()
except:
print(
"Enter a valid link, make sure it starts with 'https://www.youtube.com/'\nTerminating Program."
)
sys.exit()
return url
def show_details(url):
global vid
global best
vid = pafy.new(url)
best = vid.getbest(preftype="mp4")
print(
f"Title: {vid.title}\nChannel: {vid.author}\nDuration: {vid.duration}\nBest Resolution: {best.resolution}"
)
def save_vid():
print("Downloading video in the current direcotry...")
best.download()
def save_audio():
print("Downloading audio in the current direcotry...")
vid.getbestaudio().download()
def save():
task = input("\nSave Video, Audio, Both or None(v,a,b,n): ")
if task == "v":
save_vid()
elif task == "a":
save_audio()
elif task == "b":
save_vid()
save_audio()
elif task != "n":
print("Incorrect input")
if __name__ == "__main__":
show_details(get_inp())
save()