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 |