Spaces:
Sleeping
Sleeping
replace yt-dlp with cobalt.tools
Browse files- app.py +35 -1
- requirements.txt +0 -1
app.py
CHANGED
@@ -503,12 +503,46 @@ def get_youtube_stream_url(youtube_url):
|
|
503 |
f"Error: Unable to process the YouTube URL. {str(e)}")
|
504 |
return None
|
505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
# If a YouTube URL is provided, process the video
|
508 |
if youtube_url:
|
509 |
analysis_init() # Initialize the analysis UI
|
510 |
|
511 |
-
stream_url =
|
|
|
512 |
|
513 |
if stream_url:
|
514 |
process_video(stream_url) # Process the video
|
|
|
503 |
f"Error: Unable to process the YouTube URL. {str(e)}")
|
504 |
return None
|
505 |
|
506 |
+
# Function to get video URL using Cobalt API
|
507 |
+
|
508 |
+
|
509 |
+
def get_cobalt_video_url(youtube_url):
|
510 |
+
cobalt_api_url = "https://api.cobalt.tools/api/json"
|
511 |
+
headers = {
|
512 |
+
"Accept": "application/json",
|
513 |
+
"Content-Type": "application/json"
|
514 |
+
}
|
515 |
+
payload = {
|
516 |
+
"url": youtube_url,
|
517 |
+
"vCodec": "h264",
|
518 |
+
"vQuality": "720",
|
519 |
+
"aFormat": "mp3",
|
520 |
+
"isAudioOnly": False
|
521 |
+
}
|
522 |
+
|
523 |
+
try:
|
524 |
+
response = requests.post(cobalt_api_url, headers=headers, json=payload)
|
525 |
+
response.raise_for_status()
|
526 |
+
data = response.json()
|
527 |
+
|
528 |
+
if data['status'] == 'stream':
|
529 |
+
return data['url']
|
530 |
+
elif data['status'] == 'redirect':
|
531 |
+
return data['url']
|
532 |
+
else:
|
533 |
+
yt_error.error(f"Error: {data['text']}")
|
534 |
+
return None
|
535 |
+
except requests.exceptions.RequestException as e:
|
536 |
+
yt_error.error(f"Error: Unable to process the YouTube URL. {str(e)}")
|
537 |
+
return None
|
538 |
+
|
539 |
|
540 |
# If a YouTube URL is provided, process the video
|
541 |
if youtube_url:
|
542 |
analysis_init() # Initialize the analysis UI
|
543 |
|
544 |
+
stream_url = get_cobalt_video_url(youtube_url)
|
545 |
+
# stream_url = get_youtube_stream_url(youtube_url)
|
546 |
|
547 |
if stream_url:
|
548 |
process_video(stream_url) # Process the video
|
requirements.txt
CHANGED
@@ -6,5 +6,4 @@ setuptools
|
|
6 |
streamlit_webrtc
|
7 |
twilio
|
8 |
ultralytics
|
9 |
-
yt-dlp
|
10 |
watchdog
|
|
|
6 |
streamlit_webrtc
|
7 |
twilio
|
8 |
ultralytics
|
|
|
9 |
watchdog
|