Last active
April 7, 2025 16:54
-
-
Save nishantbadhautiya/f6b6a9d5b79ed1934728a2eb110f1f0f to your computer and use it in GitHub Desktop.
YouTube Playlist Downloader Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Ensure the script is run as root | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "β Please run this script as root (use sudo)." | |
| exit 1 | |
| fi | |
| echo "======================= β STEP 1: Folder Setup =======================" | |
| FOLDER="/others" | |
| if [ -d "$FOLDER" ]; then | |
| echo "π The folder $FOLDER already exists." | |
| else | |
| mkdir "$FOLDER" | |
| echo "β Folder $FOLDER created successfully." | |
| fi | |
| echo "===================== β STEP 2: ffmpeg Check/Install ===================" | |
| if command -v ffmpeg >/dev/null 2>&1; then | |
| echo "β ffmpeg is already installed at $(which ffmpeg)" | |
| ffmpeg -version | |
| else | |
| echo "π ffmpeg is not installed. Installing..." | |
| apt update && apt install -y ffmpeg | |
| if command -v ffmpeg >/dev/null 2>&1; then | |
| echo "β ffmpeg installed successfully!" | |
| else | |
| echo "β Installation failed. Please check your internet connection or sources." | |
| read -p "β Do you want to continue anyway? (y/n): " user_choice | |
| case "$user_choice" in | |
| y|Y ) echo "β‘οΈ Continuing..." ;; | |
| * ) echo "π Exiting."; exit 1 ;; | |
| esac | |
| fi | |
| fi | |
| echo "==================== β STEP 3: yt-dlp Check/Install ===================" | |
| if command -v yt-dlp >/dev/null 2>&1; then | |
| echo "β yt-dlp is already installed at $(which yt-dlp)" | |
| else | |
| echo "π yt-dlp not installed. Installing..." | |
| curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp | |
| chmod a+rx /usr/local/bin/yt-dlp | |
| if command -v yt-dlp >/dev/null 2>&1; then | |
| echo "β yt-dlp installed successfully!" | |
| else | |
| echo "β Failed to install yt-dlp. Exiting script." | |
| exit 1 | |
| fi | |
| fi | |
| echo "π¦ yt-dlp version: $(yt-dlp --version)" | |
| echo "=================== β STEP 4: Download Playlist ======================" | |
| OUTPUT_DIR="/others/youtube" | |
| mkdir -p "$OUTPUT_DIR" | |
| read -p "πΊ Enter YouTube Playlist URL: " PLAYLIST_URL | |
| # Video quality | |
| echo "π₯ Choose video quality (default: 720p):" | |
| echo " 1) 144p" | |
| echo " 2) 240p" | |
| echo " 3) 360p" | |
| echo " 4) 480p" | |
| echo " 5) 720p" | |
| echo " 6) 1080p" | |
| echo " 7) 1440p" | |
| echo " 8) 2160p" | |
| read -p "π Enter number (1-8) for desired quality [default 720px]: " QUALITY_OPTION | |
| QUALITY_OPTION=${QUALITY_OPTION:-5} | |
| case $QUALITY_OPTION in | |
| 1) QUALITY=144 ;; | |
| 2) QUALITY=240 ;; | |
| 3) QUALITY=360 ;; | |
| 4) QUALITY=480 ;; | |
| 5) QUALITY=720 ;; | |
| 6) QUALITY=1080 ;; | |
| 7) QUALITY=1440 ;; | |
| 8) QUALITY=2160 ;; | |
| *) echo "β Invalid option. Exiting."; exit 1 ;; | |
| esac | |
| # Playlist start index | |
| read -p "π’ Playlist start (default: 1): " START_INDEX | |
| START_INDEX=${START_INDEX:-1} | |
| # Playlist end index (optional) | |
| read -p "π’ Playlist end (default: last video): " END_INDEX | |
| # Ask for subtitle | |
| read -p "π Do you want subtitles? (y/n) [default: n]: " SUB_CHOICE | |
| SUB_CHOICE=${SUB_CHOICE:-n} | |
| echo "π Starting download..." | |
| # Download logic with or without subtitles | |
| if [[ "$SUB_CHOICE" =~ ^[Yy]$ ]]; then | |
| yt-dlp -f "bestvideo[height<=${QUALITY}]+bestaudio" \ | |
| -o "${OUTPUT_DIR}/%(playlist_index)s-%(title)s.%(ext)s" \ | |
| --embed-subs --sub-lang "en" \ | |
| --playlist-start "$START_INDEX" \ | |
| ${END_INDEX:+--playlist-end "$END_INDEX"} \ | |
| "$PLAYLIST_URL" | |
| else | |
| yt-dlp -f "bestvideo[height<=${QUALITY}]+bestaudio" \ | |
| -o "${OUTPUT_DIR}/%(playlist_index)s-%(title)s.%(ext)s" \ | |
| --playlist-start "$START_INDEX" \ | |
| ${END_INDEX:+--playlist-end "$END_INDEX"} \ | |
| "$PLAYLIST_URL" | |
| fi | |
| echo "β Playlist download complete!" | |
| echo "======================= β STEP 5: Zip & Upload ========================" | |
| ZIP_NAME="youtube_download.zip" | |
| ZIP_PATH="/others/$ZIP_NAME" | |
| LINK_FILE="/others/youtube_download.txt" | |
| echo "π¦ Creating ZIP archive..." | |
| zip -r "$ZIP_PATH" "$OUTPUT_DIR" >/dev/null | |
| # Check if ZIP was successfully created | |
| if [ ! -f "$ZIP_PATH" ]; then | |
| echo "β Failed to create ZIP file. Exiting." | |
| exit 1 | |
| fi | |
| # β Print total size of the ZIP file (human-readable) | |
| FILE_SIZE=$(du -h "$ZIP_PATH" | cut -f1) | |
| echo "π Total ZIP file size: $FILE_SIZE" | |
| # Upload with progress bar | |
| echo "π Uploading ZIP using bashupload with progress bar..." | |
| UPLOAD_OUTPUT=$(curl --progress-bar --upload-file "$ZIP_PATH" https://bashupload.com/"$ZIP_NAME") | |
| # Extract download link from upload response | |
| DOWNLOAD_LINK=$(echo "$UPLOAD_OUTPUT" | grep -Eo 'https://bashupload\.com/[a-zA-Z0-9._/-]+' | tail -n 1) | |
| # Get human-readable file size | |
| FILE_SIZE=$(du -h "$ZIP_PATH" | cut -f1) | |
| # Save the link to a text file | |
| echo "$DOWNLOAD_LINK" > "$LINK_FILE" | |
| # Display download info box | |
| if [[ -n "$DOWNLOAD_LINK" ]]; then | |
| echo "" | |
| echo "π’ Your ZIP file is ready to download!" | |
| echo "" | |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββ" | |
| echo "β π₯ Download Link: β" | |
| echo "β β" | |
| printf "β %-42s β\n" "$DOWNLOAD_LINK" | |
| echo "β β" | |
| printf "β π¦ File Size: %-30s β\n" "$FILE_SIZE" | |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββ" | |
| echo "" | |
| echo "" | |
| else | |
| echo "β Failed to retrieve download link. Check your internet or try again." | |
| fi | |
| # Clean up | |
| echo "" | |
| echo "π§Ή Cleaning up all files in /others/ ..." | |
| rm -rf /others/* | |
| echo "β Cleanup complete." | |
| echo "β All steps completed successfully!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment