/** * Avvia un Job in coda * * @param array $params * @param LoggerInterface $logger (optional) * @return bool */ public function run() { $fs = new Filesystem(); $taskId = $this->getParam('taskId'); $taskModel = TaskModel::where('id', '=', $taskId)->firstOrFail(); $this->setLogContext($taskModel->toArray()); $jobModel = $taskModel->job()->first(); $fileModel = $jobModel->files()->first(); //prendi il jobservice col dao del job associato al task settato $job = $taskModel->job()->firstOrFail(); $this->logInfo("Controllo della directory "); $service = new JobService(); $service->setDao($job); $folder = $service->resolveArtifactsPath(); $fsM = SymfonyFileSystemManager::getInstance(); $fsM->createDir($folder, '0700', true); $input = $fileModel->path; $output = $folder . DIRECTORY_SEPARATOR . BinaryFile::resolveName(); //transcoding $transcoder = JambonCoreFactory::getInstance(); $resolution = $this->resolveResolution($taskModel); $taskModel->updateResolution($resolution); $taskModel->setStarted(); $transcoder->initTranscodeOperation($taskModel->format, false, $resolution, 2, $input, $output); $ffprobeInfo = $transcoder->performTranscodeOperation(); $output = $transcoder->getOutputPath(); $taskModel->setCompleted(); $ffprobeInfoArray = @json_decode($ffprobeInfo, true); if (!empty($ffprobeInfoArray)) { //risoluzione del filename in output $fileName = $fileModel->getName(); $vanillaName = pathinfo($fileName, PATHINFO_FILENAME); $extension = pathinfo($output, PATHINFO_EXTENSION); $name = $vanillaName . '_' . $resolution . '.' . $extension; //salvataggio del model file in db $fileModel = FileModel::create($output, FileModel::FILE_ROLE_ARTIFACT, $name); //salvataggio del ffprobe $fileModel->setMeta(FileModel::META_FFPROBE_KEY, $ffprobeInfoArray, true); $fileModel->updateFileHash(); $taskModel->files()->attach($fileModel->id); $taskModel->save(); } else { throw new \Exception("Error Processing transcoding"); } //se non ci sono task aperti chiudo il job //$shouldCloseJob = (TaskModel::where('completed_at', '=', null)->count() === 0); //dump($shouldCloseJob); // if($shouldCloseJob) { // } }
/** * Scarica il file e ne crea una entry in database * * @throw Exception * @param string $url * @param string $fileName (optional) * @return FileModel */ public function downloadSource($url, $fileName = null) { $fsM = SymfonyFileSystemManager::getInstance(); $basePath = $this->resolveSourcePath(); //risoluzione del path $fsM->createDir($basePath, '0700', true); $file = BinaryFile::fromDownloadChunked($url, null, $basePath, function ($bytesCount, $totalSize) { if ($totalSize) { $perc = $bytesCount * 100 / $totalSize; $string = "Downloading: {$perc}%"; $back = strlen($string); echo "[{$back}D" . $string; } else { echo $bytesCount . '\\n'; } }); $path = $file->getPath(); $fileModel = FileModel::create($path, FileModel::FILE_ROLE_SOURCE, $fileName); $ffprobeInfo = shell_exec("ffprobe -v quiet -print_format json -show_format -show_streams {$path} 2>&1"); $fileModel->setMeta(FileModel::META_FFPROBE_KEY, json_decode($ffprobeInfo, true), true); return $fileModel; }