Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
youtube-dl wrapper for downloading videos direct to the correct Plex collection on my plex Mac Mini
#!/bin/bash
# all sorts of more advanced features are available, but this is a start:
# https://github.com/ytdl-org/youtube-dl/blob/master/README.md#output-template-examples
if [ -z $1 ]; then
echo "Syntax: $0 VIDEO_URL"
exit 1
fi
VIDEO_URL="$1"
set -eu
cd $HOME > /dev/null
LASTCHECK_FILE="$HOME/.youtube-dl-wrapper-last-update-check"
NOW=$(date +%s 2>/dev/null)
LASTCHECK=$(cat $LASTCHECK_FILE 2>/dev/null)
CHECK_DELTA=$(($NOW-$LASTCHECK))
INTERVAL=$((12*60*60))
if (( $CHECK_DELTA > $INTERVAL )); then
echo "Checking for youtube-dl update..."
brew update > /dev/null
brew outdated | grep -q youtube-dl && brew upgrade youtube-dl && echo ""
echo "$NOW" > "$LASTCHECK_FILE"
fi
VIDEO_TITLE=$(youtube-dl --get-title "$VIDEO_URL")
echo "Downloading: \"$VIDEO_TITLE\""
echo ""
PS3="Select destination collection (Ctrl-C to quit): "
select OUT_DIR in *Videos
do
if [ -z "$OUT_DIR" ]; then
echo "Invalid selection. Hit Ctrl-C to quit."
echo ""
else
break
fi
done
echo ""
youtube-dl --no-playlist -o "$HOME/$OUT_DIR/%(uploader)s - %(title)s (%(upload_date)s).%(ext)s" "$VIDEO_URL"
# cd back to wherever the user was before running this script
cd - > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.