Spaces:
Sleeping
Sleeping
Update bleep_that_sht/yt_download.py
Browse files- bleep_that_sht/yt_download.py +13 -23
bleep_that_sht/yt_download.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
-
from pytube import YouTube
|
2 |
-
|
|
|
3 |
import re
|
4 |
|
5 |
|
@@ -12,31 +13,20 @@ def is_valid_youtube_url(url: str) -> bool:
|
|
12 |
return re.match(pattern, url) is not None
|
13 |
|
14 |
|
15 |
-
def download_video(
|
16 |
-
url: str,
|
17 |
-
savepath: str,
|
18 |
-
my_proxies: dict = {}
|
19 |
-
) -> None:
|
20 |
try:
|
21 |
print("Downloading video from youtube...")
|
22 |
if is_valid_youtube_url(url):
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
)
|
32 |
-
.order_by("resolution")
|
33 |
-
.asc()
|
34 |
-
)
|
35 |
-
audio_video_itags = [v.itag for v in audio_video_streams]
|
36 |
-
first_choice_itag = audio_video_itags[0]
|
37 |
-
yt.streams.get_by_itag(first_choice_itag).download(filename=savepath)
|
38 |
print("...done!")
|
39 |
else:
|
40 |
raise ValueError(f"invalid input url: {url}")
|
41 |
except Exception as e:
|
42 |
-
raise ValueError(f"yt_download failed with exception {e}")
|
|
|
1 |
+
# from pytube import YouTube
|
2 |
+
|
3 |
+
import yt_dlp
|
4 |
import re
|
5 |
|
6 |
|
|
|
13 |
return re.match(pattern, url) is not None
|
14 |
|
15 |
|
16 |
+
def download_video(url: str, savepath: str, my_proxies: dict = {}) -> None:
|
|
|
|
|
|
|
|
|
17 |
try:
|
18 |
print("Downloading video from youtube...")
|
19 |
if is_valid_youtube_url(url):
|
20 |
+
ydl_opts = {
|
21 |
+
'format': 'bestvideo[height<=720]+bestaudio/best',
|
22 |
+
'merge_output_format': 'mp4',
|
23 |
+
'outtmpl': savepath,
|
24 |
+
}
|
25 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
26 |
+
ydl.download([url])
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
print("...done!")
|
29 |
else:
|
30 |
raise ValueError(f"invalid input url: {url}")
|
31 |
except Exception as e:
|
32 |
+
raise ValueError(f"yt_download failed with exception {e}")
|