/** * @param $asset_path * @return string|void json encoded metadata collection for asset given * @throws \Exception */ public function analyze($asset_path) { $msg = "Received path spec: {$asset_path}"; $this->report[] = $msg; static::$logger->addInfo($msg); if (static::$manager->has($asset_path)) { $msg = "File not found at path: {$asset_path}"; $this->report[] = $msg; static::$logger->addInfo($msg); } $mimes = new MimeTypes(); $mimeType = $mimes->getMimeType(pathinfo($asset_path, PATHINFO_EXTENSION)); $msg = "Selecting analyzer by mime-type: {$mimeType}"; $this->report[] = $msg; static::$logger->addInfo($msg); if (strpos($asset_path, '://') !== false) { list($protocol, $path) = explode('://', $asset_path); } else { $protocol = 'default'; $path = $asset_path; } $base_path = core_config($protocol . '.local'); $abs_file_path = $base_path . DS . $path; $msg = "Derived absolute path to asset file: {$abs_file_path}"; $this->report[] = $msg; static::$logger->addInfo($msg); // TODO make this external - config values $ffprobe_config = array('ffmpeg.binaries' => '/usr/bin/ffmpeg', 'ffprobe.binaries' => '/usr/bin/ffprobe', 'timeout' => 3600, 'ffmpeg.threads' => 12); if (strpos($mimeType, 'image') === 0) { return $this->ingestImageAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'video') === 0) { return $this->ingestVideoAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'audio') !== false) { return $this->ingestAudioAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'text') !== false) { return $this->ingestTextAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'json') !== false) { return $this->ingestJSONAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'msword') !== false) { return $this->ingestMSWordAsset($abs_file_path, $mimeType, $ffprobe_config); } elseif (strpos($mimeType, 'pdf') !== false) { return $this->ingestPDFAsset($abs_file_path, $mimeType, $ffprobe_config); } else { $mimeType = 'other'; return $this->ingestOtherAsset($abs_file_path, $mimeType, $ffprobe_config); } }
public function testGetMimeTypeUndefined() { $this->assertEquals(null, $this->mime->getMimeType('undefined')); }
/** * Get MIME type of a file. * @param string $fileName File name or path. * @return string A MIME type. */ public function getMimeType($fileName) { return $this->mimeTypes->getMimeType(\Jivoo\Utilities::getFileExtension($fileName)); }