require_once "../inc/base.php"; $iamincluded = true; require_once "../player/metadata.php"; header("Content-Type: text/plain"); try { $pl = get_playback(); $info = $pl->getCurrentSong(); $pl->disconnect(); $rlyric = ""; if (isset($info['Artist']) && isset($info['Title'])) { $file = get_lyric_filename($info['Artist'], $info['Title']); $lyric = false; if (file_exists($file)) { $lyric = _get_lyric_cache($file, $info['file']); } else { $lyric = @_get_lyric_lyricwiki($info['Artist'], $info['Title'], $info['file']); } if ($lyric !== FALSE) { $lyric = simplexml_load_string($lyric); if ($lyric && $lyric->result->lyric) { $lyric = (string) $lyric->result->lyric; $lyric = explode("\n", $lyric); $lines = count($lyric); $tmp = ""; /* try until we hit something */ while (strlen($tmp) <= 0 && $lines > 0) { $tmp = $lyric[rand(0, count($lyric) - 1)]; if (strlen($tmp)) { $rlyric = substr(trim($tmp), 0, 60); if ($rlyric) { $rlyric = " -~\"" . $rlyric . "\"";
function get_lyric($info = null) { header("Content-Type: text/xml; charset=UTF-8"); ob_end_clean(); if (is_null($info)) { $info = get_current_info(); } if (!$info) { $xml = array_to_xml(array("result" => "failed")); echo $xml->asXML(); exit; } $artist = $info[0]; $title = $info[1]; $file_name = $info[2]; $file = get_lyric_filename($artist, $title); if (file_exists($file) && !isset($_GET['force'])) { $xml = _get_lyric_cache($file, $file_name); if ($xml) { echo $xml; exit; } } $xml = _get_lyric_lyricwiki($artist, $title, $file_name); if ($xml) { echo $xml; } else { echo array_to_xml(array("result" => "failed"))->asXML(); } exit; }