Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,12 +24,14 @@ import sys
|
|
| 24 |
from enum import Enum
|
| 25 |
from typing import Any, Dict, List, Optional, Tuple
|
| 26 |
|
|
|
|
| 27 |
import cv2
|
| 28 |
import gradio as gr
|
| 29 |
import innertube
|
| 30 |
import numpy as np
|
| 31 |
from PIL import Image
|
| 32 |
from ultralytics import YOLO
|
|
|
|
| 33 |
import yt_dlp
|
| 34 |
|
| 35 |
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
@@ -90,7 +92,7 @@ class SearchService:
|
|
| 90 |
|
| 91 |
@staticmethod
|
| 92 |
def get_stream(youtube_url: str) -> Optional[str]:
|
| 93 |
-
"""Retrieves the livestream URL for a given YouTube video URL using yt-dlp.
|
| 94 |
|
| 95 |
:param youtube_url: The URL of the YouTube video.
|
| 96 |
:type youtube_url: str
|
|
@@ -103,11 +105,14 @@ class SearchService:
|
|
| 103 |
'no_warnings': True,
|
| 104 |
'force_generic_extractor': False,
|
| 105 |
'skip_download': True,
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
try:
|
| 108 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 109 |
info_dict = ydl.extract_info(youtube_url, download=False)
|
| 110 |
if info_dict.get('is_live'):
|
|
|
|
| 111 |
live_url = info_dict.get('url')
|
| 112 |
if live_url:
|
| 113 |
logging.debug(f"Found livestream URL: {live_url}")
|
|
@@ -127,7 +132,7 @@ INITIAL_STREAMS = SearchService.search("world live cams", SearchFilter.LIVE)
|
|
| 127 |
class LiveYouTubeObjectDetector:
|
| 128 |
def __init__(self):
|
| 129 |
logging.getLogger().setLevel(logging.DEBUG)
|
| 130 |
-
self.model = YOLO("
|
| 131 |
self.streams = INITIAL_STREAMS
|
| 132 |
|
| 133 |
# Gradio UI
|
|
@@ -241,4 +246,4 @@ class LiveYouTubeObjectDetector:
|
|
| 241 |
app.queue().launch(show_api=False, debug=True)
|
| 242 |
|
| 243 |
if __name__ == "__main__":
|
| 244 |
-
LiveYouTubeObjectDetector().render()
|
|
|
|
| 24 |
from enum import Enum
|
| 25 |
from typing import Any, Dict, List, Optional, Tuple
|
| 26 |
|
| 27 |
+
import os
|
| 28 |
import cv2
|
| 29 |
import gradio as gr
|
| 30 |
import innertube
|
| 31 |
import numpy as np
|
| 32 |
from PIL import Image
|
| 33 |
from ultralytics import YOLO
|
| 34 |
+
|
| 35 |
import yt_dlp
|
| 36 |
|
| 37 |
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
|
|
| 92 |
|
| 93 |
@staticmethod
|
| 94 |
def get_stream(youtube_url: str) -> Optional[str]:
|
| 95 |
+
"""Retrieves the livestream URL for a given YouTube video URL using yt-dlp with cookies.
|
| 96 |
|
| 97 |
:param youtube_url: The URL of the YouTube video.
|
| 98 |
:type youtube_url: str
|
|
|
|
| 105 |
'no_warnings': True,
|
| 106 |
'force_generic_extractor': False,
|
| 107 |
'skip_download': True,
|
| 108 |
+
# Include the cookies file
|
| 109 |
+
'cookiefile': 'cookies.txt',
|
| 110 |
}
|
| 111 |
try:
|
| 112 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 113 |
info_dict = ydl.extract_info(youtube_url, download=False)
|
| 114 |
if info_dict.get('is_live'):
|
| 115 |
+
# Get the live stream URL
|
| 116 |
live_url = info_dict.get('url')
|
| 117 |
if live_url:
|
| 118 |
logging.debug(f"Found livestream URL: {live_url}")
|
|
|
|
| 132 |
class LiveYouTubeObjectDetector:
|
| 133 |
def __init__(self):
|
| 134 |
logging.getLogger().setLevel(logging.DEBUG)
|
| 135 |
+
self.model = YOLO("yolov8n.pt")
|
| 136 |
self.streams = INITIAL_STREAMS
|
| 137 |
|
| 138 |
# Gradio UI
|
|
|
|
| 246 |
app.queue().launch(show_api=False, debug=True)
|
| 247 |
|
| 248 |
if __name__ == "__main__":
|
| 249 |
+
LiveYouTubeObjectDetector().render()
|