Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active November 3, 2015 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/75784c8ac3ac48d3310a to your computer and use it in GitHub Desktop.
Save ormaaj/75784c8ac3ac48d3310a to your computer and use it in GitHub Desktop.
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