MP3’s and the Modern Listener
Jul 20, 2003 adminStuffShare/Save
As I mentioned earlier, I’ve started using Kung-Tunes to list what I’m listening to. It has a handy feature that lets you put together a list of recent tracks. However, like Metallica and others, I believe strongly in the power of the album as a complete work of art, and that’s how I do most of my listening – one album at a time. Neither Itunes nor Kung-Tunes, nor for that matter any other MP3 software I’ve ever seen, really supports this method of listening. If I just listened to three entire albums straight through, that’s not 60 lines worth of data. It’s really only 3.
Enter PHP.
I jimmied together a little PHP script to parse data from Kung-Tunes and group consecutive songs from the same album together. The first step is to create a new Kung-Tunes track listing template which uploads to “tracklist.txt”. Mine looks like this:
^t@ #p^p#p @ #a^a#a @ #y^y#y @
The @’s are separator tokens for the script. You can make them whatever you want, as long as you’re sure it’s something you wouldn’t find in any of your songs.
And here’s the PHP script:
<?php
$fp = fopen("PHP/tracklist.txt", "r");
$text = fgets($fp, 10240);
$all = explode("@", trim($text));
// Remove extra blank element at end from Kung-Tunes parsing
array_splice($all, count($all)-1);
$i = 0;
while ($i < count($all)) {
$title_save[$i/4] = trim($all[$i++]);
$artist_save[$i/4] = trim($all[$i++]);
$album_save[$i/4] = trim($all[$i++]);
$year_save[$i/4] = trim($all[$i++]);
}
$title[0] = $title_save[0];
$artist[0] = $artist_save[0];
$album[0] = $album_save[0];
$year[0] = $year_save[0];
$j = 0;
for ($i = 1; $i < count($title_save); $i++) {
// Different Album
if (($artist_save[$i] != $artist_save[$i - 1]) || ($album_save[$i] != $album_save[$i-1])) {
$j++;
$artist[$j] = $artist_save[$i];
$title[$j] = $title_save[$i];
$album[$j] = $album_save[$i];
$year[$j] = $year_save[$i];
}
// Same Album
else {
$title[$j] = $title[$j] . ", " . $title_save[$i];
}
}
for ($i = 0; $i < count($title); $i++) {
echo "<tr><td>$artist[$i]</td><td>$title[$i]</td><td>$album[$i]</td><td>$year[$i]</td></tr>";
}
?>
Happy Kung-Tuning!
July 20th, 2003 at 9:15 pm
Hey! Arthur’s a programmerator!
Nice work, I think. I don’t speak PHP yet, neither do I Kung-Tune, but your process is worthy of praise in and of itself.
I’d have to say that it is 60 lines of data, though. The point is what you’re listening to right now, not during the previous hour or the next hour. If you’re just compressing the data for your recently played page, that’s one thing, but if you’re gonna strip the song out of the listing on your front page, to me that’s kind of just kicking Kung Tunes in the nuts.
July 20th, 2003 at 11:27 pm
Yeah, just for the recently played page. If someone listens to 4 albums straight in a row, do I really need 80 rows of tracks to find out what they’re listening to? It’s like trying to find out what’s at the library by reading each book one at a time. It’s ridiculous – you need a catalog. If they’re listening to whole albums, I want to see data grouped by albums.
I’d never kick Kung-Tunes in the nuts. It’s a fantastic piece of software! Just trying to add my own personal touch.
July 21st, 2003 at 12:34 am
Interesting idea, Justi– Arthur.