Spaces:
Running
Running
Ahmed Mostafa
feat: implement multi-provider YouTube transcript downloader and corresponding API endpoints for notes processing
cbed3ed | import subprocess | |
| import logging | |
| import time | |
| import urllib.request | |
| from pathlib import Path | |
| import platform | |
| from pathlib import Path | |
| logger = logging.getLogger(__name__) | |
| # Search for the POT server script in several locations | |
| _POSSIBLE_PATHS = [ | |
| Path("/opt/bgutil-provider/server/build/main.js"), | |
| Path("./bgutil-provider/server/build/main.js"), | |
| Path("C:/bgutil-provider/server/build/main.js"), | |
| ] | |
| def _get_server_path(): | |
| for p in _POSSIBLE_PATHS: | |
| if p.exists(): | |
| return p | |
| return None | |
| class POTServer: | |
| def __init__(self): | |
| self._proc = None | |
| def start(self): | |
| server_path = _get_server_path() | |
| if not server_path: | |
| logger.error("❌ POT server script not found in any of the expected locations!") | |
| return False | |
| logger.info(f"🚀 Starting Node.js POT solver from {server_path}...") | |
| self._proc = subprocess.Popen(["node", str(server_path)]) | |
| # انتظر ثواني يتأكد إنه اشتغل | |
| time.sleep(5) | |
| return True | |
| def stop(self): | |
| if self._proc: | |
| self._proc.terminate() | |
| self._proc = None | |
| logger.info("🛑 POT server stopped.") | |
| def is_running(self): | |
| return self._proc is not None and self._proc.poll() is None | |
| pot_server = POTServer() |