Hi there,
I was given a script that publishs what I am listening to on my winamp mp3 player to my website. The script listed below reads a file called playlist.js and then lists the 50 most recent tunes I have played.
Now I would like to have an addon script that will allow me to also show on my frontpage the current track being played.
But with the code as it stands all I will get is the 50 played tracks.
I still want to retain my page with the 50 tracks on but also have a page that shows what I am playing right now.
Can anyone advise or have any code to do this?
/* How to use cafeAmp:
Upload cafeAmp.php in playlist.js's directory.
Include this PHP code in your page:
[?php
include('cafeAmp.php');
$blogamp = new cafeAmp();
$blogamp->display();
?]
(replace '[' with '<' and ']' with '>')
Then make a file named cafeAmp_template.txt in the same directory.
example: [url]http://tidakada.com/cafeAmp_template.txt[/url]
Look down for template tags. */
/* Template tags:
{blogamp_songs} at the start of the template, and {/blogamp_songs} at the end
{$blogamp_lenght} : lenght of the song, in format 0:00
{$blogamp_samplerate} : sample rate, usually 22 or 44
{$blogamp_bitrate} : bit rate, usually 128
{$blogamp_channels} : "stereo" or "mono"
{$blogamp_title} : complete title of the song 'artist - song'
{$blogamp_song} : name of the song
{$blogamp_artist} : band/artist's name
{$blogamp_year}
{$blogamp_month}
{$blogamp_day}
{$blogamp_hour}
{$blogamp_minute}
{$blogamp_second}
note: month, day, hour, minute, second have a leading zero if < 10 */
class cafeAmp {
var $url = '../playlist/playlist.js';
var $songs = 'all';
var $template_string = '';
var $template_file = '../playlist/cafeAmp_template.txt';
var $echo = 1;
/* usage: $this->assign('var','value'); */
function assign($var, $value) {
$this->$var = $value;
}
/* usage: $this->display('url' [, those optional parameters below ]); */
function display($blogamp_file = 'blah', $blogamp_songs = 'blah', $blogamp_template_string = 'blah', $blogamp_template_file = 'blah', $blogamp_echo = 'blah') {
if ($blogamp_file == 'blah') { $blogamp_file = $this->url; }
if ($blogamp_songs == 'blah') { $blogamp_songs = $this->songs; }
if ($blogamp_template_string == 'blah') { $blogamp_template_string = $this->template_string; }
if ($blogamp_template_file == 'blah') { $blogamp_template_file = $this->template_file; }
if ($blogamp_echo == 'blah') { $blogamp_echo = $this->echo; }
/* opens the BlogAmp playlist.js file */
$f = fopen($blogamp_file,'r');
while (!feof($f)) {
$content .= fgets($f, 1024);
}
fclose($f);
/* gets playlist.js songs info*/
preg_match_all("'new song\( (.+?),(.+?),(.+?),(.+?),\"(.+?)\",(.+?),(.+?),(.+?),(.+?),(.+?),(.+?) \)'s", $content, $blogamp_infos);
$songs_lenght = $blogamp_infos[1];
$songs_samplerate = $blogamp_infos[2];
$songs_bitrate = $blogamp_infos[3];
$songs_channels = $blogamp_infos[4];
$songs_title = $blogamp_infos[5];
$songs_year = $blogamp_infos[6];
$songs_month = $blogamp_infos[7];
$songs_day = $blogamp_infos[8];
$songs_hour = $blogamp_infos[9];
$songs_minute = $blogamp_infos[10];
$songs_second = $blogamp_infos[11];
/* gets the template */
if (empty($blogamp_template_string)) {
$f = fopen($blogamp_template_file, 'r');
$blogamp_template = fread($f, filesize($blogamp_template_file));
fclose($f);
} else {
$blogamp_template = $blogamp_template_string;
}
preg_match_all("'{blogamp_songs}(.+?){/blogamp_songs}'si", $blogamp_template, $blogamp_template_loop);
$blogamp_template_loop = $blogamp_template_loop[1][0];
$blogamp_template = str_replace('{blogamp_songs}','',$blogamp_template);
$blogamp_template = str_replace('{/blogamp_songs}','',$blogamp_template);
/* processes the template - BlogAmp songs info */
$blogamp_template_loop_processed = '';
$k = count($songs_title);
$j = (($blogamp_songs == 'all') || ($blogamp_songs > $k)) ? $k : intval($blogamp_songs);
for ($i = 0; $i<$j; $i++) {
$tmp_template = $blogamp_template_loop;
$tmp_lenght = (intval($songs_lenght[$i] / 60)).':'.$this->leadzero(($songs_lenght[$i]-((intval($songs_lenght[$i] / 60))*60)),2);
$tmp_samplerate = $songs_samplerate[$i];
$tmp_bitrate = $songs_bitrate[$i];
$tmp_channels = ($songs_channels[$i] == 2) ? 'stereo' : 'mono';
$tmp_title = stripslashes($songs_title[$i]);
$blah = explode(' - ', $tmp_title);
$tmp_song = trim($blah[0]);
$tmp_artist = trim($blah[1]);
$tmp_year = $songs_year[$i];
$tmp_month = $this->leadzero($songs_month[$i], 2);
$tmp_day = $this->leadzero($songs_day[$i],2);
$tmp_hour = $this->leadzero($songs_hour[$i],2);
$tmp_minute = $this->leadzero($songs_minute[$i],2);
$tmp_second = $this->leadzero($songs_second[$i],2);
$tmp_template = str_replace('{$blogamp_lenght}',$tmp_lenght, $tmp_template);
$tmp_template = str_replace('{$blogamp_samplerate}',$tmp_samplerate, $tmp_template);
$tmp_template = str_replace('{$blogamp_bitrate}',$tmp_bitrate, $tmp_template);
$tmp_template = str_replace('{$blogamp_channels}',$tmp_channels, $tmp_template);
$tmp_template = str_replace('{$blogamp_title}',$tmp_title, $tmp_template);
$tmp_template = str_replace('{$blogamp_song}',$tmp_song, $tmp_template);
$tmp_template = str_replace('{$blogamp_artist}',$tmp_artist, $tmp_template);
$tmp_template = str_replace('{$blogamp_year}',$tmp_year, $tmp_template);
$tmp_template = str_replace('{$blogamp_month}',$tmp_month, $tmp_template);
$tmp_template = str_replace('{$blogamp_day}',$tmp_day, $tmp_template);
$tmp_template = str_replace('{$blogamp_hour}',$tmp_hour, $tmp_template);
$tmp_template = str_replace('{$blogamp_minute}',$tmp_minute, $tmp_template);
$tmp_template = str_replace('{$blogamp_second}',$tmp_second, $tmp_template);
$blogamp_template_loop_processed .= $tmp_template;
}
$blogamp_template = str_replace($blogamp_template_loop, $blogamp_template_loop_processed, $blogamp_template);
clearstatcache();
/* echoes or returns the processed template :) */
if ($blogamp_echo) {
echo $blogamp_template;
} else {
return $blogamp_template;
}
}
function leadzero($number,$threshold) { // function to add leading zeros when necessary
$l=strlen($number);
if ($l<$threshold)
for ($i=0; $i<($threshold-$l); $i=$i+1) { $number="0".$number; }
return($number);
}
}
?>
This is a bit too complex for me 🙁
Thank a lot