How to display the Now Playing information online (part 1)

Home > Search > How-to
  by

If we were to rip our CD in a Media Player other than VLC, such as Windows Media Player, the Media Information could be poorly formatted. For example, we want our Media Information in VLC to be like this:

  • Artist: Nirvana
  • Title: Smells Like Teen Spirit
  • Album: Nevermind


If we were to rip our CD in Windows Media Player, the Media Information would look like this in VLC:

Title: Nirvana Nevermind 01 Smells Like Teen Spirit.wav

Following are the steps on how to rip a CD in VLC, so that the Media Information is properly formatted for VLC.

  1. Ctrl R (or select Media -> Convert/Save). The Open Media popup box appears
  2. Click on the Disc Tab
  3. Bullet Audio CD
  4. Click on the Browse button and select the CD
  5. Click on the Convert/Save button. The popup changes to the Convert window
  6. Bullet Dump raw input
  7. Click on the Browse button and select the output location
  8. Click on Start
  9. VLC now has the Media Information properly formatted.
  10. More TBD

 

VLC Configuration

  1. Select Tools -> Preferences (or just Ctrl P). The simple preferences popup box appears.
  2. At the bottom left corner of the simple preferences popup box, change show settings from simple to all. The popup box changes to Advanced Preferences.
  3. In the left panel, under Interface, select Main Interfaces and checkmark web.
  4. In the left panel, under Interface, expand Main Interfaces, select Lua and input a password. Click Save.
  5. Restart VLC
  6. In a web browser, go here: http://localhost:8080/requests/status.xml. There should be a popup box asking for a username and password. Don't enter anything in username, and enter the password you set. Set VLC to Web Interface and go to http://localhost:8080/requests/status.xml
  7. You should now have an output of the Now Playing XML

Automation via BASH Shell Scripts
Our next step is to create a job that downloads the latest XML file to a directory on our web server once every 5 seconds, and also modifies the fields in the XML file. My web server is Linux, so this part of this tutorial will shift to Linux. We will create five Shell Scripts to make this automation happen. The five Shells Scripts are:

  1. nowplaying.sh
  2. nowplaying_intervals.sh
  3. sed.sh
  4. sed_intervals.sh
  5. nohup.sh

The nowplaying.sh contains the command which copys the contents of the XML file from http://localhost:8080/requests/status.xml and creates a new file in our Linux machine with the XML contents. The nowplaying_intervals.sh runs the nowplaying.sh once every 5 seconds. The sed.sh modifies the fields of the XML file, removing unnecessary fields, and appending either an XSL stylesheet or PHP script to the XML. The sed_intervals.sh runs the sed.sh once every 5 seconds. Lastly, the nohup.sh glues everything together. Thinks of the nohup.sh as the controller and master. Without nohup.sh, nothing would run. The nohup.sh runs the nowplaying_intervals.sh and sed_intervals.sh scripts, which then in turn run the nowplaying.sh and sed.sh scripts. nohup.sh also enables logging, for debugging purposes.

To start this automation, we will start the nohup.sh script in Terminal. After the job is started, we can close Terminal, and the automation will continue to run, as this last & symbol in the nohup.sh tells the process to run in the background.

nowplaying.sh

#!/bin/bash wget -N --user='' --password='supersecretpassword' http://localhost:8080/requests/status.xml

 

nowplaying_intervals.sh

#!/bin/bash while true do /var/www/path/to/your/webserver/nowplaying.sh sleep 5 done

 

Following are two different set's of SED scripts. One modifies the XML for PHP. The other modifies the XML for XSL. If using the XML for PHP script, your web page will end in .php. If using the XML for XSL script, your web page will end in .xml. This is just preference, and one script is not better than the other.

sed.sh (XML for PHP)

#!/bin/bash cat status.xml | sed "s,<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>,<?php \$xmlstr = <<<XML," | sed "s,<root>,<?xml version=\"1.0\" standalone=\"yes\" ?>," | sed "/fullscreen/d" | sed "/audiodelay/d" | sed "/apiversion/d" | sed "/currentplid/d" | sed "/time/d" | sed "/length/d" | sed "/random/d" | sed "/volume/d" | sed "/audiofilters/d" | sed "/rate/d" | sed "/videoeffects/d" | sed "/hue/d" | sed "/saturation/d" | sed "/contrast/d" | sed "/brightness/d" | sed "/state/d" | sed "/information/d" | sed "/loop/d" | sed "/position/d" | sed "/repeat/d" | sed "/subtitledelay/d" | sed "/equalizer/d" | sed "/lostabuffers/d" | sed "/<version>/d" | sed "/readpackets/d" | sed "/lostpictures/d" | sed "/demuxreadbytes/d" | sed "/playedabuffers/d" | sed "/demuxcorrupted/d" | sed "/sentbytes/d" | sed "/displayedpictures/d" | sed "/sentpackets/d" | sed "/demuxdiscontinuity/d" | sed "/decodedvideo/d" | sed "/readbytes/d" | sed "/decodedaudio/d" | sed "/<stats>/d" | sed "s, </stats>,XML;," | sed "s,</root>,?>," | sed "s,info name,info type,g" >xml.php

 

sed.sh (XML for XSL)

#!/bin/bash cat status.xml | sed "s,<root>,<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?><meta http-equiv="refresh" content="5">," | sed "/fullscreen/d" | sed "/audiodelay/d" | sed "/apiversion/d" | sed "/currentplid/d" | sed "/time/d" | sed "/length/d" | sed "/random/d" | sed "/volume/d" | sed "/audiofilters/d" | sed "/rate/d" | sed "/videoeffects/d" | sed "/hue/d" | sed "/saturation/d" | sed "/contrast/d" | sed "/brightness/d" | sed "/state/d" | sed "/information/d" | sed "/loop/d" | sed "/position/d" | sed "/repeat/d" | sed "/subtitledelay/d" | sed "/equalizer/d" | sed "/lostabuffers/d" | sed "/<version>/d" | sed "/readpackets/d" | sed "/lostpictures/d" | sed "/demuxreadbytes/d" | sed "/playedabuffers/d" | sed "/demuxcorrupted/d" | sed "/sentbytes/d" | sed "/displayedpictures/d" | sed "/sentpackets/d" | sed "/demuxdiscontinuity/d" | sed "/decodedvideo/d" | sed "/readbytes/d" | sed "/decodedaudio/d" | sed "/<stats>/d" | sed ",</stats>,d" | sed ",</root>,d," | sed "s,info name,info type,g" <newstatus.xml


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments