From 93a6cc17a57987909defb5687d8aa955517709a2 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Fri, 21 Nov 2014 17:12:11 +0100 Subject: The class name is Movie NOT Movies --- config/config.sample.php | 2 +- lib/private/preview.php | 4 +- lib/private/preview/movie.php | 106 +++++++++++++++++++++++++++++++++++++++++ lib/private/preview/movies.php | 106 ----------------------------------------- 4 files changed, 109 insertions(+), 109 deletions(-) create mode 100644 lib/private/preview/movie.php delete mode 100644 lib/private/preview/movies.php diff --git a/config/config.sample.php b/config/config.sample.php index 2287b7af7dd..bf26172c494 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -617,7 +617,7 @@ $CONFIG = array( * concerns: * * - OC\Preview\Illustrator - * - OC\Preview\Movies + * - OC\Preview\Movie * - OC\Preview\MSOffice2003 * - OC\Preview\MSOffice2007 * - OC\Preview\MSOfficeDoc diff --git a/lib/private/preview.php b/lib/private/preview.php index 778007b21fd..c9d8810be6f 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -17,7 +17,7 @@ use OC\Preview\Provider; use OCP\Files\NotFoundException; require_once 'preview/image.php'; -require_once 'preview/movies.php'; +require_once 'preview/movie.php'; require_once 'preview/mp3.php'; require_once 'preview/svg.php'; require_once 'preview/txt.php'; @@ -713,7 +713,7 @@ class Preview { * - OC\Preview\OpenDocument * - OC\Preview\StarOffice * - OC\Preview\SVG - * - OC\Preview\Movies + * - OC\Preview\Movie * - OC\Preview\PDF * - OC\Preview\TIFF * - OC\Preview\Illustrator diff --git a/lib/private/preview/movie.php b/lib/private/preview/movie.php new file mode 100644 index 00000000000..d69266ceb33 --- /dev/null +++ b/lib/private/preview/movie.php @@ -0,0 +1,106 @@ +getFileInfo($path); + $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted()); + + if ($useFileDirectly) { + $absPath = $fileview->getLocalFile($path); + } else { + $absPath = \OC_Helper::tmpFile(); + + $handle = $fileview->fopen($path, 'rb'); + + // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB. + // in some cases 1MB was no enough to generate thumbnail + $firstmb = stream_get_contents($handle, 5242880); + file_put_contents($absPath, $firstmb); + } + + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); + if ($result === false) { + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); + if ($result === false) { + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); + } + } + + if (!$useFileDirectly) { + unlink($absPath); + } + + return $result; + } + + /** + * @param int $maxX + * @param int $maxY + * @param string $absPath + * @param string $tmpPath + * @param int $second + * @return bool|\OC_Image + */ + private function generateThumbNail($maxX, $maxY, $absPath, $second) + { + $tmpPath = \OC_Helper::tmpFile(); + + if (self::$avconvBinary) { + $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . + ' -i ' . escapeshellarg($absPath) . + ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . + ' > /dev/null 2>&1'; + } else { + $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . + ' -i ' . escapeshellarg($absPath) . + ' -f mjpeg -vframes 1' . + ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . + ' ' . escapeshellarg($tmpPath) . + ' > /dev/null 2>&1'; + } + + exec($cmd, $output, $returnCode); + + if ($returnCode === 0) { + $image = new \OC_Image(); + $image->loadFromFile($tmpPath); + unlink($tmpPath); + return $image->valid() ? $image : false; + } + unlink($tmpPath); + return false; + } + } + + // a bit hacky but didn't want to use subclasses + Movie::$avconvBinary = $avconvBinary; + Movie::$ffmpegBinary = $ffmpegBinary; + + \OC\Preview::registerProvider('OC\Preview\Movie'); + } +} + diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php deleted file mode 100644 index d69266ceb33..00000000000 --- a/lib/private/preview/movies.php +++ /dev/null @@ -1,106 +0,0 @@ -getFileInfo($path); - $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted()); - - if ($useFileDirectly) { - $absPath = $fileview->getLocalFile($path); - } else { - $absPath = \OC_Helper::tmpFile(); - - $handle = $fileview->fopen($path, 'rb'); - - // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB. - // in some cases 1MB was no enough to generate thumbnail - $firstmb = stream_get_contents($handle, 5242880); - file_put_contents($absPath, $firstmb); - } - - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); - if ($result === false) { - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); - if ($result === false) { - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); - } - } - - if (!$useFileDirectly) { - unlink($absPath); - } - - return $result; - } - - /** - * @param int $maxX - * @param int $maxY - * @param string $absPath - * @param string $tmpPath - * @param int $second - * @return bool|\OC_Image - */ - private function generateThumbNail($maxX, $maxY, $absPath, $second) - { - $tmpPath = \OC_Helper::tmpFile(); - - if (self::$avconvBinary) { - $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . - ' -i ' . escapeshellarg($absPath) . - ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . - ' > /dev/null 2>&1'; - } else { - $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . - ' -i ' . escapeshellarg($absPath) . - ' -f mjpeg -vframes 1' . - ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . - ' ' . escapeshellarg($tmpPath) . - ' > /dev/null 2>&1'; - } - - exec($cmd, $output, $returnCode); - - if ($returnCode === 0) { - $image = new \OC_Image(); - $image->loadFromFile($tmpPath); - unlink($tmpPath); - return $image->valid() ? $image : false; - } - unlink($tmpPath); - return false; - } - } - - // a bit hacky but didn't want to use subclasses - Movie::$avconvBinary = $avconvBinary; - Movie::$ffmpegBinary = $ffmpegBinary; - - \OC\Preview::registerProvider('OC\Preview\Movie'); - } -} - -- cgit v1.2.3