Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Last active April 27, 2022 02:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tyzbit/74adf898bc948b2896d813702d47d9ae to your computer and use it in GitHub Desktop.
Save tyzbit/74adf898bc948b2896d813702d47d9ae to your computer and use it in GitHub Desktop.
Download a video from a URL in clipboard automatically (bind to keyboard shortcut) (Mac/Linux)
#!/bin/bash
dir="$HOME/Videos"
opts="--add-metadata --no-mtime"
if [ -f /usr/local/bin/youtube-dl ]; then
youtube_dl="/usr/local/bin/youtube-dl"
else
youtube_dl="$(which youtube-dl)"
fi
if [[ "$(uname -a | awk '{print $1}')" == "Darwin" ]]; then
paste="pbpaste"
opts="${opts} --ffmpeg-location /usr/local/bin/ffmpeg"
else
paste="xsel -ob"
fi
cd "${dir}"
# Try downloading normally
if ! $youtube_dl $opts -o "${dir}/%(title)s.%(ext)s" "$($paste)"; then
# If the title is too long, use the id
$youtube_dl $opts -o "${dir}/%(id)s.%(ext)s" "$($paste)"
fi
@tyzbit
Copy link
Author

tyzbit commented Nov 25, 2020

Requires youtube-dl and xsel on Linux.

Requires youtube-dl on Mac.

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