Ejemplo n.º 1
0
 /**
  * Reads audio file record from database and generates audio preview.
  */
 public function preview()
 {
     Logger::printf("Requested preview for track %s", $this->track_id);
     if ($this->hasPreview()) {
         Logger::printf("Track preview is available (file_id is %s)", $this->track_data[TSongs::PREVIEW_ID]);
         FileServer::sendToClient($this->track_data[TSongs::PREVIEW_ID]);
         return;
     }
     Logger::printf("Track preview is unavailable");
     Logger::printf("Generating new track preview in real time");
     header("Content-Type: " . PREVIEW_MIME);
     $temp_file = TempFileProvider::generate("preview", ".mp3");
     $filename = FileServer::getFileUsingId($this->track_data[TSongs::FILE_ID]);
     $command_template = "%s -i %s -bufsize 256k -vn -ab 128k -ac 2 -acodec libmp3lame -f mp3 - | tee %s";
     $command = sprintf($command_template, $this->settings->get("tools", "ffmpeg_cmd"), escapeshellarg($filename), escapeshellarg($temp_file));
     passthru($command);
     $temp_file_id = FileServer::register($temp_file, PREVIEW_MIME);
     Logger::printf("New preview registered => %s", $temp_file_id);
     SongDao::updateSongUsingId($this->track_id, [TSongs::PREVIEW_ID => $temp_file_id]);
 }
Ejemplo n.º 2
0
 public function doGet($id)
 {
     FileServer::sendToClient($id);
 }