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@ #pp#p @ #aa#a @ #yy#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);<br/>
$text = fgets($fp, 10240);<br/>

$all = explode(@, trim($text));<br/>

// Remove extra blank element at end from Kung-Tunes parsing<br/>
array_splice($all, count($all)-1);<br/>
$i = 0;<br/>
while ($i  count($all)) {<br/>
    $title_save[$i/4] = trim($all[$i++]);<br/>
    $artist_save[$i/4] = trim($all[$i++]);<br/>
    $album_save[$i/4] = trim($all[$i++]);<br/>
    $year_save[$i/4] = trim($all[$i++]);<br/>
}<br/>

$title[0] = $title_save[0];<br/>
$artist[0] = $artist_save[0];<br/>
$album[0] = $album_save[0];<br/>
$year[0] = $year_save[0];<br/>
$j = 0;<br/>

for ($i = 1; $i  count($title_save); $i++) {<br/>

    // Different Album<br/>
    if (($artist_save[$i] != $artist_save[$i - 1]) || ($album_save[$i] != $album_save[$i-1])) {<br/>
        $j++;<br/>
        $artist[$j] = $artist_save[$i];<br/>
        $title[$j] = $title_save[$i];<br/>
        $album[$j] = $album_save[$i];<br/>
        $year[$j] = $year_save[$i];<br/>
    }<br/>

    // Same Album<br/>
    else {<br/>
        $title[$j] = $title[$j] . ,  . $title_save[$i];<br/>
    }<br/>
}<br/>

for ($i = 0; $i  count($title); $i++) {<br/>
    echo trtd$artist[$i]/tdtd$title[$i]/tdtd$album[$i]/tdtd$year[$i]/td/tr;<br/>
}<br/>

?



Happy Kung-Tuning!