Last active
August 29, 2015 14:05
-
-
Save ChrisK2/2c9550229bb0abf931ee to your computer and use it in GitHub Desktop.
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 | |
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