Automatically share mps-youtube activity to a website

Since I’ve been working from home, I’ve been using mpsyt as a command line player for music from YouTube. Revived a 2008 HP Mini netbook with Lubuntu as an auxiliary machine and needed something really light as far as resource usage. You can configure mpsyt for audio only and it’s vastly lighter than playing videos in a browser.

After a video finishes playing, it’s automatically logged here:

anna@anna-HP-Mini:~$ tail -2 .config/mps-youtube/play_history.m3u 
#EXTINF:2251,NEON CITY - A Synthwave Mix [Chillwave - Retrowave - Synthwave]
https://www.youtube.com/watch?v=k4oeMldaqHk

Wouldn’t it be fun to post that as an embedded YouTube video on a webpage so your fellow techs can see what you’re listening to during the shift!

I made a little script to generate the embed link and update that on my server.

anna@anna-HP-Mini:~$ cat scripts/embed.sh 
#!/bin/bash

ID=`awk -F= 'END{print $2}' /home/anna/.config/mps-youtube/play_history.m3u`
YT=`echo 'src="https://www.youtube.com/embed/'`
CLOSE=`echo '"''>'`
LINK=$YT$ID$CLOSE

ssh radioshack -T "sed -i '85s#.*#$LINK#' /home/radioshack/public_html/index.php"

Then set up incron to watch the log file, running the script when it’s modified.

anna@anna-HP-Mini:~$ incrontab -l
/home/anna/.config/mps-youtube/play_history.m3u IN_MODIFY bash /home/anna/scripts/embed.sh

The script updates line 85 of index.php up on my site, the src line here.

<center><h2>
<?php
echo "server fixing music  ".date("F d Y H:i:s",
                      filemtime("index.php")); 
?>
</h2></center>
<center><iframe width="420" height="315"
src="https://www.youtube.com/embed/k4oeMldaqHk">
</iframe></center>

And this is what it looks like on my website.

Leave a Reply