/** * Extracts media metadata using MediaInfo * * @param string $ps_filepath file path * @param string $ps_mediainfo_path optional path to MediaInfo binary. If omitted the path configured in external_applications.conf is used. * * @return array Extracted metadata */ function caExtractMetadataWithMediaInfo($ps_filepath, $ps_mediainfo_path = null) { if (!$ps_mediainfo_path) { $ps_mediainfo_path = caGetExternalApplicationPath('mediainfo'); } if (!caIsValidFilePath($ps_mediainfo_path)) { return false; } // // TODO: why don't we parse this from the XML output like civilized people? // exec($ps_mediainfo_path . " " . caEscapeShellArg($ps_filepath), $va_output, $vn_return); $vs_cat = "GENERIC"; $va_return = array(); foreach ($va_output as $vs_line) { $va_split = explode(":", $vs_line); $vs_left = trim(array_shift($va_split)); $vs_right = trim(join(":", $va_split)); if (strlen($vs_right) == 0) { // category line $vs_cat = strtoupper($vs_left); continue; } if (strlen($vs_left) && strlen($vs_right)) { if ($vs_left != "Complete name") { // we probably don't want to display temporary filenames $va_return[$vs_cat][$vs_left] = $vs_right; } } } return $va_return; }
/** * Detects if PDFMiner (http://www.unixuser.org/~euske/python/pdfminer/index.html) is installed in the given path. * @param string $ps_pdfminer_path path to PDFMiner * @return boolean */ function caPDFMinerInstalled($ps_pdfminer_path = null) { if (!$ps_pdfminer_path) { $ps_pdfminer_path = caGetExternalApplicationPath('pdfminer'); } global $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER; if (isset($_MEDIAHELPER_PLUGIN_CACHE_PDFMINER[$ps_pdfminer_path])) { return $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER[$ps_pdfminer_path]; } else { $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER = array(); } if (!caIsValidFilePath($ps_pdfminer_path)) { return false; } if (!file_exists($ps_pdfminer_path)) { return $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER[$ps_pdfminer_path] = false; } if (caGetOSFamily() == OS_WIN32) { return true; } // don't try exec test on Windows exec($ps_pdfminer_path . " > /dev/null", $va_output, $vn_return); if ($vn_return == 100) { return $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER[$ps_pdfminer_path] = true; } return $_MEDIAHELPER_PLUGIN_CACHE_PDFMINER[$ps_pdfminer_path] = false; }