#!/bin/bash # YouTube Cookies Extractor Script # This script helps you extract cookies from your browser for yt-dlp echo "==========================================" echo "YouTube Cookies Extractor" echo "==========================================" echo "" echo "This script will help you extract cookies from your browser" echo "to bypass YouTube's bot detection." echo "" COOKIES_FILE="./youtube-cookies.txt" echo "Options:" echo "" echo "1. Extract from Chrome/Chromium" echo "2. Extract from Firefox" echo "3. Manual instructions (export from browser extension)" echo "" read -p "Choose an option (1-3): " choice case $choice in 1) echo "" echo "Extracting cookies from Chrome/Chromium..." echo "" # Check if yt-dlp can extract cookies if command -v yt-dlp &> /dev/null; then echo "Using yt-dlp to extract cookies from Chrome..." yt-dlp --cookies-from-browser chrome --cookies "$COOKIES_FILE" --print-to-file webpage_url - "https://www.youtube.com" 2>/dev/null if [ -f "$COOKIES_FILE" ]; then echo "✓ Cookies extracted successfully to: $COOKIES_FILE" echo "" echo "Add this to your .env file:" echo "YOUTUBE_COOKIES_PATH=$(realpath $COOKIES_FILE)" else echo "✗ Failed to extract cookies automatically." echo "You may need to export cookies manually (see option 3)" fi else echo "✗ yt-dlp not found. Please install it first:" echo " pip install yt-dlp" fi ;; 2) echo "" echo "Extracting cookies from Firefox..." echo "" if command -v yt-dlp &> /dev/null; then echo "Using yt-dlp to extract cookies from Firefox..." yt-dlp --cookies-from-browser firefox --cookies "$COOKIES_FILE" --print-to-file webpage_url - "https://www.youtube.com" 2>/dev/null if [ -f "$COOKIES_FILE" ]; then echo "✓ Cookies extracted successfully to: $COOKIES_FILE" echo "" echo "Add this to your .env file:" echo "YOUTUBE_COOKIES_PATH=$(realpath $COOKIES_FILE)" else echo "✗ Failed to extract cookies automatically." echo "You may need to export cookies manually (see option 3)" fi else echo "✗ yt-dlp not found. Please install it first:" echo " pip install yt-dlp" fi ;; 3) echo "" echo "==========================================" echo "Manual Cookie Export Instructions" echo "==========================================" echo "" echo "Method 1: Using a browser extension (recommended)" echo " 1. Install one of these browser extensions:" echo " - Chrome: 'Get cookies.txt LOCALLY' or 'cookies.txt'" echo " - Firefox: 'cookies.txt'" echo "" echo " 2. Go to https://www.youtube.com and log in" echo "" echo " 3. Click on the extension icon and export cookies as 'youtube-cookies.txt'" echo "" echo " 4. Save the file to: $(realpath .)/youtube-cookies.txt" echo "" echo "Method 2: Using yt-dlp directly" echo " Run this command:" echo " yt-dlp --cookies-from-browser chrome --cookies youtube-cookies.txt 'https://www.youtube.com'" echo "" echo " (Replace 'chrome' with 'firefox', 'edge', 'safari', etc. if needed)" echo "" echo "Method 3: Using browser DevTools (advanced)" echo " 1. Go to https://www.youtube.com and log in" echo " 2. Open DevTools (F12)" echo " 3. Go to Application/Storage tab" echo " 4. Find Cookies > https://www.youtube.com" echo " 5. Export all cookies manually to Netscape format" echo "" echo "After creating the file, add this to your .env:" echo "YOUTUBE_COOKIES_PATH=$(realpath .)/youtube-cookies.txt" echo "" ;; *) echo "Invalid option" exit 1 ;; esac echo "" echo "==========================================" echo "" echo "IMPORTANT: Keep your cookies file secure!" echo "Do NOT share it or commit it to git." echo "The cookies give access to your YouTube account." echo "" echo "The cookies will expire eventually, so you may need" echo "to re-export them periodically." echo ""