Spaces:
Sleeping
Sleeping
Nikita Makarov
commited on
Commit
·
2c4e0c3
1
Parent(s):
fdd1b7e
Fix YouTube API key access in Modal proxy
Browse files- modal_proxy.py +6 -1
modal_proxy.py
CHANGED
|
@@ -26,6 +26,11 @@ def search_youtube(query: str, limit: int = 5) -> Dict[str, Any]:
|
|
| 26 |
try:
|
| 27 |
# YouTube Data API v3 search endpoint
|
| 28 |
url = "https://www.googleapis.com/youtube/v3/search"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
params = {
|
| 30 |
'part': 'snippet',
|
| 31 |
'q': f"{query} music",
|
|
@@ -33,7 +38,7 @@ def search_youtube(query: str, limit: int = 5) -> Dict[str, Any]:
|
|
| 33 |
'maxResults': limit,
|
| 34 |
'order': 'relevance',
|
| 35 |
'safeSearch': 'moderate',
|
| 36 |
-
'key':
|
| 37 |
}
|
| 38 |
|
| 39 |
response = requests.get(url, params=params, timeout=30)
|
|
|
|
| 26 |
try:
|
| 27 |
# YouTube Data API v3 search endpoint
|
| 28 |
url = "https://www.googleapis.com/youtube/v3/search"
|
| 29 |
+
# Get API key from Modal secret
|
| 30 |
+
api_key = os.environ.get("YOUTUBE_API_KEY", "")
|
| 31 |
+
if not api_key:
|
| 32 |
+
return {"success": False, "error": "YouTube API key not found in environment", "tracks": []}
|
| 33 |
+
|
| 34 |
params = {
|
| 35 |
'part': 'snippet',
|
| 36 |
'q': f"{query} music",
|
|
|
|
| 38 |
'maxResults': limit,
|
| 39 |
'order': 'relevance',
|
| 40 |
'safeSearch': 'moderate',
|
| 41 |
+
'key': api_key
|
| 42 |
}
|
| 43 |
|
| 44 |
response = requests.get(url, params=params, timeout=30)
|