-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuckyoutube.py
43 lines (34 loc) · 1.48 KB
/
fuckyoutube.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
import re
from pytube import YouTube
def get_direct_link(youtube_url, selected_quality=None):
try:
yt = YouTube(youtube_url)
streams = yt.streams.filter(progressive=True, file_extension="mp4")
if not streams:
return "could not find anything"
if selected_quality:
selected_streams = [s for s in streams if selected_quality in s.resolution]
if selected_streams:
stream = selected_streams[0]
else:
return f"selected quality '{selected_quality}' not available. available resolutions: {', '.join([s.resolution for s in streams])}"
else:
stream = yt.streams.get_highest_resolution()
direct_link = stream.url
return direct_link
except Exception as e:
return str(e)
if __name__ == "__main__":
youtube_url = input("url: ")
yt = YouTube(youtube_url)
available_qualities = [s.resolution for s in yt.streams.filter(progressive=True, file_extension="mp4")]
print("available resolutions:")
for quality in available_qualities:
print(quality)
selected_quality = input("enter the desired resolution (or press ENTER for the highest resolution): ")
direct_link = get_direct_link(youtube_url, selected_quality)
if direct_link:
print("direct link:\n")
print(direct_link)
else:
print("could not retrieve")