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
+13 -2
View File
@@ -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,7 +79,16 @@ 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")
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}")
@@ -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,