Last active
November 3, 2015 07:04
-
-
Save ormaaj/75784c8ac3ac48d3310a to your computer and use it in GitHub Desktop.
This file contains 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
function yt { | |
typeset vid file x | |
if ! vid=$(xsel -o); then | |
{ | |
echo 'xsel failed' | |
typeset -p DISPLAY | |
} >&2 | |
return 1 | |
elif ! file=$(youtube-dl --get-filename -- "$vid"); then | |
echo 'Could not resolve file name from URL.' >&2 | |
return 1 | |
elif [[ -f $file ]]; then | |
printf 'File already exists: %q\n' "$file" >&2 | |
return 1 | |
else | |
{ | |
inotifywait -e create . 2>&1 >&3 | { | |
while IFS= read -r x; do | |
if [[ $x != 'Watches established.' ]]; then | |
break | |
fi | |
done | |
youtube-dl -f '[height <=? 720]' --no-part "$vid" <&4 >&2 | |
} | |
} 3>&1 | { | |
while IFS= read -r x && [[ $x != "./ CREATE ${file}" ]] | |
do : | |
done | |
smplayer "$file" <&4 >&2 | |
} | |
fi 4<&0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment