in Music

On my speakers

I had an email from Mat this week asking how I get the ‘On my speakers’ sidebar feature on my blog. Instead of just telling Mat, I thought I’d share with you all!

I’d wanted to add this feature to the blog for some time due to some unexplained geeky desire. I came across a post on Ask MetaFlter by chance and it pointed me to the website of IndieRock, an application that was created in response to an earlier Ask MetaFilter post!

Basically, IndieRock monitors what iTunes is playing and outputs a plain text file to an FTP server. Simple as that. I’ve got mine to start up when I log in, so it’s almost all set every time I use my PC. I say almost as unfortunately you have to type your FTP password at the start of every session, but I don’t see this as a terrible inconvenience – it helps me to remember what my password is!

Once the text file is in a suitable place on the server, I include a breakdown of the first line using an embedded PHP script as follows:


<div class="side">
<?php
$filename = 'indierock.txt';
$size = filesize($filename);
if($size == "0"){
print("<em>currently not loaded</em><br/>");
} else {
$file = file("indierock.txt");
foreach($file as $line) {
$elements = explode("t", $line);
break;
}
if($elements[0] == "Unknown Artist"){
} else {
print("Artist: " . $elements[0] . "<br/>");
}
if($elements[1] == "Unknown Title"){
} else {
print("Song: " . $elements [1] . "<br/>");
}
if ($elements[2] == "Unknown Album"){
} else {
print("Album: " . $elements[2] . "<br/>");
}
}
?>
</div>

I then had to put the following in a file called .htaccess in the public_html folder on the web server:


RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

This tells Apache (the web server) to do something with the embedded PHP instead of just displaying the code.

That’s it!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)