PHP-Recent tracks modification

Kirjoittanut . Liittyy aiheisiin , , .

Arkistomatskua

Otathan huomioon, että tämä on yli 17 vuotta vanha artikkeli, joten sisältö ei ole välttämättä ihan ajan tasalla. Olin artikkelin kirjoittamishetkellä 19-vuotias.

I love last.fm. I first registered because I wanted to list my recently listened tracks on my website. I found a plugin for WordPress by Marc Hodges which doesn’t seem to work in WordPress 2.2.2. So, I was browsing last.fm forums and I found good-old Recent Tracks-script by astoever. I wasn’t pleased with the original, so I customized it a bit.

(below is the original writing I posted on the forum)

I wanted ”time x ago”-timestamp, so I did one. I’m not good at php but here’s the result:

$trackArray = explode(”,”, $track[$i]);

$entry = explode(”?”, $trackArray[1]);

echo ”<li class=\”song\”><span class=\”artist\”>”.$entry[0].”</span><br /><span class=\”title\”>”.$entry[1].”</li>”;

$now = time();
$played = date($trackArray[0]);
$lastplayed = $now – $played;

$minutes = $lastplayed / 60;
$hours = $lastplayed / 3600;
$days = $lastplayed / 86400;

if ($minutes > 60) {
echo ”<br /><span class=\”time\”>”.round($hours, 0).” hours ”;
} else {
echo ”<br /><span class=\”time\”>”.round($minutes, 0).” minutes ”;
}
if ($hours > 24) {
echo ”<br /><span class=\”time\”>”.round($days, 0).” days ”;
}

echo ”ago</span></li>”;

}
echo $wrapperEnd;
}

?>

(if you want to try, replace this with the end of the code; note ”echo $wrapperEnd; -> replace the original ending with this…)

the Code is yet under construction. I’ll develop it a bit but yet decided to tell this…

Btw what’s the point with question marks between the artist and song (for example ”Dream Theater ? Octavarium”). I split those because I wanted them to be on different lines.

I also have band-artwork but that aint gonna tell you (yet) :)

What do you think?
Seems to work for me, for now.

Working demo (rollemaa.fi/scrobbler-example.php) with temp-stylesheets (rollemaa.fi has been a bit slow recently though). Oh, almost forgot, thanks Nikke for those little tips.

Piditkö tekstistä? Tarjoa kahvit!

Kuva Roni Laukkarisesta

Roni Laukkarinen

Kirjoittaja on 35-vuotias elämäntapanörtti, ammatiltaan yrittäjä ja teknologiajohtaja perustamassaan digitoimistossa, verkkosivujen tekijä, koukussa kirjoittamiseen 5-vuotiaasta. Päivät kuluu monipuolisen musiikkiharrastuksen, retropelien ja koodaamisen parissa, mutta arkea piristyttää myös vaimo ja kaksi lasta. Mastodon ja leffat lähellä sydäntä.

Lue Rollesta lisää

Reaktiot

Vaadittu kenttä