/** * Adds a file to the list. * * @param string $path Path of the file to add to the list * @return boolean If the file was successfully added to the list return true, else false */ function add($path) { $path = realpath(trim($path)); if (is_file($path)) { if (!$this->pathExist($path)) { $audioinfo = GetAllMP3info($path); if ($audioinfo["fileformat"] == 'mp3' || $audioinfo["fileformat"] == 'ogg') { $this->list[] =& new sotf_AudioFile($path); } else { $this->list[] =& new sotf_File($path); } } } return false; }
/** * Sets up sotf_AudioFile object * * @constructor sotf_AudioFile * @param string $path Path of the file */ function sotf_AudioFile($path) { $parent = get_parent_class($this); parent::$parent($path); // Call the constructor of the parent class. lk. super() $audioinfo = GetAllMP3info($this->path); if ($audioinfo["fileformat"] == 'mp3' || $audioinfo["fileformat"] == 'ogg') { $this->type = "audio"; $this->format = $audioinfo["fileformat"]; if ($audioinfo["bitrate_mode"] == 'vbr') { $this->bitrate = "VBR"; } else { $this->bitrate = $audioinfo["bitrate_audio"] / 1000; } if (!$this->bitrate) { $this->bitrate = $audioinfo["bitrate"] / 1000; } if (!$this->bitrate && $this->format == 'mp3') { $this->bitrate = $audioinfo["mpeg"]["audio"]["bitrate"] / 1000; } $this->average_bitrate = $audioinfo["bitrate_audio"] / 1000; if (!$this->average_bitrate && is_numeric($this->bitrate)) { $this->average_bitrate = $this->bitrate; } $this->samplerate = $audioinfo["frequency"]; if (!$this->samplerate && $this->format == 'mp3') { $this->samplerate = $audioinfo["mpeg"]["audio"]["frequency"]; } if (!$this->samplerate && $this->format == 'ogg') { $this->samplerate = $audioinfo["ogg"]["samplerate"]; } $this->channels = $audioinfo["channels"]; if (!$this->channels && $this->format == 'mp3') { $this->channels = $audioinfo["mpeg"]["audio"]["channels"]; } if (!$this->channels && $this->format == 'ogg') { $this->channels = $audioinfo["ogg"]["numberofchannels"]; } $this->duration = $audioinfo["playtime_seconds"]; $this->mimetype = $this->determineMimeType($this->format); } }
/** * Sets logo of the station * * @param object $file sotf_File object represents the logo * @return boolean True if the function succeeded, else false * @use $db * @use $iconWidth * @use $iconHeight */ function setLogo($file) { global $db, $iconWidth, $iconHeight; if ($file->type != "none") { $info = GetAllMP3info($file->getPath()); if ($info['png']['width'] == $iconWidth && $info['png']['height'] == $iconHeight) { if ($fp = fopen($file->getPath(), 'rb')) { $data = fread($fp, filesize($file->getPath())); fclose($fp); $this->setBlob("icon", $data); return true; } } } return false; }
// symbolic-link-resolution enhancements by davidbullock@tech-center.com $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link $TargetObjectType = filetype($TargetObject); // Check file type without examining extension if ($TargetObjectType == 'dir') { $DirectoryContents["{$currentfulldir}"]['dir']["{$file}"]['filesize'] = '-'; $DirectoryContents["{$currentfulldir}"]['dir']["{$file}"]['playtime_string'] = '-'; } else { if ($TargetObjectType == 'file') { $fileinformation = GetAllMP3info($currentfilename, FALSE); if (!isset($fileinformation['fileformat']) || $fileinformation['fileformat'] == '') { // auto-detect couldn't find the file format (probably corrupt header?), re-scan based on extension, if applicable $formatExtensions = array('mp3' => 'mp3', 'ogg' => 'ogg', 'zip' => 'zip', 'wav' => 'riff', 'avi' => 'riff', 'mid' => 'midi', 'mpg' => 'mpeg', 'jpg' => 'image', 'gif' => 'image', 'png' => 'image'); if (isset($formatExtensions[fileextension($currentfilename)])) { $fileinformation = GetAllMP3info($currentfilename, $formatExtensions[fileextension($currentfilename)]); } } if (isset($fileinformation['fileformat']) && $fileinformation['fileformat']) { $DirectoryContents["{$currentfulldir}"]['known']["{$file}"] = $fileinformation; } else { $DirectoryContents["{$currentfulldir}"]['other']["{$file}"]['filesize'] = filesize($currentfilename); $DirectoryContents["{$currentfulldir}"]['other']["{$file}"]['playtime_string'] = '-'; } } } } $endtime = getmicrotime(); closedir($handle); echo 'done<BR>'; echo 'Directory scanned in ' . number_format($endtime - $starttime, 2) . ' seconds.<BR>';
function RemoveID3v2($filename, $showerrors = FALSE) { // File MUST be writeable - CHMOD(646) at least. It's best if the // directory is also writeable, because that method is both faster and less susceptible to errors. if (is_writeable(dirname($filename))) { // preferred method - only one copying operation, minimal chance of corrupting // original file if script is interrupted, but required directory to be writeable if ($fp_source = @fopen($filename, 'rb')) { $OldMP3fileInfo = GetAllMP3info($filename); rewind($fp_source); if ($OldMP3fileInfo['audiodataoffset'] !== FALSE) { fseek($fp_source, $OldMP3fileInfo['audiodataoffset'], SEEK_SET); } if ($fp_temp = @fopen($filename . 'getid3tmp', 'w+b')) { // while (($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) !== FALSE) { while ($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_temp); } else { $error .= 'Could not open ' . $filename . 'getid3tmp mode "w+b"<BR>'; } fclose($fp_source); } else { $error .= 'Could not open ' . $filename . ' mode "rb"<BR>'; } if (file_exists($filename)) { unlink($filename); } rename($filename . 'getid3tmp', $filename); } else { if (is_writable($filename)) { // less desirable alternate method - double-copies the file, overwrites original file // and could corrupt source file if the script is interrupted or an error occurs. if ($fp_source = @fopen($filename, 'rb')) { $OldMP3fileInfo = GetAllMP3info($filename); rewind($fp_source); if ($OldMP3fileInfo['audiodataoffset'] !== FALSE) { fseek($fp_source, $OldMP3fileInfo['audiodataoffset'], SEEK_SET); } if ($fp_temp = tmpfile()) { // while (($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) !== FALSE) { while ($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_source); if ($fp_source = @fopen($filename, 'wb')) { rewind($fp_temp); // while (($buffer = fread($fp_temp, FREAD_BUFFER_SIZE)) !== FALSE) { while ($buffer = fread($fp_temp, FREAD_BUFFER_SIZE)) { fwrite($fp_source, $buffer, strlen($buffer)); } fseek($fp_temp, -128, SEEK_END); fclose($fp_source); } else { $error .= 'Could not open ' . $filename . ' mode "wb"<BR>'; } fclose($fp_temp); } else { $error .= 'Could not create tmpfile()<BR>'; } } else { $error .= 'Could not open ' . $filename . ' mode "rb"<BR>'; } } else { $error .= 'Directory and file both not writeable<BR>'; } } if ($error) { if ($showerrors) { echo $error; } return FALSE; } else { return TRUE; } }
// delete tags if ($VersionToEdit1 == '1') { echo 'ID3v1 tag' . (RemoveID3v1($EditorFilename, TRUE) ? '' : ' NOT') . ' successfully deleted<BR>'; } if ($VersionToEdit2 == '2') { echo 'ID3v2 tag' . (RemoveID3v2($EditorFilename, TRUE) ? '' : ' NOT') . ' successfully deleted<BR>'; } } } echo '<A HREF="' . $PHP_SELF . '">Start Over</A><BR>'; echo '<TABLE BORDER="0"><FORM ACTION="' . $PHP_SELF . '" METHOD="POST" ENCTYPE="multipart/form-data">'; echo '<TR><TD ALIGN="CENTER" COLSPAN="2"><B>Sample ID3v2 editor</B></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Filename</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorFilename" VALUE="' . FixTextFields($EditorFilename) . '"></TD></TR>'; if ($EditorFilename) { if (file_exists($EditorFilename)) { $OldMP3fileInfo = GetAllMP3info($EditorFilename); $EditorTitle = $OldMP3fileInfo['title']; $EditorArtist = $OldMP3fileInfo['artist']; $EditorAlbum = $OldMP3fileInfo['album']; $EditorYear = $OldMP3fileInfo['year']; $EditorTrack = $OldMP3fileInfo['track']; $EditorComment = $OldMP3fileInfo['comment']; if (isset($OldMP3fileInfo['genre'])) { $EditorGenre = LookupGenre($OldMP3fileInfo['genre'], TRUE); } else { $EditorGenre = 255; } echo '<TR><TD ALIGN="RIGHT"><B>Title</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorTitle" VALUE="' . FixTextFields($EditorTitle) . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Artist</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorArtist" VALUE="' . FixTextFields($EditorArtist) . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Album</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorAlbum" VALUE="' . FixTextFields($EditorAlbum) . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Year</B></TD><TD><INPUT TYPE="TEXT" SIZE="4" NAME="EditorYear" VALUE="' . FixTextFields($EditorYear) . '"></TD></TR>';
if (!is_file($filepath)) { raiseError("no_such_file"); } // prepare playlist for streaming into icecast $fp = fopen($tmpfile, 'wb'); /* TODO: add jingle $jinglefile = $repo->getStationJingle($station); if (!is_object($jinglefile)) { fwrite($fp,$jinglefile . "\n"); } */ fwrite($fp, $filepath . "\n"); fclose($fp); // prepare streaming command $mp3info = GetAllMP3info($filepath); $bitrate = (string) $mp3info['mpeg']['audio']['bitrate']; $mystreamCmd = str_replace('__PLAYLIST__', $tmpfile, $streamCmd); $mystreamCmd = str_replace('__NAME__', $name, $mystreamCmd); $mystreamCmd = str_replace('__BITRATE__', $bitrate, $mystreamCmd); debug("Cmd", $mystreamCmd); debug("Url", $url); exec($mystreamCmd); //$res = exec($mystreamCmd); //debug("Cmd output", $res); // send playlist to client header("Content-type: audio/x-mpegurl\n"); //header("Content-transfer-encoding: binary\n"); header("Content-length: " . strlen($url) . "\n"); // send playlist echo $url;