/** * */ public function __construct() { parent::__construct(); $this->info['NAME'] = 'wkhtmltopdf'; $this->set('CODE', 'wkhtmltopdf'); $this->description = _t('Renders HTML as PDF using wkhtmltopdf'); $this->ops_wkhtmltopdf_path = caGetExternalApplicationPath('wkhtmltopdf'); }
/** * */ public function __construct() { parent::__construct(); $this->info['NAME'] = 'PhantomJS'; $this->set('CODE', 'PhantomJS'); $this->description = _t('Renders HTML as PDF using PhantomJS'); $this->ops_phantom_path = caGetExternalApplicationPath('phantomjs'); }
/** * * * @param string $ps_source * @param array $pa_options * @return bool */ public function read($ps_source, $pa_options = null) { $vs_path_to_exif_tool = caGetExternalApplicationPath("exiftool"); $this->opn_current_row = -1; $this->opa_row_buf = caMakeArrayKeysLowercase(caExtractMetadataWithExifTool($ps_source)); if (!is_array($this->opa_row_buf)) { return false; } return true; }
public function register() { $this->opo_config = Configuration::load(); $vs_external_app_config_path = $this->opo_config->get('external_applications'); $this->opo_external_app_config = Configuration::load($vs_external_app_config_path); $this->ops_path_to_ffmpeg = $this->opo_external_app_config->get('ffmpeg_app'); $this->ops_mediainfo_path = caGetExternalApplicationPath('mediainfo'); $this->opb_mediainfo_available = caMediaInfoInstalled(); $this->opb_ffmpeg_available = caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg); $this->info["INSTANCE"] = $this; return $this->info; }
public function write($ps_filepath, $ps_mimetype) { if (!$this->handle) { return false; } $this->properties["width"] = $this->properties["version_width"]; $this->properties["height"] = $this->properties["version_height"]; # is mimetype valid? if (!($vs_ext = $this->info["EXPORT"][$ps_mimetype])) { $this->postError(1610, _t("Can't convert file to %1", $ps_mimetype), "WLPlugMediaMesh->write()"); return false; } switch ($ps_mimetype) { case 'application/ctm': if (file_exists($this->filepath) && caOpenCTMInstalled()) { exec(caGetExternalApplicationPath('openctm') . ' ' . caEscapeShellArg($this->filepath) . " " . caEscapeShellArg($ps_filepath) . ".ctm --method MG2 --level 9 2>&1", $va_output); return "{$ps_filepath}.ctm"; } else { @unlink("{$ps_filepath}.ctm"); //$this->postError(1610, _t("Couldn't convert %1 model to ctm", $this->properties['mimetype']), "WLPlugMediaMesh->write()"); //return false; } break; default: # pretty restricted, but we can convert ply to stl! if ($this->properties['mimetype'] == 'application/ply' && $ps_mimetype == 'application/stl') { if (file_exists($this->filepath)) { if (caMeshlabServerInstalled()) { putenv("DISPLAY=:0"); chdir('/usr/local/bin'); exec(caGetExternalApplicationPath('meshlabserver') . " -i " . caEscapeShellArg($this->filepath) . " -o " . caEscapeShellArg($ps_filepath) . ".stl 2>&1", $va_output); return "{$ps_filepath}.stl"; } elseif (PlyToStl::convert($this->filepath, $ps_filepath . '.stl')) { return "{$ps_filepath}.stl"; } else { @unlink("{$ps_filepath}.stl"); $this->postError(1610, _t("Couldn't convert ply model to stl"), "WLPlugMediaMesh->write()"); return false; } } } break; } # use default media icons return __CA_MEDIA_3D_DEFAULT_ICON__; }
/** * Extracts media metadata using ExifTool * * @param string $ps_filepath file path * @param bool $pb_skip_unknown If set to true, exiftool won't try to extract unknown tags from the source file * Use this if metadata extraction fails for unknown reasons. Sometimes tools like Photoshop write weird * binary data into the files that causes json_decode to barf. * * @return array|null Extracted metadata, null if exiftool is not installed or something went wrong */ function caExtractMetadataWithExifTool($ps_filepath, $pb_skip_unknown = false) { if (caExifToolInstalled()) { $vs_unknown_param = $pb_skip_unknown ? '' : '-u'; $vs_path_to_exif_tool = caGetExternalApplicationPath('exiftool'); exec("{$vs_path_to_exif_tool} -json -a {$vs_unknown_param} -g1 " . caEscapeShellArg($ps_filepath) . " 2> /dev/null", $va_output, $vn_return); if ($vn_return == 0) { $va_data = json_decode(join("\n", $va_output), true); if (!is_array($va_data)) { return null; } $va_data = array_shift($va_data); if (sizeof($va_data) > 0) { return $va_data; } } } return null; }
/** * */ public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null) { if (!caMediaPluginFFmpegInstalled()) { return false; } $o_tc = new TimecodeParser(); $vn_start = $vn_end = null; if ($o_tc->parse($ps_start)) { $vn_start = $o_tc->getSeconds(); } if ($o_tc->parse($ps_end)) { $vn_end = $o_tc->getSeconds(); } if (!$vn_start || !$vn_end) { return null; } if ($vn_start >= $vn_end) { return null; } $vn_duration = $vn_end - $vn_start; exec(caGetExternalApplicationPath('ffmpeg') . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration} -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); if ($vn_return != 0) { @unlink($ps_filepath); $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()"); return false; } return true; }
/** * Embed media metadata into given file. Embedding is performed on a copy of the file and placed into the * system tmp directory. The given file is never modified. * * @param string $ps_file The file to embed metadata into * @param string $ps_table Table name of the subject record. This is used to figure out the appropriate mapping to use from media_metadata.conf * @param int $pn_pk Primary key of the subject record. This is used to run the export for the right record. * @param string $ps_type_code Optional type code for the subject record * @param int $pn_rep_pk Primary key of the subject representation. * If there are export mapping for object representations, we run them after the mapping for the subject table. * Fields that get exported here should overwrite fields from the subject table export. * @param string $ps_rep_type_code type code for object representation * @return string File name of a temporary file with the embedded metadata, false on failure */ function caEmbedMediaMetadataIntoFile($ps_file, $ps_table, $pn_pk, $ps_type_code, $pn_rep_pk, $ps_rep_type_code) { require_once __CA_MODELS_DIR__ . '/ca_data_exporters.php'; if (!caExifToolInstalled()) { return false; } // we need exiftool for embedding $vs_path_to_exif_tool = caGetExternalApplicationPath('exiftool'); if (!file_exists($ps_file)) { return false; } if (!preg_match("/^image\\//", mime_content_type($ps_file))) { return false; } // Don't try to embed in files other than images // make a temporary copy (we won't touch the original) copy($ps_file, $vs_tmp_filepath = caGetTempDirPath() . "/" . time() . md5($ps_file)); // // SUBJECT TABLE // if ($vs_subject_table_export = caExportMediaMetadataForRecord($ps_table, $ps_type_code, $pn_pk)) { $vs_export_filename = caGetTempFileName('mediaMetadataSubjExport', 'xml'); if (@file_put_contents($vs_export_filename, $vs_subject_table_export) === false) { return false; } exec("{$vs_path_to_exif_tool} -tagsfromfile {$vs_export_filename} -all:all " . caEscapeShellArg($vs_tmp_filepath), $va_output, $vn_return); @unlink($vs_export_filename); @unlink("{$vs_tmp_filepath}_original"); } // // REPRESENTATION // if ($vs_representation_Export = caExportMediaMetadataForRecord('ca_object_representations', $ps_rep_type_code, $pn_rep_pk)) { $vs_export_filename = caGetTempFileName('mediaMetadataRepExport', 'xml'); if (@file_put_contents($vs_export_filename, $vs_representation_Export) === false) { return false; } exec("{$vs_path_to_exif_tool} -tagsfromfile {$vs_export_filename} -all:all " . caEscapeShellArg($vs_tmp_filepath), $va_output, $vn_return); @unlink($vs_export_filename); @unlink("{$vs_tmp_filepath}_original"); } return $vs_tmp_filepath; }
/** * Extracts media metadata using ExifTool * * @param string $ps_filepath file path * @param string $ps_exiftool_path optional path to ExifTool binary. If omitted the path configured in external_applications.conf is used. * * @return array Extracted metadata */ function caExtractMetadataWithExifTool($ps_filepath, $ps_mediainfo_path = null) { if (caExifToolInstalled()) { if (!$vs_path_to_exif_tool) { $vs_path_to_exif_tool = caGetExternalApplicationPath('exiftool'); } exec("{$vs_path_to_exif_tool} -json -a -u -g1 " . caEscapeShellArg($ps_filepath) . " 2> /dev/null", $va_output, $vn_return); if (!is_array($va_data = array_pop(json_decode(join(" ", $va_output), true)))) { return false; } return $va_data; } return null; }
/** * Extract video duration using MediaInfo. This can be used as a fallback to getID3 * @param string $ps_filepath * * @return float|null */ function caExtractVideoFileDurationWithMediaInfo($ps_filepath) { $ps_mediainfo_path = caGetExternalApplicationPath('mediainfo'); if (!caMediaInfoInstalled($ps_mediainfo_path)) { return false; } $va_output = array(); exec($ps_mediainfo_path . ' --Inform="Video;%Duration/String3%" ' . caEscapeShellArg($ps_filepath), $va_output, $vn_return); if (!is_array($va_output) || sizeof($va_output) != 1) { return null; } $va_tmp = explode(':', array_shift($va_output)); if (sizeof($va_tmp) == 3) { // should have hours, minutes, seconds return round(intval($va_tmp[0]) * 3600 + intval($va_tmp[1]) * 60 + floatval($va_tmp[2])); } return null; }
/** * 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_MEDIAINFO; if (isset($_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO[$ps_pdfminer_path])) { return $_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO[$ps_pdfminer_path]; } else { $_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO = array(); } if (!trim($ps_pdfminer_path) || preg_match("/[^\\/A-Za-z0-9\\.:]+/", $ps_pdfminer_path) || !file_exists($ps_pdfminer_path)) { return false; } if (!file_exists($ps_pdfminer_path . "/pdf2txt.py")) { return $_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO[$ps_pdfminer_path] = false; } exec($ps_pdfminer_path . "/pdf2txt.py > /dev/null", $va_output, $vn_return); if ($vn_return == 100) { return $_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO[$ps_pdfminer_path] = true; } return $_MEDIAHELPER_PLUGIN_CACHE_MEDIAINFO[$ps_pdfminer_path] = false; }