sheikhed commited on
Commit
ea5cc73
·
verified ·
1 Parent(s): a349b93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -2,6 +2,17 @@ import gradio as gr
2
  import yt_dlp
3
  import os
4
  import re
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  def sanitize_filename(title):
7
  """Remove invalid characters from filename"""
@@ -13,6 +24,14 @@ def download_audio(url, output_dir="downloads"):
13
  if not os.path.exists(output_dir):
14
  os.makedirs(output_dir)
15
 
 
 
 
 
 
 
 
 
16
  # Configure yt-dlp options
17
  ydl_opts = {
18
  'format': 'bestaudio/best',
@@ -22,6 +41,7 @@ def download_audio(url, output_dir="downloads"):
22
  'preferredquality': '192',
23
  }],
24
  'outtmpl': os.path.join(output_dir, '%(title)s.%(ext)s'),
 
25
  'verbose': True
26
  }
27
 
@@ -80,7 +100,7 @@ iface = gr.Interface(
80
  inputs=gr.Textbox(label="YouTube URL", placeholder="Enter YouTube video URL here..."),
81
  outputs=gr.Textbox(label="Status"),
82
  title="YouTube to MP3 Downloader",
83
- description="Enter a YouTube URL to download the audio as MP3",
84
  examples=[["https://www.youtube.com/watch?v=dQw4w9WgXcQ"]],
85
  theme=gr.themes.Base()
86
  )
 
2
  import yt_dlp
3
  import os
4
  import re
5
+ from pathlib import Path
6
+
7
+ def get_browser_cookies():
8
+ """Get cookies from browser - tries Chrome first, then Firefox, then Edge"""
9
+ browsers = ['chrome', 'firefox', 'edge']
10
+ for browser in browsers:
11
+ try:
12
+ return browser
13
+ except Exception:
14
+ continue
15
+ return None
16
 
17
  def sanitize_filename(title):
18
  """Remove invalid characters from filename"""
 
24
  if not os.path.exists(output_dir):
25
  os.makedirs(output_dir)
26
 
27
+ # Get browser cookies
28
+ browser = get_browser_cookies()
29
+ if not browser:
30
+ return {
31
+ "status": "error",
32
+ "message": "No supported browser found. Please ensure Chrome, Firefox, or Edge is installed."
33
+ }
34
+
35
  # Configure yt-dlp options
36
  ydl_opts = {
37
  'format': 'bestaudio/best',
 
41
  'preferredquality': '192',
42
  }],
43
  'outtmpl': os.path.join(output_dir, '%(title)s.%(ext)s'),
44
+ 'cookiesfrombrowser': (browser,), # Add browser cookies
45
  'verbose': True
46
  }
47
 
 
100
  inputs=gr.Textbox(label="YouTube URL", placeholder="Enter YouTube video URL here..."),
101
  outputs=gr.Textbox(label="Status"),
102
  title="YouTube to MP3 Downloader",
103
+ description="Enter a YouTube URL to download the audio as MP3. Make sure you're logged into YouTube in Chrome, Firefox, or Edge.",
104
  examples=[["https://www.youtube.com/watch?v=dQw4w9WgXcQ"]],
105
  theme=gr.themes.Base()
106
  )