- Introduced `playwright_extract_m3u8.py` to extract M3U8 URLs from YouTube videos using Playwright. - Added `README_PLAYWRIGHT.md` for usage instructions and requirements. - Created `expand_and_test_proxies.py` to expand user-provided proxies and test their validity. - Implemented `generate_proxy_whitelist.py` to generate a whitelist of working proxies based on testing results. - Added sample proxy files: `user_proxies.txt` for user-defined proxies and `proxies_sample.txt` as a template. - Generated `expanded_proxies.txt`, `whitelist.json`, and `whitelist.txt` for storing expanded and valid proxies. - Included error handling and logging for proxy testing results.
142 lines
4.7 KiB
Bash
Executable File
142 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# export-chrome-cookies.sh
|
|
# Exporta cookies de YouTube desde el perfil del navegador del HOST
|
|
# usando yt-dlp, y las copia a ./data/cookies.txt para que la API las use.
|
|
#
|
|
# Uso:
|
|
# ./export-chrome-cookies.sh # Chrome (default)
|
|
# ./export-chrome-cookies.sh chromium # Chromium
|
|
# ./export-chrome-cookies.sh brave # Brave
|
|
# ./export-chrome-cookies.sh firefox # Firefox
|
|
# ./export-chrome-cookies.sh edge # Edge
|
|
#
|
|
# IMPORTANTE:
|
|
# - Cierra el navegador antes de ejecutar (Chrome bloquea el archivo de cookies)
|
|
# - En Linux no requiere contraseña ni keychain especial
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
set -e
|
|
|
|
BROWSER="${1:-chrome}"
|
|
OUTPUT="./data/cookies.txt"
|
|
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
|
|
|
|
ok() { echo -e "${GREEN}✅ $1${NC}"; }
|
|
warn() { echo -e "${YELLOW}⚠️ $1${NC}"; }
|
|
err() { echo -e "${RED}❌ $1${NC}"; exit 1; }
|
|
|
|
echo ""
|
|
echo "🍪 Exportando cookies de YouTube desde: $BROWSER"
|
|
echo ""
|
|
|
|
# Verificar yt-dlp
|
|
if ! command -v yt-dlp &>/dev/null; then
|
|
err "yt-dlp no está instalado. Instala con: pip install yt-dlp"
|
|
fi
|
|
|
|
# Verificar que el navegador no esté corriendo (puede causar errores de bloqueo)
|
|
BROWSER_PROC=""
|
|
case "$BROWSER" in
|
|
chrome) BROWSER_PROC="google-chrome\|chrome" ;;
|
|
chromium) BROWSER_PROC="chromium" ;;
|
|
brave) BROWSER_PROC="brave" ;;
|
|
firefox) BROWSER_PROC="firefox" ;;
|
|
edge) BROWSER_PROC="msedge\|microsoft-edge" ;;
|
|
esac
|
|
|
|
if [ -n "$BROWSER_PROC" ] && pgrep -f "$BROWSER_PROC" &>/dev/null; then
|
|
warn "El navegador '$BROWSER' parece estar corriendo."
|
|
warn "Ciérralo antes de exportar para evitar errores de bloqueo del DB."
|
|
echo ""
|
|
read -p "¿Continuar de todos modos? (s/N): " confirm
|
|
[[ "$confirm" =~ ^[sS]$ ]] || { echo "Cancelado."; exit 0; }
|
|
echo ""
|
|
fi
|
|
|
|
# Crear directorio de destino
|
|
mkdir -p "$(dirname "$OUTPUT")"
|
|
|
|
# Detectar ruta del perfil
|
|
PROFILE_PATH=""
|
|
case "$BROWSER" in
|
|
chrome)
|
|
for p in "$HOME/.config/google-chrome/Default" "$HOME/.config/google-chrome/Profile 1"; do
|
|
[ -d "$p" ] && PROFILE_PATH="$p" && break
|
|
done
|
|
;;
|
|
chromium)
|
|
PROFILE_PATH="$HOME/.config/chromium/Default"
|
|
;;
|
|
brave)
|
|
PROFILE_PATH="$HOME/.config/BraveSoftware/Brave-Browser/Default"
|
|
;;
|
|
firefox)
|
|
# Firefox: yt-dlp detecta el perfil automáticamente
|
|
PROFILE_PATH=""
|
|
;;
|
|
edge)
|
|
PROFILE_PATH="$HOME/.config/microsoft-edge/Default"
|
|
;;
|
|
*)
|
|
err "Navegador '$BROWSER' no soportado. Usa: chrome, chromium, brave, firefox, edge"
|
|
;;
|
|
esac
|
|
|
|
if [ -n "$PROFILE_PATH" ] && [ ! -d "$PROFILE_PATH" ]; then
|
|
err "No se encontró el perfil de $BROWSER en: $PROFILE_PATH"
|
|
fi
|
|
|
|
# Construir argumento --cookies-from-browser
|
|
if [ -n "$PROFILE_PATH" ]; then
|
|
BROWSER_ARG="${BROWSER}:${PROFILE_PATH}"
|
|
echo " Perfil: $PROFILE_PATH"
|
|
else
|
|
BROWSER_ARG="$BROWSER"
|
|
echo " Perfil: detectado automáticamente"
|
|
fi
|
|
echo " Destino: $OUTPUT"
|
|
echo ""
|
|
|
|
# Exportar cookies con yt-dlp
|
|
echo "⏳ Extrayendo cookies..."
|
|
yt-dlp \
|
|
--cookies-from-browser "$BROWSER_ARG" \
|
|
--cookies "$OUTPUT" \
|
|
--skip-download \
|
|
--no-warnings \
|
|
--extractor-args "youtube:player_client=tv_embedded" \
|
|
"https://www.youtube.com/watch?v=dQw4w9WgXcQ" 2>&1 || {
|
|
err "Error al extraer cookies. Asegúrate de que el navegador está cerrado y tienes sesión en YouTube."
|
|
}
|
|
|
|
# Verificar resultado
|
|
if [ ! -f "$OUTPUT" ] || [ ! -s "$OUTPUT" ]; then
|
|
err "No se generó el archivo de cookies o está vacío."
|
|
fi
|
|
|
|
YT_LINES=$(grep -c "youtube.com" "$OUTPUT" 2>/dev/null || echo 0)
|
|
FILE_SIZE=$(du -h "$OUTPUT" | cut -f1)
|
|
|
|
echo ""
|
|
ok "Cookies exportadas exitosamente"
|
|
echo " Archivo: $OUTPUT"
|
|
echo " Tamaño: $FILE_SIZE"
|
|
echo " Líneas youtube.com: $YT_LINES"
|
|
echo ""
|
|
|
|
if [ "$YT_LINES" -lt 3 ]; then
|
|
warn "Pocas cookies de YouTube encontradas ($YT_LINES)."
|
|
warn "Verifica que estás logueado en YouTube en $BROWSER."
|
|
else
|
|
ok "Cookies de YouTube encontradas: $YT_LINES líneas"
|
|
fi
|
|
|
|
echo ""
|
|
echo "📋 Próximos pasos:"
|
|
echo " 1. Si el contenedor está corriendo, las cookies ya están disponibles en /app/data/"
|
|
echo " 2. Si no está corriendo: docker compose up -d"
|
|
echo " 3. Prueba: curl http://localhost:8282/cookies/status"
|
|
echo ""
|
|
|