From 8d3af05070a2897787c98295586d005d46d183c0 Mon Sep 17 00:00:00 2001 From: Renato Date: Thu, 2 Jul 2026 17:46:34 +0200 Subject: [PATCH] fix: use venv python + yt-dlp cookies in telegram_bot --- openshorts/telegram_bot.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/openshorts/telegram_bot.py b/openshorts/telegram_bot.py index 31a6a71..3f88712 100644 --- a/openshorts/telegram_bot.py +++ b/openshorts/telegram_bot.py @@ -22,6 +22,8 @@ load_dotenv() BOT_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"] CHAT_ID = int(os.environ["TELEGRAM_CHAT_ID"]) NEXTCLOUD_BASE = "/home/ren/nextcloud/html/data/renato97/files/viral_clips" +VENV_PYTHON = "/home/ren/viral/venv/bin/python3" +COOKIES = "/home/ren/yt/cookies.txt" SCRIPT_DIR = Path(__file__).parent queue = asyncio.Queue() @@ -77,8 +79,17 @@ async def get_video_title(url: str) -> str: print("[DEBUG] yt-dlp title timed out after 30s") return "video" except FileNotFoundError: - print("[DEBUG] yt-dlp command not found in PATH") - return "video" + print("[DEBUG] yt-dlp command not found. Trying venv yt-dlp...") + try: + r = await asyncio.to_thread( + subprocess.run, + [VENV_PYTHON, "-m", "yt_dlp", "--cookies", COOKIES, "--print", "title", url], + capture_output=True, text=True, timeout=30, + ) + return r.stdout.strip() or "video" + except Exception as e2: + print(f"[DEBUG] venv yt-dlp also failed: {e2}") + return "video" except Exception as e: print(f"[DEBUG] yt-dlp title failed: {e}") return "video" @@ -132,7 +143,7 @@ async def process_video(bot, url: str): print(f"[DEBUG] Spawning: {' '.join(cmd)}") proc = await asyncio.create_subprocess_exec( - sys.executable, + VENV_PYTHON, "-u", *cmd, env=env, stdout=asyncio.subprocess.PIPE,