prasanth.thangavel commited on
Commit
a3b8611
·
1 Parent(s): de0b0bd

Add firefox cookies to handle bot issue

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -1,16 +1,28 @@
1
  import gradio as gr
2
  from yt_dlp import YoutubeDL
3
  import os
 
4
  import tempfile
5
  import shutil
6
  from pathlib import Path
7
 
 
 
 
 
 
 
 
 
 
 
8
  def download_for_browser(url, mode='audio', quality='high'):
9
  if not url:
10
  return None, "Please enter a valid URL"
11
 
12
  # Create temporary directory that persists until file is served
13
  temp_dir = Path(tempfile.mkdtemp())
 
14
 
15
  try:
16
  # Configure download options
@@ -40,6 +52,9 @@ def download_for_browser(url, mode='audio', quality='high'):
40
  'merge_output_format': 'mp4'
41
  })
42
 
 
 
 
43
  # Download file
44
  with YoutubeDL(opts) as ydl:
45
  info = ydl.extract_info(url, download=True)
 
1
  import gradio as gr
2
  from yt_dlp import YoutubeDL
3
  import os
4
+ from pathlib import Path
5
  import tempfile
6
  import shutil
7
  from pathlib import Path
8
 
9
+ def get_cookies():
10
+ """Get or create cookie file path"""
11
+ with open('firefox-cookies.txt', 'r+') as fh:
12
+ cookies = fh.read()
13
+ return cookies
14
+
15
+ def get_cookies_path():
16
+ """Get cookie file path"""
17
+ return "./firefox-cookies.txt"
18
+
19
  def download_for_browser(url, mode='audio', quality='high'):
20
  if not url:
21
  return None, "Please enter a valid URL"
22
 
23
  # Create temporary directory that persists until file is served
24
  temp_dir = Path(tempfile.mkdtemp())
25
+ cookiefile = get_cookies_path()
26
 
27
  try:
28
  # Configure download options
 
52
  'merge_output_format': 'mp4'
53
  })
54
 
55
+ # Add cookies
56
+ opts["cookiefile"] = cookiefile
57
+
58
  # Download file
59
  with YoutubeDL(opts) as ydl:
60
  info = ydl.extract_info(url, download=True)