Skip to content

Instantly share code, notes, and snippets.

@parkerlreed
Last active October 17, 2020 02:34
Show Gist options
  • Save parkerlreed/990d9ca146ee7ccb8cf9 to your computer and use it in GitHub Desktop.
Save parkerlreed/990d9ca146ee7ccb8cf9 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.

youloop

Script that monitors the clipboard and play Youtube videos.

make install to copy service file to /etc/systemd/user/ and enable it for ths user.

install:
sudo cp youloop.service /etc/systemd/user/
systemctl enable --user youloop.service
systemctl start --user youloop.service
#!/bin/bash
function loop(){
sleep 2
url=`xclip -selection clipboard -o`
if [[ `cat /tmp/youtubeurl` == "$url" ]]
then
return
fi
if [[ $url == *"youtube"* && `pgrep mpv` == "" ]]
then
echo "$url" > /tmp/youtubeurl
mpv --hwdec vaapi --ytdl-format=bestvideo[ext=mp4]+bestaudio[ext=m4a] "$url"
fi
}
while(true)
do
loop
done
[Unit]
Description=Service to monitor for Youtube URLs and play them
[Service]
ExecStart=/usr/bin/youloop
ExecStop=killall youloop
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment