| | 99 | $recodeTo = setting('MusicStreamRecodeBitRate', hostname); |
| | 100 | |
| | 101 | if ($mime == 'audio/mpeg' && isset($recodeTo) && $recodeTo > 0) |
| | 102 | { |
| | 103 | // use lame to recode the file to the required bit-rate. |
| | 104 | // Local file? |
| | 105 | if (file_exists("$basepath/$path/$fname")) { |
| | 106 | $handle = fopen("$basepath/$path/$fname", 'r'); |
| | 107 | } |
| | 108 | // Otherwise, send it via the backend |
| | 109 | else { |
| | 110 | global $Master_Host; |
| | 111 | $port = _or(get_backend_setting('BackendStatusPort', $Master_Host), |
| | 112 | get_backend_setting('BackendStatusPort')); |
| | 113 | $handle = fopen("http://$Master_Host:$port/Myth/$xml_command?Id=".$xml_id, 'r'); |
| | 114 | } |
| | 115 | |
| | 116 | $songInfoCmd = '--id3v2-only' . |
| | 117 | ' --tt "' . escapeshellcmd($songInfo['name']) . '"' . |
| | 118 | ' --tn "' . escapeshellcmd($songInfo['track']) . '"' . |
| | 119 | ' --ty "' . escapeshellcmd($songInfo['year']) . '"' . |
| | 120 | ' --tl "' . escapeshellcmd($songInfo['album_name']) . '"' . |
| | 121 | ' --ta "' . escapeshellcmd($songInfo['artist_name']) . '"'; |
| | 122 | $desc = array( 0 => array("pipe", "r"), |
| | 123 | 1 => array("pipe", "w"), |
| | 124 | 2 => array("pipe", "w") ); |
| | 125 | $pipes = array(); |
| | 126 | $process = proc_open("lame --mp3input -b" . $recodeTo . " --cbr " . $songInfoCmd . " - -", $desc, $pipes); |
| | 127 | |
| | 128 | if (is_resource($process)) |
| | 129 | { |
| | 130 | while ($buf = fread($handle, 8192)) |
| | 131 | { |
| | 132 | fwrite($pipes[0], $buf); |
| | 133 | echo fread($pipes[1], 8192); |
| | 134 | } |
| | 135 | fclose($pipes[0]); |
| | 136 | fclose($pipes[1]); |
| | 137 | fclose($pipes[2]); |
| | 138 | } |
| | 139 | fclose($handle); |
| | 140 | exit; |
| | 141 | } |
| | 142 | |