diff -r 000000000000 -r c63de9eb7045 functions.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/functions.php Sun Mar 23 14:59:33 2008 -0400 @@ -0,0 +1,124 @@ + $tmpfile"); + $output = @file_get_contents($tmpfile); + @unlink($tmpfile); + $output = trim($output); + + // detect type of output + if ( $output == 'true' ) + return true; + else if ( $output == 'false' ) + return false; + else if ( preg_match('/^-?[0-9]+/', $output) ) + return intval($output); + else + return $output; +} + +/** + * Rebuilds the copy of the playlist in RAM + */ + +function rebuild_playlist() +{ + // import what we need + global $homedir, $playlist; + // sync and load the playlist file + $playlist_file = dcop_action('playlist', 'saveCurrentPlaylist'); + // start XML parser + try + { + $xml = simplexml_load_file($playlist_file); + } + catch ( Exception $e ) + { + burnout("Caught exception trying to load playlist file:\n$e"); + } + $attribs = $xml->attributes(); + if ( @$attribs['product'] != 'Amarok' ) + { + burnout('Playlist is not in Amarok format'); + } + $playlist = array(); + foreach ( $xml->children() as $child ) + { + $attribs = $child->attributes(); + $item = array( + 'uri' => $attribs['uri'], + 'title' => strval($child->Title), + 'artist' => strval($child->Artist), + 'album' => strval($child->Album), + 'length' => seconds_to_str(intval($child->Length)) + ); + $playlist[] = $item; + } +} + +/** + * Converts a number to minute:second format + * @param int Seconds + * @return string format: mm:ss + */ + +function seconds_to_str($secs) +{ + $seconds = $secs % 60; + $minutes = ( $secs - $seconds ) / 60; + $seconds = strval($seconds); + $minutes = strval($minutes); + if ( strlen($seconds) < 2 ) + $seconds = "0$seconds"; + if ( strlen($minutes) < 2 ) + $minutes = "0$minutes"; + return "$minutes:$seconds"; +} +