Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.