chuanenlin commited on
Commit
f36363b
·
1 Parent(s): 1a29f57

Handle yt-dlp bot check

Browse files
Files changed (1) hide show
  1. whichframe.py +5 -22
whichframe.py CHANGED
@@ -19,35 +19,18 @@ model, preprocess = openai_clip.load("ViT-B/32", device=device)
19
 
20
  def fetch_video(url):
21
  try:
22
- browsers = ['chrome', 'firefox', 'edge', 'safari', 'opera']
23
- for browser in browsers:
24
- try:
25
- ydl_opts = {
26
- 'format': 'bestvideo[height<=360][ext=mp4]',
27
- 'quiet': True,
28
- 'no_warnings': True,
29
- 'cookiesfrombrowser': (browser,),
30
- }
31
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
32
- info = ydl.extract_info(url, download=False)
33
- duration = info.get('duration', 0)
34
- if duration >= 300: # 5 minutes
35
- st.error("Please find a YouTube video shorter than 5 minutes.")
36
- st.stop()
37
- video_url = info['url']
38
- return None, video_url
39
- except Exception:
40
- continue
41
-
42
  ydl_opts = {
43
- 'format': 'bestvideo[height<=360][ext=mp4]',
44
  'quiet': True,
45
  'no_warnings': True,
 
 
 
46
  }
47
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
48
  info = ydl.extract_info(url, download=False)
49
  duration = info.get('duration', 0)
50
- if duration >= 300:
51
  st.error("Please find a YouTube video shorter than 5 minutes.")
52
  st.stop()
53
  video_url = info['url']
 
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
+ 'extract_flat': True,
27
+ 'no_check_certificates': True,
28
+ 'force_generic_extractor': True
29
  }
30
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
31
  info = ydl.extract_info(url, download=False)
32
  duration = info.get('duration', 0)
33
+ if duration >= 300: # 5 minutes
34
  st.error("Please find a YouTube video shorter than 5 minutes.")
35
  st.stop()
36
  video_url = info['url']