Skip to content

Instantly share code, notes, and snippets.

@azend
Forked from parkerlreed/Makefile
Last active August 29, 2015 14:27
Show Gist options
  • Save azend/c5841c01067d59e2220a to your computer and use it in GitHub Desktop.
Save azend/c5841c01067d59e2220a to your computer and use it in GitHub Desktop.
Script to monitor clipboard for a new Youtube URL and plays the video when the URL does not match the existing URL. Also does not run when an mpv instance is already running.
#!/bin/bash
function loop(){
sleep 2
url=`xclip -selection clipboard -o`
if [[ `cat /tmp/youtubeurl` == "$url" ]]
then
return
fi
mpv=`pgrep mpv`
if [[ $url == *"youtube"* && $mpv == "" ]]
then
echo "$url" > /tmp/youtubeurl
mpv --hwdec vaapi --ytdl-format=bestvideo[ext=mp4]+bestaudio[ext=m4a] "$url"
fi
}
while(true)
do
loop
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment