fix: use venv python + yt-dlp cookies in telegram_bot

This commit is contained in:
Renato
2026-07-02 17:46:34 +02:00
parent 3afa1a522b
commit 8d3af05070
+14 -3
View File
@@ -22,6 +22,8 @@ load_dotenv()
BOT_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"] BOT_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
CHAT_ID = int(os.environ["TELEGRAM_CHAT_ID"]) CHAT_ID = int(os.environ["TELEGRAM_CHAT_ID"])
NEXTCLOUD_BASE = "/home/ren/nextcloud/html/data/renato97/files/viral_clips" 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 SCRIPT_DIR = Path(__file__).parent
queue = asyncio.Queue() queue = asyncio.Queue()
@@ -77,8 +79,17 @@ async def get_video_title(url: str) -> str:
print("[DEBUG] yt-dlp title timed out after 30s") print("[DEBUG] yt-dlp title timed out after 30s")
return "video" return "video"
except FileNotFoundError: except FileNotFoundError:
print("[DEBUG] yt-dlp command not found in PATH") print("[DEBUG] yt-dlp command not found. Trying venv yt-dlp...")
return "video" 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: except Exception as e:
print(f"[DEBUG] yt-dlp title failed: {e}") print(f"[DEBUG] yt-dlp title failed: {e}")
return "video" return "video"
@@ -132,7 +143,7 @@ async def process_video(bot, url: str):
print(f"[DEBUG] Spawning: {' '.join(cmd)}") print(f"[DEBUG] Spawning: {' '.join(cmd)}")
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
sys.executable, VENV_PYTHON,
"-u", *cmd, "-u", *cmd,
env=env, env=env,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,