Delanoe Pirard commited on
Commit
6386cd1
·
1 Parent(s): fe3c4d3
Files changed (2) hide show
  1. agents/video_analyzer_agent.py +21 -1
  2. get_cookie.py +0 -1
agents/video_analyzer_agent.py CHANGED
@@ -16,6 +16,8 @@ from llama_index.llms.google_genai import GoogleGenAI
16
  from tqdm import tqdm
17
  from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
18
 
 
 
19
  # ---------------------------------------------------------------------------
20
  # Environment setup & logging
21
  # ---------------------------------------------------------------------------
@@ -106,13 +108,31 @@ def download_video_and_analyze(video_url: str) -> str:
106
  llm_model_name = os.getenv("VIDEO_ANALYZER_LLM_MODEL", "models/gemini-1.5-pro")
107
  gemini_api_key = os.getenv("GEMINI_API_KEY")
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  ydl_opts = {
110
  'format': 'best',
111
  'outtmpl': os.path.join("downloaded_videos", 'temp_video.%(ext)s'),
112
  'quiet': True,
113
  'extract_flat': True,
114
  'ignoreerrors': True,
115
- "cookies": os.getenv("YT_COOKIE", "")
 
 
116
  }
117
 
118
  with yt_dlp.YoutubeDL(ydl_opts) as ydl_download:
 
16
  from tqdm import tqdm
17
  from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
18
 
19
+ from get_cookie import cookie_txt
20
+
21
  # ---------------------------------------------------------------------------
22
  # Environment setup & logging
23
  # ---------------------------------------------------------------------------
 
108
  llm_model_name = os.getenv("VIDEO_ANALYZER_LLM_MODEL", "models/gemini-1.5-pro")
109
  gemini_api_key = os.getenv("GEMINI_API_KEY")
110
 
111
+ cookie_txt = os.getenv("YT_COOKIE", "")
112
+
113
+ cookies = {}
114
+ for line in cookie_txt.splitlines():
115
+ line = line.strip()
116
+ if not line or line.startswith('#'):
117
+ continue
118
+ parts = line.split('\t')
119
+ # NetScape format: domain, flag, path, secure, expiration, name, value
120
+ if len(parts) >= 7:
121
+ name = parts[5]
122
+ value = parts[6]
123
+ cookies[name] = value
124
+
125
+ cookie_header = '; '.join(f"{k}={v}" for k, v in cookies.items())
126
+
127
  ydl_opts = {
128
  'format': 'best',
129
  'outtmpl': os.path.join("downloaded_videos", 'temp_video.%(ext)s'),
130
  'quiet': True,
131
  'extract_flat': True,
132
  'ignoreerrors': True,
133
+ "headers": {
134
+ "Cookie": cookie_header
135
+ },
136
  }
137
 
138
  with yt_dlp.YoutubeDL(ydl_opts) as ydl_download:
get_cookie.py CHANGED
@@ -35,4 +35,3 @@ def export_youtube_cookies_netscape(domain: str = "youtube.com") -> str:
35
  tmp.flush()
36
  return tmp.name
37
 
38
- print(export_youtube_cookies_netscape())
 
35
  tmp.flush()
36
  return tmp.name
37