@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | function check_input_parameters($options) |
23 | 23 | { |
24 | 24 | if (!count($options) || isset($options['h']) || |
25 | - isset($options['help'])) |
|
26 | - usage(); |
|
25 | + isset($options['help'])) { |
|
26 | + usage(); |
|
27 | + } |
|
27 | 28 | |
28 | 29 | if (!isset($options['bucket']) || !isset($options['file']) || |
29 | 30 | !isset($options['to'])) |
@@ -60,8 +61,7 @@ discard block |
||
60 | 61 | // Print JSON error output |
61 | 62 | print json_encode([ "status" => "SUCCESS", |
62 | 63 | "msg" => "[".__FILE__."] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
63 | -} |
|
64 | -catch (Exception $e) { |
|
64 | +} catch (Exception $e) { |
|
65 | 65 | $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage(); |
66 | 66 | // Print JSON error output |
67 | 67 | print json_encode([ "status" => "ERROR", |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | function check_input_parameters(&$options) |
24 | 24 | { |
25 | 25 | if (!count($options) || isset($options['h']) || |
26 | - isset($options['help'])) |
|
27 | - usage(); |
|
26 | + isset($options['help'])) { |
|
27 | + usage(); |
|
28 | + } |
|
28 | 29 | |
29 | 30 | if (!isset($options['bucket']) || !isset($options['file']) || |
30 | 31 | !isset($options['from'])) |
@@ -57,10 +58,12 @@ discard block |
||
57 | 58 | ); |
58 | 59 | |
59 | 60 | // StorageClass and Encryption ? |
60 | - if (isset($options['rrs'])) |
|
61 | - $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
62 | - if (isset($options['encrypt'])) |
|
63 | - $params['ServerSideEncryption'] = 'AES256'; |
|
61 | + if (isset($options['rrs'])) { |
|
62 | + $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
63 | + } |
|
64 | + if (isset($options['encrypt'])) { |
|
65 | + $params['ServerSideEncryption'] = 'AES256'; |
|
66 | + } |
|
64 | 67 | |
65 | 68 | // Upload and Save file to S3 |
66 | 69 | $s3->putObject($params); |
@@ -68,8 +71,7 @@ discard block |
||
68 | 71 | // Print JSON error output |
69 | 72 | print json_encode([ "status" => "SUCCESS", |
70 | 73 | "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
71 | -} |
|
72 | -catch (Exception $e) { |
|
74 | +} catch (Exception $e) { |
|
73 | 75 | $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
74 | 76 | |
75 | 77 | // Print JSON error output |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct($cpeLogger = null) |
19 | 19 | { |
20 | - if (!$cpeLogger) |
|
21 | - $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
20 | + if (!$cpeLogger) { |
|
21 | + $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
22 | + } |
|
22 | 23 | $this->cpeLogger = $cpeLogger; |
23 | 24 | } |
24 | 25 | |
@@ -112,10 +113,12 @@ discard block |
||
112 | 113 | if ($procStatus['exitcode'] > 0) |
113 | 114 | { |
114 | 115 | $this->cpeLogger->log_out("ERROR", basename(__FILE__), "Can't execute: $cmd. Exit Code: ".$procStatus['exitcode']); |
115 | - if ($allOut) |
|
116 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
117 | - if ($allOutErr) |
|
118 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
116 | + if ($allOut) { |
|
117 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
118 | + } |
|
119 | + if ($allOutErr) { |
|
120 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
121 | + } |
|
119 | 122 | } |
120 | 123 | |
121 | 124 | if ($showProgress) { |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct($cpeLogger = null) |
24 | 24 | { |
25 | - if (!$cpeLogger) |
|
26 | - $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils'); |
|
25 | + if (!$cpeLogger) { |
|
26 | + $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils'); |
|
27 | + } |
|
27 | 28 | $this->cpeLogger = $cpeLogger; |
28 | 29 | } |
29 | 30 | |
@@ -61,10 +62,12 @@ discard block |
||
61 | 62 | $cmd .= " --bucket $bucket"; |
62 | 63 | $cmd .= " --file $filename"; |
63 | 64 | $cmd .= " --from $pathToFileToSend"; |
64 | - if ($options['rrs']) |
|
65 | - $cmd .= " --rrs"; |
|
66 | - if ($options['encrypt']) |
|
67 | - $cmd .= " --encrypt"; |
|
65 | + if ($options['rrs']) { |
|
66 | + $cmd .= " --rrs"; |
|
67 | + } |
|
68 | + if ($options['encrypt']) { |
|
69 | + $cmd .= " --encrypt"; |
|
70 | + } |
|
68 | 71 | |
69 | 72 | // HAndle execution |
70 | 73 | return ($this->handle_s3_ops( |
@@ -91,21 +94,25 @@ discard block |
||
91 | 94 | true, |
92 | 95 | 5); |
93 | 96 | |
94 | - if ($out['outErr']) |
|
95 | - throw new CpeSdk\CpeException($out['outErr'], |
|
97 | + if ($out['outErr']) { |
|
98 | + throw new CpeSdk\CpeException($out['outErr'], |
|
96 | 99 | self::S3_OPS_FAILED); |
100 | + } |
|
97 | 101 | |
98 | - if (!$out['out']) |
|
99 | - throw new CpeSdk\CpeException("Script '$caller' didn't return any data !", |
|
102 | + if (!$out['out']) { |
|
103 | + throw new CpeSdk\CpeException("Script '$caller' didn't return any data !", |
|
100 | 104 | self::NO_OUTPUT_DATA); |
105 | + } |
|
101 | 106 | |
102 | - if (!($decoded = json_decode($out['out'], true))) |
|
103 | - throw new CpeSdk\CpeException($out['out'], |
|
107 | + if (!($decoded = json_decode($out['out'], true))) { |
|
108 | + throw new CpeSdk\CpeException($out['out'], |
|
104 | 109 | self::S3_OPS_FAILED); |
110 | + } |
|
105 | 111 | |
106 | - if ($decoded["status"] == "ERROR") |
|
107 | - throw new CpeSdk\CpeException($decoded["msg"], |
|
112 | + if ($decoded["status"] == "ERROR") { |
|
113 | + throw new CpeSdk\CpeException($decoded["msg"], |
|
108 | 114 | self::S3_OPS_FAILED); |
115 | + } |
|
109 | 116 | |
110 | 117 | return ($decoded); |
111 | 118 | } |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | |
68 | 68 | # If we have metadata, we expect the output of ffprobe |
69 | 69 | $metadata = null; |
70 | - if (isset($this->input->{'input_asset_metadata'})) |
|
71 | - $metadata = $this->input->{'input_asset_metadata'}; |
|
70 | + if (isset($this->input->{'input_asset_metadata'})) { |
|
71 | + $metadata = $this->input->{'input_asset_metadata'}; |
|
72 | + } |
|
72 | 73 | |
73 | 74 | // Perform transcoding |
74 | 75 | $result = $videoTranscoder->transcode_asset( |
@@ -90,8 +91,9 @@ discard block |
||
90 | 91 | |
91 | 92 | # If we have metadata, we expect the output of ffprobe |
92 | 93 | $metadata = null; |
93 | - if (isset($this->input->{'input_asset_metadata'})) |
|
94 | - $metadata = $this->input->{'input_asset_metadata'}; |
|
94 | + if (isset($this->input->{'input_asset_metadata'})) { |
|
95 | + $metadata = $this->input->{'input_asset_metadata'}; |
|
96 | + } |
|
95 | 97 | |
96 | 98 | // Perform transcoding |
97 | 99 | $result = $imageTranscoder->transcode_asset( |
@@ -194,16 +196,18 @@ discard block |
||
194 | 196 | |
195 | 197 | if (!file_exists($this->pathToOutputFiles)) |
196 | 198 | { |
197 | - if ($this->debug) |
|
198 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
199 | + if ($this->debug) { |
|
200 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
199 | 201 | "Creating TMP output folder '".$this->pathToOutputFiles."'", |
200 | 202 | $this->activityLogKey); |
203 | + } |
|
201 | 204 | |
202 | - if (!mkdir($this->pathToOutputFiles, 0750, true)) |
|
203 | - throw new CpeSdk\CpeException( |
|
205 | + if (!mkdir($this->pathToOutputFiles, 0750, true)) { |
|
206 | + throw new CpeSdk\CpeException( |
|
204 | 207 | "Unable to create temporary folder '$this->pathToOutputFiles' !", |
205 | 208 | self::TMP_FOLDER_FAIL |
206 | 209 | ); |
210 | + } |
|
207 | 211 | } |
208 | 212 | } |
209 | 213 |
@@ -65,13 +65,14 @@ discard block |
||
65 | 65 | $this->activityLogKey |
66 | 66 | ); |
67 | 67 | |
68 | - if ($metadata) |
|
69 | - $this->cpeLogger->log_out( |
|
68 | + if ($metadata) { |
|
69 | + $this->cpeLogger->log_out( |
|
70 | 70 | "INFO", |
71 | 71 | basename(__FILE__), |
72 | 72 | "Input Video metadata: " . print_r($metadata, true), |
73 | 73 | $this->activityLogKey |
74 | 74 | ); |
75 | + } |
|
75 | 76 | |
76 | 77 | try { |
77 | 78 | $ffmpegCmd = ""; |
@@ -138,8 +139,7 @@ discard block |
||
138 | 139 | // FFProbe the output file and return its information |
139 | 140 | $output_info = |
140 | 141 | $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
141 | - } |
|
142 | - catch (\Exception $e) { |
|
142 | + } catch (\Exception $e) { |
|
143 | 143 | $this->cpeLogger->log_out( |
144 | 144 | "ERROR", |
145 | 145 | basename(__FILE__), |
@@ -289,8 +289,7 @@ discard block |
||
289 | 289 | $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
290 | 290 | $pathToOutputFiles .= "/" . $outputFileInfo['basename']; |
291 | 291 | $frameOptions = " -ss $time -vframes 1"; |
292 | - } |
|
293 | - else if ($outputWanted->{'mode'} == 'intervals') |
|
292 | + } else if ($outputWanted->{'mode'} == 'intervals') |
|
294 | 293 | { |
295 | 294 | $intervals = self::INTERVALS_DEFAULT; |
296 | 295 | if (isset($outputWanted->{'intervals'}) && |
@@ -343,8 +342,7 @@ discard block |
||
343 | 342 | array(1 => array("pipe", "w"), 2 => array("pipe", "w")), |
344 | 343 | false, false, |
345 | 344 | false, 1); |
346 | - } |
|
347 | - catch (\Exception $e) { |
|
345 | + } catch (\Exception $e) { |
|
348 | 346 | $this->cpeLogger->log_out( |
349 | 347 | "ERROR", |
350 | 348 | basename(__FILE__), |
@@ -604,8 +602,7 @@ discard block |
||
604 | 602 | foreach ($metadata->streams as $key => $value) { |
605 | 603 | if ($value->codec_type === 'video') { |
606 | 604 | $videoStreams = $value; |
607 | - } |
|
608 | - else if ($value->codec_type === 'audio') { |
|
605 | + } else if ($value->codec_type === 'audio') { |
|
609 | 606 | $audioStreams = $value; |
610 | 607 | } |
611 | 608 | } |
@@ -48,7 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | public function is_dir_empty($dir) |
50 | 50 | { |
51 | - if (!is_readable($dir)) return null; |
|
51 | + if (!is_readable($dir)) { |
|
52 | + return null; |
|
53 | + } |
|
52 | 54 | $handle = opendir($dir); |
53 | 55 | while (false !== ($entry = readdir($handle))) { |
54 | 56 | if ($entry !== '.' && $entry !== '..') { |
@@ -83,8 +85,7 @@ discard block |
||
83 | 85 | false, false, |
84 | 86 | false, 1 |
85 | 87 | ); |
86 | - } |
|
87 | - catch (\Exception $e) { |
|
88 | + } catch (\Exception $e) { |
|
88 | 89 | $this->cpeLogger->log_out( |
89 | 90 | "ERROR", |
90 | 91 | basename(__FILE__), |
@@ -40,13 +40,14 @@ discard block |
||
40 | 40 | $this->activityLogKey |
41 | 41 | ); |
42 | 42 | |
43 | - if ($metadata) |
|
44 | - $this->cpeLogger->log_out( |
|
43 | + if ($metadata) { |
|
44 | + $this->cpeLogger->log_out( |
|
45 | 45 | "INFO", |
46 | 46 | basename(__FILE__), |
47 | 47 | "Input Video metadata: " . print_r($metadata, true), |
48 | 48 | $this->activityLogKey |
49 | 49 | ); |
50 | + } |
|
50 | 51 | |
51 | 52 | try { |
52 | 53 | $convertCmd = ""; |
@@ -67,8 +68,7 @@ discard block |
||
67 | 68 | $metadata, |
68 | 69 | $outputWanted |
69 | 70 | ); |
70 | - } |
|
71 | - else { |
|
71 | + } else { |
|
72 | 72 | $convertCmd = $this->craft_convert_cmd( |
73 | 73 | $tmpPathInput, |
74 | 74 | $pathToInputFile, |
@@ -112,8 +112,7 @@ discard block |
||
112 | 112 | // FFProbe the output file and return its information |
113 | 113 | $output_info = |
114 | 114 | $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
115 | - } |
|
116 | - catch (\Exception $e) { |
|
115 | + } catch (\Exception $e) { |
|
117 | 116 | $this->cpeLogger->log_out( |
118 | 117 | "ERROR", |
119 | 118 | basename(__FILE__), |
@@ -74,22 +74,25 @@ discard block |
||
74 | 74 | |
75 | 75 | $inputFileInfo = null; |
76 | 76 | // Create TMP storage to store input file to transcode |
77 | - if (isset($this->input->{'input_asset'}->{'file'})) |
|
78 | - $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
77 | + if (isset($this->input->{'input_asset'}->{'file'})) { |
|
78 | + $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | // Create the tmp folder if doesn't exist |
81 | 82 | if (!file_exists($this->tmpPathInput)) |
82 | 83 | { |
83 | - if ($this->debug) |
|
84 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
84 | + if ($this->debug) { |
|
85 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
85 | 86 | "Creating TMP input folder '".$this->tmpPathInput."'", |
86 | 87 | $this->activityLogKey); |
88 | + } |
|
87 | 89 | |
88 | - if (!mkdir($this->tmpPathInput, 0750, true)) |
|
89 | - throw new CpeSdk\CpeException( |
|
90 | + if (!mkdir($this->tmpPathInput, 0750, true)) { |
|
91 | + throw new CpeSdk\CpeException( |
|
90 | 92 | "Unable to create temporary folder '$this->tmpPathInput' !", |
91 | 93 | self::TMP_FOLDER_FAIL |
92 | 94 | ); |
95 | + } |
|
93 | 96 | } |
94 | 97 | |
95 | 98 | $this->pathToInputFile = null; |
@@ -105,8 +108,7 @@ discard block |
||
105 | 108 | $this->input->{'input_asset'}->{'file'}, |
106 | 109 | $saveFileTo |
107 | 110 | ); |
108 | - } |
|
109 | - else if (isset($this->input->{'input_asset'}->{'http'})) |
|
111 | + } else if (isset($this->input->{'input_asset'}->{'http'})) |
|
110 | 112 | { |
111 | 113 | // Pad HTTP input so it is cached in case of full encodes |
112 | 114 | $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; |