RCaz commited on
Commit
bdfdf41
·
verified ·
1 Parent(s): 4d6c9ef

handles cookies for yt_dlp using firefox browser

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -17,6 +17,26 @@ def download_video(url, request):
17
  if not os.path.exists(output_path):
18
  os.mkdir(output_path)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # get video
21
  ydl_opts_video = {
22
  'format': 'worst[ext=mp4]',
 
17
  if not os.path.exists(output_path):
18
  os.mkdir(output_path)
19
 
20
+ # get cookies
21
+ export_cookies_path = "/cache/exported_cookies.txt"
22
+ try:
23
+ ydl_opts_export_cookies = {
24
+ 'cookiesfrombrowser': 'firefox', # Try firefox, or 'chrome', 'edge', etc.
25
+ 'cookiefile': export_cookies_path,
26
+ 'quiet': True,
27
+ }
28
+ print(f"Attempting to export cookies from Firefox to {export_cookies_path}...")
29
+ with yt_dlp.YoutubeDL(ydl_opts_export_cookies) as ydl:
30
+ # A dummy URL is often sufficient for cookie export
31
+ ydl.extract_info("https://www.youtube.com", download=False)
32
+ print("Cookies exported successfully (if Firefox was installed and logged in).")
33
+
34
+ except yt_dlp.utils.DownloadError as e:
35
+ print(f"Could not export cookies from browser: {e}")
36
+ print("Please ensure a supported browser is installed and logged in, or manually create a 'cookies.txt' file.")
37
+
38
+
39
+
40
  # get video
41
  ydl_opts_video = {
42
  'format': 'worst[ext=mp4]',