@@ -85,8 +85,9 @@ discard block |
||
| 85 | 85 | // Upload resulting file |
| 86 | 86 | $this->uploadResultFiles($task, $output); |
| 87 | 87 | |
| 88 | - if ($this->client) |
|
| 89 | - $this->client->onTranscodeDone($this->token, $result); |
|
| 88 | + if ($this->client) { |
|
| 89 | + $this->client->onTranscodeDone($this->token, $result); |
|
| 90 | + } |
|
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | return json_encode($result); |
@@ -102,8 +103,9 @@ discard block |
||
| 102 | 103 | |
| 103 | 104 | # If we have metadata, we expect the output of ffprobe |
| 104 | 105 | $metadata = null; |
| 105 | - if (isset($this->input->{'input_metadata'})) |
|
| 106 | - $metadata = $this->input->{'input_metadata'}; |
|
| 106 | + if (isset($this->input->{'input_metadata'})) { |
|
| 107 | + $metadata = $this->input->{'input_metadata'}; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | // Perform transcoding |
| 109 | 111 | $result = $imageTranscoder->transcode_asset( |
@@ -140,8 +142,9 @@ discard block |
||
| 140 | 142 | |
| 141 | 143 | # If we have metadata, we expect the output of ffprobe |
| 142 | 144 | $metadata = null; |
| 143 | - if (isset($this->input->{'input_metadata'})) |
|
| 144 | - $metadata = $this->input->{'input_metadata'}; |
|
| 145 | + if (isset($this->input->{'input_metadata'})) { |
|
| 146 | + $metadata = $this->input->{'input_metadata'}; |
|
| 147 | + } |
|
| 145 | 148 | |
| 146 | 149 | // Perform transcoding |
| 147 | 150 | $result = $videoTranscoder->transcode_asset( |
@@ -224,16 +227,18 @@ discard block |
||
| 224 | 227 | |
| 225 | 228 | if (!file_exists($outputFilesPath)) |
| 226 | 229 | { |
| 227 | - if ($this->debug) |
|
| 228 | - $this->cpeLogger->logOut("INFO", basename(__FILE__), |
|
| 230 | + if ($this->debug) { |
|
| 231 | + $this->cpeLogger->logOut("INFO", basename(__FILE__), |
|
| 229 | 232 | "Creating TMP output folder '".$outputFilesPath."'", |
| 230 | 233 | $this->logKey); |
| 234 | + } |
|
| 231 | 235 | |
| 232 | - if (!mkdir($outputFilesPath, 0750, true)) |
|
| 233 | - throw new CpeSdk\CpeException( |
|
| 236 | + if (!mkdir($outputFilesPath, 0750, true)) { |
|
| 237 | + throw new CpeSdk\CpeException( |
|
| 234 | 238 | "Unable to create temporary folder '$outputFilesPath' !", |
| 235 | 239 | self::TMP_FOLDER_FAIL |
| 236 | 240 | ); |
| 241 | + } |
|
| 237 | 242 | } |
| 238 | 243 | |
| 239 | 244 | return ($outputFilesPath); |
@@ -302,15 +307,18 @@ discard block |
||
| 302 | 307 | global $name; |
| 303 | 308 | |
| 304 | 309 | // Handle input parameters |
| 305 | - if (!($options = getopt("N:A:l:C:hd"))) |
|
| 306 | - usage(); |
|
| 310 | + if (!($options = getopt("N:A:l:C:hd"))) { |
|
| 311 | + usage(); |
|
| 312 | + } |
|
| 307 | 313 | |
| 308 | - if (isset($options['h'])) |
|
| 309 | - usage(); |
|
| 314 | + if (isset($options['h'])) { |
|
| 315 | + usage(); |
|
| 316 | + } |
|
| 310 | 317 | |
| 311 | 318 | // Debug |
| 312 | - if (isset($options['d'])) |
|
| 313 | - $debug = true; |
|
| 319 | + if (isset($options['d'])) { |
|
| 320 | + $debug = true; |
|
| 321 | + } |
|
| 314 | 322 | |
| 315 | 323 | if (isset($options['A']) && $options['A']) { |
| 316 | 324 | $arn = $options['A']; |
@@ -329,9 +337,10 @@ discard block |
||
| 329 | 337 | $name = $options['N']; |
| 330 | 338 | } |
| 331 | 339 | |
| 332 | - if (isset($options['l'])) |
|
| 333 | - $logPath = $options['l']; |
|
| 334 | -} |
|
| 340 | + if (isset($options['l'])) { |
|
| 341 | + $logPath = $options['l']; |
|
| 342 | + } |
|
| 343 | + } |
|
| 335 | 344 | |
| 336 | 345 | |
| 337 | 346 | |
@@ -80,13 +80,14 @@ discard block |
||
| 80 | 80 | $this->logKey |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - if ($metadata) |
|
| 84 | - $this->cpeLogger->logOut( |
|
| 83 | + if ($metadata) { |
|
| 84 | + $this->cpeLogger->logOut( |
|
| 85 | 85 | "INFO", |
| 86 | 86 | basename(__FILE__), |
| 87 | 87 | "Input Video metadata: " . print_r($metadata, true), |
| 88 | 88 | $this->logKey |
| 89 | 89 | ); |
| 90 | + } |
|
| 90 | 91 | |
| 91 | 92 | try { |
| 92 | 93 | $ffmpegCmd = ""; |
@@ -165,8 +166,7 @@ discard block |
||
| 165 | 166 | |
| 166 | 167 | // FFProbe the output file and return its information |
| 167 | 168 | $outputInfo = $this->getAssetInfo($outputFilesPath."/".$outputWanted->{'output_file_info'}['basename']); |
| 168 | - } |
|
| 169 | - catch (\Exception $e) { |
|
| 169 | + } catch (\Exception $e) { |
|
| 170 | 170 | $this->cpeLogger->logOut( |
| 171 | 171 | "ERROR", |
| 172 | 172 | basename(__FILE__), |
@@ -319,8 +319,7 @@ discard block |
||
| 319 | 319 | $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
| 320 | 320 | $outputFilesPath .= "/" . $outputFileInfo['basename']; |
| 321 | 321 | $frameOptions = " -ss $time -vframes 1"; |
| 322 | - } |
|
| 323 | - else if ($outputWanted->{'mode'} == 'intervals') |
|
| 322 | + } else if ($outputWanted->{'mode'} == 'intervals') |
|
| 324 | 323 | { |
| 325 | 324 | $intervals = self::INTERVALS_DEFAULT; |
| 326 | 325 | if (isset($outputWanted->{'intervals'}) && |
@@ -373,8 +372,7 @@ discard block |
||
| 373 | 372 | array(1 => array("pipe", "w"), 2 => array("pipe", "w")), |
| 374 | 373 | false, false, |
| 375 | 374 | false, 1); |
| 376 | - } |
|
| 377 | - catch (\Exception $e) { |
|
| 375 | + } catch (\Exception $e) { |
|
| 378 | 376 | $this->cpeLogger->logOut( |
| 379 | 377 | "ERROR", |
| 380 | 378 | basename(__FILE__), |
@@ -626,8 +624,7 @@ discard block |
||
| 626 | 624 | foreach ($metadata->streams as $key => $value) { |
| 627 | 625 | if ($value->codec_type === 'video') { |
| 628 | 626 | $videoStreams = $value; |
| 629 | - } |
|
| 630 | - else if ($value->codec_type === 'audio') { |
|
| 627 | + } else if ($value->codec_type === 'audio') { |
|
| 631 | 628 | $audioStreams = $value; |
| 632 | 629 | } |
| 633 | 630 | } |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | public function isDirEmpty($dir) |
| 61 | 61 | { |
| 62 | - if (!is_readable($dir)) return null; |
|
| 62 | + if (!is_readable($dir)) { |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 63 | 65 | $handle = opendir($dir); |
| 64 | 66 | while (false !== ($entry = readdir($handle))) { |
| 65 | 67 | if ($entry !== '.' && $entry !== '..') { |
@@ -94,8 +96,7 @@ discard block |
||
| 94 | 96 | false, false, |
| 95 | 97 | false, 1 |
| 96 | 98 | ); |
| 97 | - } |
|
| 98 | - catch (\Exception $e) { |
|
| 99 | + } catch (\Exception $e) { |
|
| 99 | 100 | $this->cpeLogger->logOut( |
| 100 | 101 | "ERROR", |
| 101 | 102 | basename(__FILE__), |
@@ -54,13 +54,14 @@ discard block |
||
| 54 | 54 | $this->activityLogKey |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - if ($metadata) |
|
| 58 | - $this->cpeLogger->logOut( |
|
| 57 | + if ($metadata) { |
|
| 58 | + $this->cpeLogger->logOut( |
|
| 59 | 59 | "INFO", |
| 60 | 60 | basename(__FILE__), |
| 61 | 61 | "Input Video metadata: " . print_r($metadata, true), |
| 62 | 62 | $this->activityLogKey |
| 63 | 63 | ); |
| 64 | + } |
|
| 64 | 65 | |
| 65 | 66 | try { |
| 66 | 67 | $convertCmd = ""; |
@@ -81,8 +82,7 @@ discard block |
||
| 81 | 82 | $metadata, |
| 82 | 83 | $outputWanted |
| 83 | 84 | ); |
| 84 | - } |
|
| 85 | - else { |
|
| 85 | + } else { |
|
| 86 | 86 | $convertCmd = $this->craft_convert_cmd( |
| 87 | 87 | $tmpPathInput, |
| 88 | 88 | $pathToInputFile, |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | // XXX: Remove FFprobe for image convertion. Save time |
| 128 | 128 | $outputInfo = |
| 129 | 129 | $this->getAssetInfo($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
| 130 | - } |
|
| 131 | - catch (\Exception $e) { |
|
| 130 | + } catch (\Exception $e) { |
|
| 132 | 131 | $this->cpeLogger->logOut( |
| 133 | 132 | "ERROR", |
| 134 | 133 | basename(__FILE__), |
@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | public function __construct($client = null, $params, $debug, $cpeLogger) |
| 37 | 37 | { |
| 38 | 38 | # Check if preper env vars are setup |
| 39 | - if (!($region = getenv("AWS_DEFAULT_REGION"))) |
|
| 40 | - throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!"); |
|
| 39 | + if (!($region = getenv("AWS_DEFAULT_REGION"))) { |
|
| 40 | + throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!"); |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | 43 | parent::__construct($client, $params, $debug, $cpeLogger); |
| 43 | 44 | |
@@ -86,8 +87,7 @@ discard block |
||
| 86 | 87 | curl_exec($ch); |
| 87 | 88 | curl_close($ch); |
| 88 | 89 | $chunk = $this->curl_data; |
| 89 | - } |
|
| 90 | - else if (isset($this->input->{'input_asset'}->{'bucket'}) && |
|
| 90 | + } else if (isset($this->input->{'input_asset'}->{'bucket'}) && |
|
| 91 | 91 | isset($this->input->{'input_asset'}->{'file'})) { |
| 92 | 92 | // Fetch first 1 KiB of the file for Magic number validation |
| 93 | 93 | $obj = $this->s3->getObject([ |
@@ -106,13 +106,14 @@ discard block |
||
| 106 | 106 | 'file -b --mime-type '.escapeshellarg($tmpFile))['out']); |
| 107 | 107 | $type = substr($mime, 0, strpos($mime, '/')); |
| 108 | 108 | |
| 109 | - if ($this->debug) |
|
| 110 | - $this->cpeLogger->logOut( |
|
| 109 | + if ($this->debug) { |
|
| 110 | + $this->cpeLogger->logOut( |
|
| 111 | 111 | "DEBUG", |
| 112 | 112 | basename(__FILE__), |
| 113 | 113 | "File meta information gathered. Mime: $mime | Type: $type", |
| 114 | 114 | $this->logKey |
| 115 | 115 | ); |
| 116 | + } |
|
| 116 | 117 | |
| 117 | 118 | // Load the right transcoder base on input_type |
| 118 | 119 | // Get asset detailed info |
@@ -190,15 +191,18 @@ discard block |
||
| 190 | 191 | global $name; |
| 191 | 192 | |
| 192 | 193 | // Handle input parameters |
| 193 | - if (!($options = getopt("N:A:l:C:hd"))) |
|
| 194 | - usage(); |
|
| 194 | + if (!($options = getopt("N:A:l:C:hd"))) { |
|
| 195 | + usage(); |
|
| 196 | + } |
|
| 195 | 197 | |
| 196 | - if (isset($options['h'])) |
|
| 197 | - usage(); |
|
| 198 | + if (isset($options['h'])) { |
|
| 199 | + usage(); |
|
| 200 | + } |
|
| 198 | 201 | |
| 199 | 202 | // Debug |
| 200 | - if (isset($options['d'])) |
|
| 201 | - $debug = true; |
|
| 203 | + if (isset($options['d'])) { |
|
| 204 | + $debug = true; |
|
| 205 | + } |
|
| 202 | 206 | |
| 203 | 207 | if (isset($options['A']) && $options['A']) { |
| 204 | 208 | $arn = $options['A']; |
@@ -217,9 +221,10 @@ discard block |
||
| 217 | 221 | $name = $options['N']; |
| 218 | 222 | } |
| 219 | 223 | |
| 220 | - if (isset($options['l'])) |
|
| 221 | - $logPath = $options['l']; |
|
| 222 | -} |
|
| 224 | + if (isset($options['l'])) { |
|
| 225 | + $logPath = $options['l']; |
|
| 226 | + } |
|
| 227 | + } |
|
| 223 | 228 | |
| 224 | 229 | |
| 225 | 230 | /* |
@@ -76,16 +76,18 @@ discard block |
||
| 76 | 76 | // Create the tmp folder if doesn't exist |
| 77 | 77 | if (!file_exists($this->tmpInputPath)) |
| 78 | 78 | { |
| 79 | - if ($this->debug) |
|
| 80 | - $this->cpeLogger->logOut("DEBUG", basename(__FILE__), |
|
| 79 | + if ($this->debug) { |
|
| 80 | + $this->cpeLogger->logOut("DEBUG", basename(__FILE__), |
|
| 81 | 81 | "Creating TMP input folder '".$this->tmpInputPath."'", |
| 82 | 82 | $this->logKey); |
| 83 | + } |
|
| 83 | 84 | |
| 84 | - if (!mkdir($this->tmpInputPath, 0750, true)) |
|
| 85 | - throw new CpeSdk\CpeException( |
|
| 85 | + if (!mkdir($this->tmpInputPath, 0750, true)) { |
|
| 86 | + throw new CpeSdk\CpeException( |
|
| 86 | 87 | "Unable to create temporary folder '$this->tmpInputPath' !", |
| 87 | 88 | self::TMP_FOLDER_FAIL |
| 88 | 89 | ); |
| 90 | + } |
|
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | $this->inputFilePath = null; |
@@ -93,8 +95,7 @@ discard block |
||
| 93 | 95 | { |
| 94 | 96 | // Pad HTTP input so it is cached in case of full encodes |
| 95 | 97 | $this->inputFilePath = 'cache:' . $this->input->{'input_asset'}->{'http'}; |
| 96 | - } |
|
| 97 | - else if (isset($this->input->{'input_asset'}->{'bucket'}) && |
|
| 98 | + } else if (isset($this->input->{'input_asset'}->{'bucket'}) && |
|
| 98 | 99 | isset($this->input->{'input_asset'}->{'file'})) |
| 99 | 100 | { |
| 100 | 101 | // Download input file and store it in TMP folder |
@@ -21,8 +21,9 @@ discard block |
||
| 21 | 21 | function check_input_parameters(&$options) |
| 22 | 22 | { |
| 23 | 23 | if (!count($options) || isset($options['h']) || |
| 24 | - isset($options['help'])) |
|
| 25 | - usage(); |
|
| 24 | + isset($options['help'])) { |
|
| 25 | + usage(); |
|
| 26 | + } |
|
| 26 | 27 | |
| 27 | 28 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 28 | 29 | !isset($options['from'])) |
@@ -46,8 +47,9 @@ discard block |
||
| 46 | 47 | |
| 47 | 48 | try { |
| 48 | 49 | # Check if preper env vars are setup |
| 49 | - if (!($region = getenv("AWS_DEFAULT_REGION"))) |
|
| 50 | - throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!"); |
|
| 50 | + if (!($region = getenv("AWS_DEFAULT_REGION"))) { |
|
| 51 | + throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!"); |
|
| 52 | + } |
|
| 51 | 53 | |
| 52 | 54 | // Get S3 client |
| 53 | 55 | $s3 = new \Aws\S3\S3Client([ |
@@ -62,10 +64,12 @@ discard block |
||
| 62 | 64 | ); |
| 63 | 65 | |
| 64 | 66 | // StorageClass and Encryption ? |
| 65 | - if (isset($options['rrs'])) |
|
| 66 | - $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 67 | - if (isset($options['encrypt'])) |
|
| 68 | - $params['ServerSideEncryption'] = 'AES256'; |
|
| 67 | + if (isset($options['rrs'])) { |
|
| 68 | + $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 69 | + } |
|
| 70 | + if (isset($options['encrypt'])) { |
|
| 71 | + $params['ServerSideEncryption'] = 'AES256'; |
|
| 72 | + } |
|
| 69 | 73 | |
| 70 | 74 | // Upload and Save file to S3 |
| 71 | 75 | $s3->putObject($params); |
@@ -73,8 +77,7 @@ discard block |
||
| 73 | 77 | // Print JSON error output |
| 74 | 78 | print json_encode([ "status" => "SUCCESS", |
| 75 | 79 | "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
| 76 | -} |
|
| 77 | -catch (Exception $e) { |
|
| 80 | +} catch (Exception $e) { |
|
| 78 | 81 | $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
| 79 | 82 | |
| 80 | 83 | // Print JSON error output |
@@ -20,13 +20,15 @@ discard block |
||
| 20 | 20 | function check_input_parameters($options) |
| 21 | 21 | { |
| 22 | 22 | if (!count($options) || isset($options['h']) || |
| 23 | - isset($options['help'])) |
|
| 24 | - usage(); |
|
| 23 | + isset($options['help'])) { |
|
| 24 | + usage(); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 27 | - !isset($options['to'])) |
|
| 28 | - throw new \SA\CpeSdk\CpeException("Missing mandatory parameter!"); |
|
| 29 | -} |
|
| 28 | + !isset($options['to'])) { |
|
| 29 | + throw new \SA\CpeSdk\CpeException("Missing mandatory parameter!"); |
|
| 30 | + } |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | $options = getopt("h", array("bucket:", "file:", "to:", "force::", "help::")); |
| 32 | 34 | check_input_parameters($options); |
@@ -43,8 +45,9 @@ discard block |
||
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | # Check if preper env vars are setup |
| 46 | -if (!($region = getenv("AWS_DEFAULT_REGION"))) |
|
| 48 | +if (!($region = getenv("AWS_DEFAULT_REGION"))) { |
|
| 47 | 49 | throw new \SA\CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!"); |
| 50 | +} |
|
| 48 | 51 | |
| 49 | 52 | // Get S3 client |
| 50 | 53 | $s3 = new \Aws\S3\S3Client([ |
@@ -35,8 +35,9 @@ discard block |
||
| 35 | 35 | $callbackTurns = 0, |
| 36 | 36 | $logKey = null) |
| 37 | 37 | { |
| 38 | - if ($logKey) |
|
| 39 | - $this->logKey = $logKey; |
|
| 38 | + if ($logKey) { |
|
| 39 | + $this->logKey = $logKey; |
|
| 40 | + } |
|
| 40 | 41 | |
| 41 | 42 | $this->cpeLogger->logOut("INFO", basename(__FILE__), "Executing: $cmd", $this->logKey); |
| 42 | 43 | |
@@ -111,10 +112,12 @@ discard block |
||
| 111 | 112 | $i++; |
| 112 | 113 | } while ($procStatus['running']); |
| 113 | 114 | |
| 114 | - if (isset($pipes[1])) |
|
| 115 | - fclose($pipes[1]); |
|
| 116 | - if (isset($pipes[2])) |
|
| 117 | - fclose($pipes[2]); |
|
| 115 | + if (isset($pipes[1])) { |
|
| 116 | + fclose($pipes[1]); |
|
| 117 | + } |
|
| 118 | + if (isset($pipes[2])) { |
|
| 119 | + fclose($pipes[2]); |
|
| 120 | + } |
|
| 118 | 121 | |
| 119 | 122 | if ($procStatus['exitcode'] > 0) |
| 120 | 123 | { |
@@ -122,14 +125,16 @@ discard block |
||
| 122 | 125 | basename(__FILE__), |
| 123 | 126 | "Can't execute: $cmd. Exit Code: ".$procStatus['exitcode'], |
| 124 | 127 | $this->logKey); |
| 125 | - if ($allOut) |
|
| 126 | - $this->cpeLogger->logOut("ERROR", |
|
| 128 | + if ($allOut) { |
|
| 129 | + $this->cpeLogger->logOut("ERROR", |
|
| 127 | 130 | basename(__FILE__), "COMMAND STDOUT: ".$allOut, |
| 128 | 131 | $this->logKey); |
| 129 | - if ($allOutErr) |
|
| 130 | - $this->cpeLogger->logOut("ERROR", |
|
| 132 | + } |
|
| 133 | + if ($allOutErr) { |
|
| 134 | + $this->cpeLogger->logOut("ERROR", |
|
| 131 | 135 | basename(__FILE__), "COMMAND STDERR: ".$allOutErr, |
| 132 | 136 | $this->logKey); |
| 137 | + } |
|
| 133 | 138 | } |
| 134 | 139 | |
| 135 | 140 | if ($showProgress) { |