From 08e18b40b58e381b9ffdbfc188adbfaf5244bcae Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Fri, 9 May 2014 21:56:12 +0200 Subject: [PATCH] Add passthru delegate and avconv support. --- src/_h5ai/index.html.jade | 4 +++- src/_h5ai/server/php/inc/App.php | 3 +++ src/_h5ai/server/php/inc/Archive.php | 2 +- src/_h5ai/server/php/inc/Thumb.php | 4 ++++ src/_h5ai/server/php/inc/util.php | 8 +++++++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/_h5ai/index.html.jade b/src/_h5ai/index.html.jade index e09cbed6..9e7f2409 100644 --- a/src/_h5ai/index.html.jade +++ b/src/_h5ai/index.html.jade @@ -48,12 +48,14 @@ html.no-js.browser( lang="en" ) span.label Use EXIF thumbs span.result ? div.info PHP EXIF extension available - li.test( data-id="ffmpeg" ) + li.test( data-id="moviethumbs" ) span.label Movie thumbs span.result ? div.info | Command line program code ffmpeg + | or + code avconv | available li.test( data-id="convert" ) span.label PDF thumbs diff --git a/src/_h5ai/server/php/inc/App.php b/src/_h5ai/server/php/inc/App.php index 79faeafe..040feda0 100644 --- a/src/_h5ai/server/php/inc/App.php +++ b/src/_h5ai/server/php/inc/App.php @@ -310,6 +310,7 @@ class App { $zip = @preg_match("/zip(.exe)?$/i", exec_cmd($cmd . " zip")) > 0; $convert = @preg_match("/convert(.exe)?$/i", exec_cmd($cmd . " convert")) > 0; $ffmpeg = @preg_match("/ffmpeg(.exe)?$/i", exec_cmd($cmd . " ffmpeg")) > 0; + $avconv = @preg_match("/avconv(.exe)?$/i", exec_cmd($cmd . " avconv")) > 0; $du = @preg_match("/du(.exe)?$/i", exec_cmd($cmd . " du")) > 0; return array( @@ -323,6 +324,8 @@ class App { "zip" => $zip, "convert" => $convert, "ffmpeg" => $ffmpeg, + "avconv" => $avconv, + "moviethumbs" => $ffmpeg || $avconv, "du" => $du ); } diff --git a/src/_h5ai/server/php/inc/Archive.php b/src/_h5ai/server/php/inc/Archive.php index 92fd30f0..34d8f9fc 100644 --- a/src/_h5ai/server/php/inc/Archive.php +++ b/src/_h5ai/server/php/inc/Archive.php @@ -48,7 +48,7 @@ class Archive { $cmd = str_replace("[DIRS]", count($this->dirs) ? implode(" ", array_map("escapeshellarg", $this->dirs)) : "", $cmd); $cmd = str_replace("[FILES]", count($this->files) ? implode(" ", array_map("escapeshellarg", $this->files)) : "", $cmd); try { - passthru($cmd); + passthru_cmd($cmd); } catch (Exeption $err) { return 500; } diff --git a/src/_h5ai/server/php/inc/Thumb.php b/src/_h5ai/server/php/inc/Thumb.php index 24efe39e..00dad454 100644 --- a/src/_h5ai/server/php/inc/Thumb.php +++ b/src/_h5ai/server/php/inc/Thumb.php @@ -3,6 +3,7 @@ class Thumb { private static $FFMPEG_CMD = "ffmpeg -ss 0:01:00 -i [SOURCE] -an -vframes 1 [TARGET]"; + private static $AVCONV_CMD = "avconv -ss 0:01:00 -i [SOURCE] -an -vframes 1 [TARGET]"; private static $CONVERT_CMD = "convert -strip [SOURCE][0] [TARGET]"; private static $THUMB_CACHE = "thumbs"; @@ -36,6 +37,9 @@ class Thumb { $capture_abs_path = $source_abs_path; } else if ($type === "mov") { $capture_abs_path = $this->capture(Thumb::$FFMPEG_CMD, $source_abs_path); + if ($capture_abs_path === null) { + $capture_abs_path = $this->capture(Thumb::$AVCONV_CMD, $source_abs_path); + } } else if ($type === "doc") { $capture_abs_path = $this->capture(Thumb::$CONVERT_CMD, $source_abs_path); } diff --git a/src/_h5ai/server/php/inc/util.php b/src/_h5ai/server/php/inc/util.php index 19c1ca64..e684bf5c 100644 --- a/src/_h5ai/server/php/inc/util.php +++ b/src/_h5ai/server/php/inc/util.php @@ -77,8 +77,14 @@ function exec_cmd($cmd) { $lines = array(); $rc = null; exec($cmd, $lines, $rc); + return implode("\n", $lines); +} - return implode('\n', $lines); +function passthru_cmd($cmd) { + + $rc = null; + passthru($cmd, $rc); + return $rc; } ?> \ No newline at end of file