Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,14 @@ import requests
|
|
9 |
import re
|
10 |
import yt_dlp
|
11 |
import logging
|
|
|
12 |
|
13 |
# Configure logging for debugging purposes
|
14 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
15 |
|
16 |
# Function to search YouTube videos using yt-dlp for better reliability
|
17 |
def youtube_search(query, max_results=10):
|
|
|
18 |
ydl_opts = {
|
19 |
'quiet': False, # Set to False to get more detailed output from yt-dlp
|
20 |
'logger': logging.getLogger(), # Use the logging module to capture yt-dlp logs
|
@@ -22,8 +24,12 @@ def youtube_search(query, max_results=10):
|
|
22 |
'noplaylist': True, # Avoid extracting playlists
|
23 |
'format': 'best',
|
24 |
}
|
25 |
-
search_url = f"ytsearch{max_results}:{query}"
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
logging.debug(f"Starting YouTube search for query: {query}")
|
28 |
|
29 |
try:
|
@@ -138,4 +144,4 @@ with gr.Blocks() as demo:
|
|
138 |
play_video_button.click(play_video, inputs=selected_video_link, outputs=video_output)
|
139 |
|
140 |
# Launch the Gradio interface
|
141 |
-
demo.launch()
|
|
|
9 |
import re
|
10 |
import yt_dlp
|
11 |
import logging
|
12 |
+
import os
|
13 |
|
14 |
# Configure logging for debugging purposes
|
15 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
16 |
|
17 |
# Function to search YouTube videos using yt-dlp for better reliability
|
18 |
def youtube_search(query, max_results=10):
|
19 |
+
cookies_file = "cookies.txt" # You need to provide this file with cookies exported from YouTube
|
20 |
ydl_opts = {
|
21 |
'quiet': False, # Set to False to get more detailed output from yt-dlp
|
22 |
'logger': logging.getLogger(), # Use the logging module to capture yt-dlp logs
|
|
|
24 |
'noplaylist': True, # Avoid extracting playlists
|
25 |
'format': 'best',
|
26 |
}
|
|
|
27 |
|
28 |
+
if os.path.exists(cookies_file):
|
29 |
+
ydl_opts['cookiefile'] = cookies_file
|
30 |
+
logging.debug("Using cookies for YouTube authentication.")
|
31 |
+
|
32 |
+
search_url = f"ytsearch{max_results}:{query}"
|
33 |
logging.debug(f"Starting YouTube search for query: {query}")
|
34 |
|
35 |
try:
|
|
|
144 |
play_video_button.click(play_video, inputs=selected_video_link, outputs=video_output)
|
145 |
|
146 |
# Launch the Gradio interface
|
147 |
+
demo.launch()
|