Spaces:
Sleeping
Sleeping
chuanenlin
commited on
Commit
·
655df7a
1
Parent(s):
f36363b
Handle yt-dlp bot check
Browse files- whichframe.py +14 -3
whichframe.py
CHANGED
@@ -17,15 +17,26 @@ CACHED_DATA_PATH = "cached_data/"
|
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
model, preprocess = openai_clip.load("ViT-B/32", device=device)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def fetch_video(url):
|
21 |
try:
|
|
|
22 |
ydl_opts = {
|
23 |
'format': 'bestvideo[height<=360][ext=mp4]/best[height<=360]',
|
24 |
'quiet': True,
|
25 |
'no_warnings': True,
|
26 |
-
'
|
27 |
-
'
|
28 |
-
'
|
29 |
}
|
30 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
31 |
info = ydl.extract_info(url, download=False)
|
|
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
model, preprocess = openai_clip.load("ViT-B/32", device=device)
|
19 |
|
20 |
+
def export_cookies():
|
21 |
+
cookie_path = "youtube.com_cookies.txt"
|
22 |
+
if not os.path.exists(cookie_path):
|
23 |
+
with open(cookie_path, "w") as f:
|
24 |
+
f.write("# Netscape HTTP Cookie File\n")
|
25 |
+
f.write("# https://curl.haxx.se/rfc/cookie_spec.html\n")
|
26 |
+
f.write("# This is a generated file! Do not edit.\n\n")
|
27 |
+
f.write(".youtube.com\tTRUE\t/\tFALSE\t2147483647\tCONSENT\tYES+cb.20210328-17-p0.en+FX+{}\n")
|
28 |
+
return cookie_path
|
29 |
+
|
30 |
def fetch_video(url):
|
31 |
try:
|
32 |
+
cookie_path = export_cookies()
|
33 |
ydl_opts = {
|
34 |
'format': 'bestvideo[height<=360][ext=mp4]/best[height<=360]',
|
35 |
'quiet': True,
|
36 |
'no_warnings': True,
|
37 |
+
'cookies': cookie_path,
|
38 |
+
'extract_flat': False,
|
39 |
+
'no_check_certificates': True
|
40 |
}
|
41 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
42 |
info = ydl.extract_info(url, download=False)
|