╔══════════════════════════════════════════════════════════════════════╗ ║ ║ ║ 🚀 GUÍA RÁPIDA: Docker + Endpoint + FFmpeg ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════╝ ## ⚡ INICIO RÁPIDO ### 1️⃣ Ejecutar Solo la API ```bash docker run -d --name tubescript_api -p 8080:8000 \ -v $(pwd)/cookies.txt:/app/cookies.txt:ro \ tubescript-api ``` **Acceso:** http://localhost:8080/docs --- ### 2️⃣ Obtener URL m3u8 de un Video ```bash # Método 1: cURL curl http://localhost:8080/stream/VIDEO_ID # Método 2: Script de prueba ./test-endpoint-stream.sh # Método 3: Navegador http://localhost:8080/stream/VIDEO_ID ``` --- ### 3️⃣ Usar URL con FFmpeg ```bash # Obtener URL STREAM_URL=$(curl -s http://localhost:8080/stream/VIDEO_ID | jq -r '.stream_url') # Transmitir a YouTube ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://a.rtmp.youtube.com/live2/TU_STREAM_KEY ``` --- ## 📋 COMANDOS DOCKER ### Solo API (Backend) ```bash # Construir docker build -t tubescript-api . # Ejecutar docker run -d --name api -p 8080:8000 tubescript-api # Ver logs docker logs -f api # Detener docker stop api && docker rm api ``` --- ### Solo Streamlit (Frontend) ```bash # Construir docker build -t tubescript-streamlit . # Ejecutar (conectado a API en host) docker run -d --name panel -p 8501:8501 \ -e API_URL=http://host.docker.internal:8080 \ -v $(pwd)/stream_config.json:/app/stream_config.json \ tubescript-streamlit \ streamlit run streamlit_app.py \ --server.port=8501 \ --server.address=0.0.0.0 \ --server.headless=true # Ver logs docker logs -f panel # Detener docker stop panel && docker rm panel ``` --- ### Ambos con docker-compose ```bash # Iniciar docker-compose up -d # Ver logs docker-compose logs -f # Detener docker-compose down ``` --- ## 🎬 COMANDOS FFMPEG ### Template Base ```bash ffmpeg -re \ -i "URL_M3U8_DEL_ENDPOINT" \ -c copy \ -f flv \ RTMP_URL/STREAM_KEY ``` --- ### YouTube ```bash ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://a.rtmp.youtube.com/live2/TU_STREAM_KEY ``` --- ### Facebook ```bash ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmps://live-api-s.facebook.com:443/rtmp/TU_STREAM_KEY ``` --- ### Twitch ```bash ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://live.twitch.tv/app/TU_STREAM_KEY ``` --- ### X (Twitter) ```bash ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmps://fa.contribute.live-video.net/app/TU_STREAM_KEY ``` --- ### Múltiples Plataformas ```bash # YouTube ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://a.rtmp.youtube.com/live2/YOUTUBE_KEY & # Facebook ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmps://live-api-s.facebook.com:443/rtmp/FACEBOOK_KEY & # Twitch ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://live.twitch.tv/app/TWITCH_KEY & wait ``` --- ## 🧪 TESTING ### Test 1: API ```bash # Iniciar API docker run -d --name test_api -p 8080:8000 tubescript-api # Probar endpoint curl http://localhost:8080/ # Probar stream curl http://localhost:8080/stream/VIDEO_ID # Limpiar docker stop test_api && docker rm test_api ``` --- ### Test 2: Endpoint con Script ```bash # Ejecutar script de prueba ./test-endpoint-stream.sh # Ingresa un VIDEO_ID cuando te lo pida ``` --- ### Test 3: FFmpeg Manual ```bash # 1. Obtener URL STREAM_URL=$(curl -s http://localhost:8080/stream/VIDEO_ID | jq -r '.stream_url') # 2. Probar 10 segundos ffmpeg -re -t 10 -i "$STREAM_URL" -c copy -f flv \ rtmp://a.rtmp.youtube.com/live2/TU_STREAM_KEY ``` --- ## 📊 ENDPOINTS DISPONIBLES | Endpoint | Método | Descripción | |----------|--------|-------------| | `/` | GET | Health check | | `/stream/{video_id}` | GET | Obtener URL m3u8 | | `/transcript/{video_id}` | GET | Obtener transcripción | | `/docs` | GET | Documentación Swagger | --- ## 🔧 VARIABLES DE ENTORNO ### Para Streamlit: ```bash -e API_URL=http://host.docker.internal:8080 # API en host -e API_URL=http://tubescript-api:8000 # API en Docker ``` --- ## 📝 FLUJO COMPLETO ```bash # 1. Iniciar API docker run -d --name api -p 8080:8000 tubescript-api # 2. Obtener URL m3u8 VIDEO_ID="VIDEO_EN_VIVO" STREAM_URL=$(curl -s http://localhost:8080/stream/$VIDEO_ID | jq -r '.stream_url') # 3. Verificar URL echo "URL obtenida: $STREAM_URL" # 4. Transmitir a YouTube ffmpeg -re -i "$STREAM_URL" -c copy -f flv \ rtmp://a.rtmp.youtube.com/live2/TU_STREAM_KEY # 5. Detener API docker stop api ``` --- ## 🎯 CASOS DE USO ### Caso 1: Solo API para Desarrollo ```bash docker run -d --name dev_api -p 8080:8000 \ -v $(pwd):/app \ tubescript-api ``` --- ### Caso 2: Testing con Video Real ```bash # 1. Iniciar API docker-compose up -d tubescript-api # 2. Probar con script ./test-endpoint-stream.sh # 3. Copiar comando FFmpeg generado # 4. Ejecutar transmisión ``` --- ### Caso 3: Producción Completa ```bash # Ambos servicios docker-compose up -d # Acceso panel open http://localhost:8501 # Acceso API open http://localhost:8080/docs ``` --- ## 💡 TIPS ✅ **Usa jq** para extraer datos JSON fácilmente: ```bash curl -s http://localhost:8080/stream/VIDEO_ID | jq -r '.stream_url' ``` ✅ **Script de prueba** incluido para generar comandos: ```bash ./test-endpoint-stream.sh ``` ✅ **Múltiples plataformas** con `&` al final para ejecutar en background ✅ **Ver logs** en tiempo real: ```bash docker-compose logs -f tubescript-api ``` --- ## 🆘 SOLUCIÓN DE PROBLEMAS ### API no responde ```bash # Ver logs docker logs tubescript_api # Reiniciar docker restart tubescript_api # Reconstruir docker-compose build tubescript-api docker-compose up -d tubescript-api ``` --- ### Error al obtener URL ```bash # Verificar que el video esté EN VIVO # Actualizar yt-dlp docker exec tubescript_api pip install -U yt-dlp # Probar manualmente docker exec -it tubescript_api bash yt-dlp -g -f best "URL_VIDEO" ``` --- ### FFmpeg no conecta ```bash # Verificar RTMP URL # Verificar Stream Key # Probar con -t 10 (10 segundos de prueba) ffmpeg -re -t 10 -i "$STREAM_URL" -c copy -f flv rtmp://... ``` --- ╔══════════════════════════════════════════════════════════════════════╗ ║ ║ ║ ✅ TODO LISTO PARA USAR ║ ║ ║ ║ COMANDO RÁPIDO: ║ ║ docker-compose up -d ║ ║ ║ ║ PROBAR ENDPOINT: ║ ║ ./test-endpoint-stream.sh ║ ║ ║ ║ DOCS COMPLETAS: ║ ║ DOCKER_COMANDOS_SEPARADOS.md ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════╝