VLC (2.2.1 in this example) has an HTTP interface where you can query the currently playing track. You can enable it from the command line:
vlc --extraintf=http --http-host 0.0.0.0:8080 --http-password 'watpasswd'
or through the GUI (these settings persist through restarts):
- Tools > Preferences, Show settings: All
- Interface > Main interfaces, check "Web"
- Interface > Main interfaces > Lua > Lua HTTP > Password
You can visit http://localhost:8080/requests/status.xml
in a browser, enter the password, and you should receive an XML containing a section like this:
<category name="meta"> <info name="title">Jazz</info> <info name="filename">http://example.com/station</info> <info name="genre">smooth</info> <info name="now_playing">Jimmy Sommers - Fly Me To The Moon</info> </category>
All that remains is to set up a cron job to periodically save the playing track.
#!/bin/bash vlc_status="$(curl --connect-timeout 15 --silent -u :watpasswd http://localhost:8080/requests/status.xml)" # Parse out now-playing track, escape named entities e.g. '&' track=$(echo "$" | xmlstarlet sel -t -v ".//info[@name='now_playing']" | xmlstarlet unesc) # Append new track to log file echo "$track" >> vlc_log.txt # Remove duplicates of new track if any # http://stackoverflow.com/a/1444448/ gawk -i inplace '!x[$0]++' vlc_log.txt