Spaces:
Configuration error
Configuration error
Update app.py
Browse files135 unmodified lines136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167135 unmodified linesstream_url = url_or_pathif "youtube.com" in url_or_path or "youtu.be" in url_or_path:ydl_opts = {'format': 'best','quiet': True,'no_warnings': True,'live_from_start': False,'source_address': '0.0.0.0'}try:with yt_dlp.YoutubeDL(ydl_opts) as ydl:info = ydl.extract_info(url_or_path, download=False)stream_url = info.get('url') or info.get('manifest_url')print(f"โ Extracted Stream URL: {stream_url[:60] if stream_url else 'None'}...")except Exception as e:print(f"โ ืฉืืืื ืืืืืืฅ ืืงืืฉืืจ ื-YouTube: {e}")return False, f"ืฉืืืื ืืืืืืฅ ืืืืืื: {e}"self.cap = cv2.VideoCapture(stream_url)if not self.cap.isOpened():return False, "ืื ื ืืชื ืืคืชืื ืืช ืืืืืื ื-OpenCV"self.is_running = TrueThread(target=self._capture_loop, daemon=True).start()Thread(target=self._yolo_loop, daemon=True).start()Thread(target=self._socket_emit_loop, daemon=True).start()return True, "ืืืจืื ืืืคืขืื ืืืฆืืื"def _capture_loop(self):135 unmodified lines136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173135 unmodified linesstream_url = url_or_pathif "youtube.com" in url_or_path or "youtu.be" in url_or_path:# ืืืืจืืช ืขืงืืคืช ืืกืืืืช ืืฉืจืช (User-Agent + ืืขืงืฃ ืคืืจืื)ydl_opts = {'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best','quiet': True,'no_warnings': True,'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36','nocheckcertificate': True,}try:print(f"๐ ืื ืกื ืืืืฅ ืืืืื ื-YouTube: {url_or_path}")with yt_dlp.YoutubeDL(ydl_opts) as ydl:info = ydl.extract_info(url_or_path, download=False)stream_url = info.get('url') or info.get('manifest_url')print(f"โ ืงืืฉืืจ ืืืืื ืืืืฅ ืืืฆืืื!")except Exception as e:print(f"โ ืฉืืืื ืืืืืืฅ ืืงืืฉืืจ ื-YouTube: {e}")return False, f"ืืืืืื ืืกื ืืช ืืฉืจืช: {e}"# ื ืืกืืื ืคืชืืืช ืืืืืื ืืจื OpenCVself.cap = cv2.VideoCapture(stream_url)if not self.cap.isOpened():print("โ OpenCV ื ืืฉื ืืคืชืืืช ืืืจื.")return False, "ืื ื ืืชื ืืคืชืื ืืช ืืืืืื ื-OpenCV"self.is_running = Trueself.is_paused = FalseThread(target=self._capture_loop, daemon=True).start()Thread(target=self._yolo_loop, daemon=True).start()Thread(target=self._socket_emit_loop, daemon=True).start()print("๐ ืืืจืืช ืืืืืื ืืืื ืืืฆืืื!")return True, "ืืืจืื ืืืคืขืื ืืืฆืืื"def _capture_loop(self):
app.py+11-5