#!/usr/bin/env python3 """ Script de prueba rápida para verificar la función de transcripción sin necesidad de Docker """ import sys import os import json import subprocess import requests def test_transcript(video_id, lang='es'): """Probar la función de transcripción""" url = f"https://www.youtube.com/watch?v={video_id}" # Comando simplificado command = [ "yt-dlp", "--skip-download", "--dump-json", "--no-warnings", "--extractor-args", "youtube:player_client=android", url ] print(f"🔍 Probando video: {video_id}") print(f"📝 Comando: {' '.join(command)}") print() try: result = subprocess.run(command, capture_output=True, text=True, timeout=60) if result.returncode != 0: print(f"❌ Error: {result.stderr[:500]}") return False if not result.stdout.strip(): print("❌ No se obtuvieron datos") return False metadata = json.loads(result.stdout) # Buscar subtítulos print("🔍 Buscando subtítulos...") print() # Verificar requested_subtitles requested_subs = metadata.get('requested_subtitles', {}) if requested_subs: print(f"✅ Encontrado en requested_subtitles:") for key, val in requested_subs.items(): print(f" - {key}: {val.get('ext', 'unknown')}") else: print("⚪ No hay requested_subtitles") # Verificar automatic_captions auto_captions = metadata.get('automatic_captions', {}) if auto_captions: print(f"\n✅ Automatic captions disponibles:") for lang_key, formats in auto_captions.items(): if lang in lang_key or lang_key.startswith(lang): print(f" - {lang_key}:") for fmt in formats[:3]: # Primeros 3 formatos print(f" • {fmt.get('ext', 'unknown')}: {fmt.get('url', 'N/A')[:80]}...") else: print("\n⚪ No hay automatic_captions") # Verificar subtitles subtitles = metadata.get('subtitles', {}) if subtitles: print(f"\n✅ Subtitles manuales disponibles:") for lang_key, formats in subtitles.items(): if lang in lang_key or lang_key.startswith(lang): print(f" - {lang_key}:") for fmt in formats[:3]: print(f" • {fmt.get('ext', 'unknown')}: {fmt.get('url', 'N/A')[:80]}...") else: print("\n⚪ No hay subtitles manuales") # Probar obtener URL print("\n" + "="*60) print("🎯 Intentando obtener URL de subtítulos...") found_subs = requested_subs if not found_subs and auto_captions: for lang_key in auto_captions.keys(): if lang in lang_key or lang_key.startswith(lang): if auto_captions[lang_key]: found_subs = {lang_key: auto_captions[lang_key][0]} print(f"✅ Usando automatic_captions[{lang_key}]") break if not found_subs and subtitles: for lang_key in subtitles.keys(): if lang in lang_key or lang_key.startswith(lang): if subtitles[lang_key]: found_subs = {lang_key: subtitles[lang_key][0]} print(f"✅ Usando subtitles[{lang_key}]") break if not found_subs: print("❌ No se encontraron subtítulos para el idioma especificado") print(f"\n💡 Idiomas disponibles:") all_langs = set(list(auto_captions.keys()) + list(subtitles.keys())) for l in sorted(all_langs): print(f" - {l}") return False # Intentar descargar lang_key = next(iter(found_subs)) sub_url = found_subs[lang_key].get('url') sub_ext = found_subs[lang_key].get('ext', 'unknown') if not sub_url: print("❌ No se pudo obtener URL de subtítulos") return False print(f"✅ URL encontrada: {sub_url[:100]}...") print(f"📝 Formato: {sub_ext}") # Intentar descargar print("\n⬇️ Descargando subtítulos...") response = requests.get(sub_url, timeout=30) if response.status_code == 200: print(f"✅ Descarga exitosa ({len(response.content)} bytes)") # Mostrar muestra del contenido sample = response.text[:500] if hasattr(response, 'text') else str(response.content[:500]) print(f"\n📄 Muestra del contenido:") print("─" * 60) print(sample) print("─" * 60) return True else: print(f"❌ Error HTTP {response.status_code}") return False except subprocess.TimeoutExpired: print("❌ Timeout al ejecutar yt-dlp") return False except Exception as e: print(f"❌ Error: {str(e)}") import traceback traceback.print_exc() return False if __name__ == "__main__": video_id = sys.argv[1] if len(sys.argv) > 1 else "6hini9Xz_fc" lang = sys.argv[2] if len(sys.argv) > 2 else "es" print("="*60) print("🧪 TubeScript - Test de Transcripción") print("="*60) print() success = test_transcript(video_id, lang) print() print("="*60) if success: print("✅ TEST EXITOSO") else: print("❌ TEST FALLIDO") print("="*60) sys.exit(0 if success else 1)