Skip to content

Instantly share code, notes, and snippets.

@ChrisK2
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisK2/2c9550229bb0abf931ee to your computer and use it in GitHub Desktop.
Save ChrisK2/2c9550229bb0abf931ee to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
URL=$1
YTDL=youtube-dl
if [ -z "$MPV" ] ; then
MPV=mpv
fi
cookies_dir="$(mktemp -d /tmp/youtube-dl_mpv.XXXX)"
cookies_file="${cookies_dir}/cookies"
user_agent="$($YTDL --dump-user-agent)" # or set whatever you want
$YTDL -F --no-playlist $URL
echo
read -p "Which video format? (best) " FMTV
read -p "Which audio format? (best) " FMTA
if [ -z $FMTV ]; then
FMTV="bestvideo"
fi
if [ -z $FMTA ]; then
FMTA="bestaudio"
fi
{
read -r title
read -r video_url
} < <($YTDL \
--user-agent="$user_agent" \
--cookies="$cookies_file" \
--get-url --get-title --no-playlist \
-f $FMTV \
"$URL")
if [ $FMTA != "none" ]; then
audio=--audio-file="$($YTDL \
--user-agent="$user_agent" \
--cookies="$cookies_file" \
--get-url --no-playlist \
-f $FMTA \
"$URL")"
fi
$MPV --cookies --cookies-file="$cookies_file" --user-agent="$user_agent" \
$audio --media-title "$title" "$video_url"
rm -rf "$cookies_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment