Skip to content

Instantly share code, notes, and snippets.

@dir
Created February 3, 2025 02:28
Show Gist options
  • Select an option

  • Save dir/5e800f6e8d10cfc24e9c3354384de3b2 to your computer and use it in GitHub Desktop.

Select an option

Save dir/5e800f6e8d10cfc24e9c3354384de3b2 to your computer and use it in GitHub Desktop.
Video Downloader (yt-dlp) Raycast Script Command
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Download Video
# @raycast.mode compact
# @raycast.packageName Media
# @raycast.argument1 { "type": "text", "placeholder": "URL", "percentEncoded": false }
# @raycast.argument2 { "type": "dropdown", "placeholder": "Format", "data": [{ "title": "Auto", "value": "auto" }, { "title": "MP4", "value": "mp4" }, { "title": "WebM", "value": "webm" }, { "title": "MKV", "value": "mkv" }, { "title": "FLV", "value": "flv" }, { "title": "AVI", "value": "avi" }, { "title": "M4A", "value": "m4a" }], "optional": true }
# @raycast.argument3 { "type": "text", "placeholder": "Output Path", "optional": true }
#
# Optional parameters:
# @raycast.icon 💾
#
# Documentation:
# @raycast.description Download a video from thousands of sites using yt-dlp.
# @raycast.author Luke Davis
# @raycast.authorURL https://raycast.com/dir
# Check if yt-dlp is installed
if ! command -v yt-dlp &>/dev/null; then
echo "yt-dlp binary couldn't be found in \$PATH. Please install it first."
exit 1
fi
# Get the URL from the first argument
URL="$1"
# Get format (default to auto if not specified)
FORMAT="${2:-auto}"
# Set output path to Downloads folder if not provided
OUTPUT_PATH="${3:-$HOME/Downloads/%(title)s.%(ext)s}"
# Create output directory if it doesn't exist
OUTPUT_DIR=$(dirname "$OUTPUT_PATH")
mkdir -p "$OUTPUT_DIR"
get_format_string() {
case "$1" in
auto) echo "bv*+ba/b" ;;
m4a) echo "ba[ext=m4a]" ;;
*) echo "bv*[ext=$1]+ba[ext=m4a]" ;;
esac
}
# Direct yt-dlp command without function wrapper
FORMAT_STRING=$(get_format_string "$FORMAT")
# First get the filename
if DOWNLOADED_FILE=$(yt-dlp -f "$FORMAT_STRING" -o "$OUTPUT_PATH" "$URL" --print filename --skip-download); then
# Then do the actual download
if yt-dlp -f "$FORMAT_STRING" -o "$OUTPUT_PATH" "$URL"; then
echo "Download completed successfully to: $DOWNLOADED_FILE"
else
echo "Download failed"
exit 1
fi
else
echo "Download failed"
exit 1
fi
@dir

dir commented Feb 3, 2025

Copy link
Copy Markdown
Author

This script is powered by, and requires yt-dlp to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment