fix: async get_video_title + debug prints in telegram_bot
This commit is contained in:
+30
-11
@@ -65,14 +65,22 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
await update.message.reply_text(f"⏳ Encolado ({qsize + 1}º en cola).")
|
await update.message.reply_text(f"⏳ Encolado ({qsize + 1}º en cola).")
|
||||||
|
|
||||||
|
|
||||||
def get_video_title(url: str) -> str:
|
async def get_video_title(url: str) -> str:
|
||||||
try:
|
try:
|
||||||
r = subprocess.run(
|
r = await asyncio.to_thread(
|
||||||
|
subprocess.run,
|
||||||
["yt-dlp", "--print", "title", url],
|
["yt-dlp", "--print", "title", url],
|
||||||
capture_output=True, text=True, timeout=30,
|
capture_output=True, text=True, timeout=30,
|
||||||
)
|
)
|
||||||
return r.stdout.strip()
|
return r.stdout.strip()
|
||||||
except Exception:
|
except subprocess.TimeoutExpired:
|
||||||
|
print("[DEBUG] yt-dlp title timed out after 30s")
|
||||||
|
return "video"
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("[DEBUG] yt-dlp command not found in PATH")
|
||||||
|
return "video"
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[DEBUG] yt-dlp title failed: {e}")
|
||||||
return "video"
|
return "video"
|
||||||
|
|
||||||
|
|
||||||
@@ -94,11 +102,16 @@ async def process_queue(bot):
|
|||||||
|
|
||||||
|
|
||||||
async def process_video(bot, url: str):
|
async def process_video(bot, url: str):
|
||||||
title = get_video_title(url)
|
print(f"[DEBUG] process_video: url={url[:80]}")
|
||||||
|
|
||||||
|
title = await get_video_title(url)
|
||||||
|
print(f"[DEBUG] title={title}")
|
||||||
|
|
||||||
safe = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:80]
|
safe = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:80]
|
||||||
folder = f"{safe}_{datetime.now():%Y-%m-%d}"
|
folder = f"{safe}_{datetime.now():%Y-%m-%d}"
|
||||||
target = f"{NEXTCLOUD_BASE}/{folder}"
|
target = f"{NEXTCLOUD_BASE}/{folder}"
|
||||||
os.makedirs(target, exist_ok=True)
|
os.makedirs(target, exist_ok=True)
|
||||||
|
print(f"[DEBUG] NEXTCLOUD_TARGET={target}")
|
||||||
|
|
||||||
msg = await bot.send_message(CHAT_ID, "🚀 Descargando...")
|
msg = await bot.send_message(CHAT_ID, "🚀 Descargando...")
|
||||||
|
|
||||||
@@ -111,14 +124,16 @@ async def process_video(bot, url: str):
|
|||||||
last_text = ""
|
last_text = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
cmd = [
|
||||||
|
str(SCRIPT_DIR / "main.py"),
|
||||||
|
"-u", url,
|
||||||
|
"-o", temp_dir,
|
||||||
|
]
|
||||||
|
print(f"[DEBUG] Spawning: {' '.join(cmd)}")
|
||||||
|
|
||||||
proc = await asyncio.create_subprocess_exec(
|
proc = await asyncio.create_subprocess_exec(
|
||||||
sys.executable,
|
sys.executable,
|
||||||
"-u",
|
"-u", *cmd,
|
||||||
str(SCRIPT_DIR / "main.py"),
|
|
||||||
"-u",
|
|
||||||
url,
|
|
||||||
"-o",
|
|
||||||
temp_dir,
|
|
||||||
env=env,
|
env=env,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT,
|
stderr=asyncio.subprocess.STDOUT,
|
||||||
@@ -128,6 +143,7 @@ async def process_video(bot, url: str):
|
|||||||
line = raw.decode("utf-8", errors="replace").strip()
|
line = raw.decode("utf-8", errors="replace").strip()
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
|
print(f"[DEBUG] stdout: {line[:100]}")
|
||||||
|
|
||||||
text = None
|
text = None
|
||||||
if "Transcribing" in line:
|
if "Transcribing" in line:
|
||||||
@@ -137,13 +153,15 @@ async def process_video(bot, url: str):
|
|||||||
elif m := re.search(r"Found\s+(\d+)\s+viral", line, re.IGNORECASE):
|
elif m := re.search(r"Found\s+(\d+)\s+viral", line, re.IGNORECASE):
|
||||||
total_clips = int(m.group(1))
|
total_clips = int(m.group(1))
|
||||||
text = f"🔥 Encontrados {total_clips} clips"
|
text = f"🔥 Encontrados {total_clips} clips"
|
||||||
elif m := re.search(r"\bClip\s+(\d+)\]\s+Starting", line):
|
elif m := re.search(r"\[Clip\s+(\d+)\]\s+Starting", line):
|
||||||
cur_clip = int(m.group(1))
|
cur_clip = int(m.group(1))
|
||||||
text = f"🎬 Clip {cur_clip}/?: reencuadrando + subs..."
|
text = f"🎬 Clip {cur_clip}/?: reencuadrando + subs..."
|
||||||
elif "Normalizing" in line and cur_clip > 0:
|
elif "Normalizing" in line and cur_clip > 0:
|
||||||
text = f"📱 Clip {cur_clip}/{max(total_clips, cur_clip)}: normalizando..."
|
text = f"📱 Clip {cur_clip}/{max(total_clips, cur_clip)}: normalizando..."
|
||||||
elif "Copying to Nextcloud" in line and cur_clip > 0:
|
elif "Copying to Nextcloud" in line and cur_clip > 0:
|
||||||
text = f"📤 Clip {cur_clip}/{max(total_clips, cur_clip)}: subiendo a Nextcloud..."
|
text = f"📤 Clip {cur_clip}/{max(total_clips, cur_clip)}: subiendo a Nextcloud..."
|
||||||
|
elif "Total execution time" in line:
|
||||||
|
text = None
|
||||||
|
|
||||||
if text and text != last_text:
|
if text and text != last_text:
|
||||||
last_text = text
|
last_text = text
|
||||||
@@ -153,6 +171,7 @@ async def process_video(bot, url: str):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
await proc.wait()
|
await proc.wait()
|
||||||
|
print(f"[DEBUG] main.py exit code: {proc.returncode}")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user