Passed
Push — develop ( c4488a...0835a7 )
by Andrew
04:33
created
src/variables/TranscoderVariable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
     {
148 148
         $result = "";
149 149
         $filePath = parse_url($url, PHP_URL_PATH);
150
-        $filePath = $_SERVER['DOCUMENT_ROOT'] . $filePath;
150
+        $filePath = $_SERVER[ 'DOCUMENT_ROOT' ] . $filePath;
151 151
         if (file_exists($filePath)) {
152 152
             $urlParams = [
153 153
                 'url' => $url,
Please login to merge, or discard this patch.
src/Transcoder.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         Event::on(
62 62
             CraftVariable::class,
63 63
             CraftVariable::EVENT_INIT,
64
-            function (Event $event) {
64
+            function(Event $event) {
65 65
                 /** @var CraftVariable $variable */
66 66
                 $variable = $event->sender;
67 67
                 $variable->set('transcoder', TranscoderVariable::class);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         Event::on(
73 73
             Assets::class,
74 74
             Assets::EVENT_GET_THUMB_PATH,
75
-            function (AssetThumbEvent $event) {
75
+            function(AssetThumbEvent $event) {
76 76
                 Craft::debug(
77 77
                     'Assets::EVENT_GET_THUMB_PATH',
78 78
                     __METHOD__
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
         Event::on(
95 95
             ClearCaches::class,
96 96
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
97
-            function (RegisterCacheOptionsEvent $event) {
98
-                $event->options[] = [
97
+            function(RegisterCacheOptionsEvent $event) {
98
+                $event->options[ ] = [
99 99
                     'key' => 'transcoder',
100 100
                     'label' => Craft::t('transcoder', 'Transcoder caches'),
101
-                    'action' => Transcoder::$plugin->getSettings()->transcoderPaths['default'],
101
+                    'action' => Transcoder::$plugin->getSettings()->transcoderPaths[ 'default' ],
102 102
                 ];
103 103
             }
104 104
         );
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
             Craft::t(
108 108
                 'transcoder',
109 109
                 '{name} plugin loaded',
110
-                ['name' => $this->name]
110
+                [ 'name' => $this->name ]
111 111
             ),
112 112
             __METHOD__
113 113
         );
Please login to merge, or discard this patch.
src/config.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,27 +32,27 @@  discard block
 block discarded – undo
32 32
     'ffprobePath' => '/usr/bin/ffprobe',
33 33
 
34 34
     // The options to use for ffprobe
35
-	'ffprobeOptions' => '-v quiet -print_format json -show_format -show_streams',
35
+    'ffprobeOptions' => '-v quiet -print_format json -show_format -show_streams',
36 36
 
37 37
     // The path where the transcoded videos are stored; must have a trailing /
38 38
     // Yii2 aliases are supported here    
39
-	'transcoderPaths' => [
40
-		'default' 	=> '@webroot/transcoder/',
41
-		'video' 	=> '@webroot/transcoder/video/',
42
-		'audio' 	=> '@webroot/transcoder/audio/',
43
-		'thumbnail' => '@webroot/transcoder/thumbnail/',
44
-		'gif'		=> '@webroot/transcoder/gif/'
45
-	],
39
+    'transcoderPaths' => [
40
+        'default' 	=> '@webroot/transcoder/',
41
+        'video' 	=> '@webroot/transcoder/video/',
42
+        'audio' 	=> '@webroot/transcoder/audio/',
43
+        'thumbnail' => '@webroot/transcoder/thumbnail/',
44
+        'gif'		=> '@webroot/transcoder/gif/'
45
+    ],
46 46
 	
47 47
     // The URL where the transcoded videos are stored; must have a trailing /
48 48
     // Yii2 aliases are supported here
49
-	'transcoderUrls' => [
50
-		'default' 	=> '@web/transcoder/',
51
-		'video' 	=> '@web/transcoder/video/',
52
-		'audio' 	=> '@web/transcoder/audio/',
53
-		'thumbnail' => '@web/transcoder/thumbnail/',
54
-		'gif'		=> '@web/transcoder/gif/'
55
-	],
49
+    'transcoderUrls' => [
50
+        'default' 	=> '@web/transcoder/',
51
+        'video' 	=> '@web/transcoder/video/',
52
+        'audio' 	=> '@web/transcoder/audio/',
53
+        'thumbnail' => '@web/transcoder/thumbnail/',
54
+        'gif'		=> '@web/transcoder/gif/'
55
+    ],
56 56
 	
57 57
     // Use a md5 hash for the filenames instead of parameterized naming
58 58
     'useHashedNames' => false,
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
             'audioCodecOptions' => '-async 1000',
77 77
         ],
78 78
         'gif' => [
79
-	        'fileSuffix' => '.mp4',
80
-	        'fileFormat' => 'mp4',
81
-	        'videoCodec' => 'libx264',
82
-	        'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
79
+            'fileSuffix' => '.mp4',
80
+            'fileFormat' => 'mp4',
81
+            'videoCodec' => 'libx264',
82
+            'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
83 83
         ]        
84 84
     ],
85 85
 
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
         'audioChannels' => '2',
146 146
     ],
147 147
 
148
-	// Default options for Gif encoding
149
-	'defaultGifOptions' => [
150
-		'videoEncoder'    	=> 'gif',
151
-		'fileSuffix'        => '.mp4',
152
-		'fileFormat'        => 'gif',
153
-		'videoCodec'        => 'libx264',
154
-		'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
155
-	],
148
+    // Default options for Gif encoding
149
+    'defaultGifOptions' => [
150
+        'videoEncoder'    	=> 'gif',
151
+        'fileSuffix'        => '.mp4',
152
+        'fileFormat'        => 'gif',
153
+        'videoCodec'        => 'libx264',
154
+        'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
155
+    ],
156 156
 ];
Please login to merge, or discard this patch.
src/services/Transcode.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             } else {
187 187
 
188 188
                 // Kick off the transcoding
189
-				$pid = $this->executeShellCommand($ffmpegCmd);
189
+                $pid = $this->executeShellCommand($ffmpegCmd);
190 190
                 Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
191 191
 
192 192
                 // Create a lockfile in tmp
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 
756 756
         if (!empty($filePath)) {
757 757
 
758
-			// Dest path
758
+            // Dest path
759 759
             $destVideoPath = Craft::getAlias($settings['transcoderPaths']['gif']);
760 760
                         
761 761
             // Options
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 
769 769
             // Build the basic command for ffmpeg
770 770
             $ffmpegCmd = $settings['ffmpegPath']
771
-            	. ' -f gif' 
771
+                . ' -f gif' 
772 772
                 . ' -i ' . escapeshellarg($filePath)
773 773
                 . ' -vcodec ' . $thisEncoder['videoCodec']
774 774
                 . ' ' . $thisEncoder['videoCodecOptions'];
775 775
 
776 776
 
777
-             // Create the directory if it isn't there already
777
+                // Create the directory if it isn't there already
778 778
             if (!file_exists($destVideoPath)) {
779 779
                 mkdir($destVideoPath);
780 780
             }
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
             } else {
810 810
 
811 811
                 // Kick off the transcoding
812
-				$pid = $this->executeShellCommand($ffmpegCmd);
812
+                $pid = $this->executeShellCommand($ffmpegCmd);
813 813
                 Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
814 814
 
815 815
                 // Create a lockfile in tmp
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -95,31 +95,31 @@  discard block
 block discarded – undo
95 95
 
96 96
         if (!empty($filePath)) {
97 97
 
98
-            $destVideoPath = Craft::getAlias($settings['transcoderPaths']['video']);
98
+            $destVideoPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'video' ]);
99 99
             $videoOptions = $this->coalesceOptions("defaultVideoOptions", $videoOptions);
100 100
 
101 101
             // Get the video encoder presets to use
102
-            $videoEncoders = $settings['videoEncoders'];
103
-            $thisEncoder = $videoEncoders[$videoOptions['videoEncoder']];
102
+            $videoEncoders = $settings[ 'videoEncoders' ];
103
+            $thisEncoder = $videoEncoders[ $videoOptions[ 'videoEncoder' ] ];
104 104
 
105
-            $videoOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
105
+            $videoOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
106 106
 
107 107
             // Build the basic command for ffmpeg
108
-            $ffmpegCmd = $settings['ffmpegPath']
108
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
109 109
                 . ' -i ' . escapeshellarg($filePath)
110
-                . ' -vcodec ' . $thisEncoder['videoCodec']
111
-                . ' ' . $thisEncoder['videoCodecOptions']
110
+                . ' -vcodec ' . $thisEncoder[ 'videoCodec' ]
111
+                . ' ' . $thisEncoder[ 'videoCodecOptions' ]
112 112
                 . ' -bufsize 1000k'
113 113
                 . ' -threads 0';
114 114
 
115 115
             // Set the framerate if desired
116
-            if (!empty($videoOptions['videoFrameRate'])) {
117
-                $ffmpegCmd .= ' -r ' . $videoOptions['videoFrameRate'];
116
+            if (!empty($videoOptions[ 'videoFrameRate' ])) {
117
+                $ffmpegCmd .= ' -r ' . $videoOptions[ 'videoFrameRate' ];
118 118
             }
119 119
 
120 120
             // Set the bitrate if desired
121
-            if (!empty($videoOptions['videoBitRate'])) {
122
-                $ffmpegCmd .= ' -b:v ' . $videoOptions['videoBitRate'] . ' -maxrate ' . $videoOptions['videoBitRate'];
121
+            if (!empty($videoOptions[ 'videoBitRate' ])) {
122
+                $ffmpegCmd .= ' -b:v ' . $videoOptions[ 'videoBitRate' ] . ' -maxrate ' . $videoOptions[ 'videoBitRate' ];
123 123
             }
124 124
 
125 125
             // Adjust the scaling if desired
@@ -129,25 +129,25 @@  discard block
 block discarded – undo
129 129
             );
130 130
 
131 131
             // Handle any audio transcoding
132
-            if (empty($videoOptions['audioBitRate'])
133
-                && empty($videoOptions['audioSampleRate'])
134
-                && empty($videoOptions['audioChannels'])
132
+            if (empty($videoOptions[ 'audioBitRate' ])
133
+                && empty($videoOptions[ 'audioSampleRate' ])
134
+                && empty($videoOptions[ 'audioChannels' ])
135 135
             ) {
136 136
                 // Just copy the audio if no options are provided
137 137
                 $ffmpegCmd .= ' -c:a copy';
138 138
             } else {
139 139
                 // Do audio transcoding based on the settings
140
-                $ffmpegCmd .= ' -acodec ' . $thisEncoder['audioCodec'];
141
-                if (!empty($videoOptions['audioBitRate'])) {
142
-                    $ffmpegCmd .= ' -b:a ' . $videoOptions['audioBitRate'];
140
+                $ffmpegCmd .= ' -acodec ' . $thisEncoder[ 'audioCodec' ];
141
+                if (!empty($videoOptions[ 'audioBitRate' ])) {
142
+                    $ffmpegCmd .= ' -b:a ' . $videoOptions[ 'audioBitRate' ];
143 143
                 }
144
-                if (!empty($videoOptions['audioSampleRate'])) {
145
-                    $ffmpegCmd .= ' -ar ' . $videoOptions['audioSampleRate'];
144
+                if (!empty($videoOptions[ 'audioSampleRate' ])) {
145
+                    $ffmpegCmd .= ' -ar ' . $videoOptions[ 'audioSampleRate' ];
146 146
                 }
147
-                if (!empty($videoOptions['audioChannels'])) {
148
-                    $ffmpegCmd .= ' -ac ' . $videoOptions['audioChannels'];
147
+                if (!empty($videoOptions[ 'audioChannels' ])) {
148
+                    $ffmpegCmd .= ' -ac ' . $videoOptions[ 'audioChannels' ];
149 149
                 }
150
-                $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions'];
150
+                $ffmpegCmd .= ' ' . $thisEncoder[ 'audioCodecOptions' ];
151 151
             }
152 152
 
153 153
             // Create the directory if it isn't there already
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             // Assemble the destination path and final ffmpeg command
164 164
             $destVideoPath = $destVideoPath . $destVideoFile;
165 165
             $ffmpegCmd .= ' -f '
166
-                . $thisEncoder['fileFormat']
166
+                . $thisEncoder[ 'fileFormat' ]
167 167
                 . ' -y ' . escapeshellarg($destVideoPath)
168 168
                 . ' 1> ' . $progressFile . ' 2>&1 & echo $!';
169 169
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
             // If the video file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
184 184
             if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
185
-                $result = Craft::getAlias($settings['transcoderUrls']['video']) . $destVideoFile;
185
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'video' ]) . $destVideoFile;
186 186
             } else {
187 187
 
188 188
                 // Kick off the transcoding
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         $filePath = $this->getAssetPath($filePath);
217 217
 
218 218
         if (!empty($filePath)) {
219
-            $destThumbnailPath = Craft::getAlias($settings['transcoderPaths']['thumbnail']);
219
+            $destThumbnailPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'thumbnail' ]);
220 220
 
221 221
             $thumbnailOptions = $this->coalesceOptions("defaultThumbnailOptions", $thumbnailOptions);
222 222
 
223 223
             // Build the basic command for ffmpeg
224
-            $ffmpegCmd = $settings['ffmpegPath']
224
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
225 225
                 . ' -i ' . escapeshellarg($filePath)
226 226
                 . ' -vcodec mjpeg'
227 227
                 . ' -vframes 1';
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
             );
234 234
 
235 235
             // Set the timecode to get the thumbnail from if desired
236
-            if (!empty($thumbnailOptions['timeInSecs'])) {
237
-                $timeCode = gmdate("H:i:s", $thumbnailOptions['timeInSecs']);
236
+            if (!empty($thumbnailOptions[ 'timeInSecs' ])) {
237
+                $timeCode = gmdate("H:i:s", $thumbnailOptions[ 'timeInSecs' ]);
238 238
                 $ffmpegCmd .= ' -ss ' . $timeCode . '.00';
239 239
             }
240 240
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
             if ($asPath) {
265 265
                 $result = $destThumbnailPath;
266 266
             } else {
267
-                $result = Craft::getAlias($settings['transcoderUrls']['thumbnail']) . $destThumbnailFile;
267
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'thumbnail' ]) . $destThumbnailFile;
268 268
             }
269 269
         }
270 270
 
@@ -288,37 +288,37 @@  discard block
 block discarded – undo
288 288
         $filePath = $this->getAssetPath($filePath);
289 289
 
290 290
         if (!empty($filePath)) {
291
-            $destAudioPath = Craft::getAlias($settings['transcoderPaths']['audio']);
291
+            $destAudioPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'audio' ]);
292 292
 
293 293
             $audioOptions = $this->coalesceOptions("defaultAudioOptions", $audioOptions);
294 294
 
295 295
             // Get the audio encoder presets to use
296
-            $audioEncoders = $settings['audioEncoders'];
297
-            $thisEncoder = $audioEncoders[$audioOptions['audioEncoder']];
296
+            $audioEncoders = $settings[ 'audioEncoders' ];
297
+            $thisEncoder = $audioEncoders[ $audioOptions[ 'audioEncoder' ] ];
298 298
 
299
-            $audioOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
299
+            $audioOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
300 300
 
301 301
             // Build the basic command for ffmpeg
302
-            $ffmpegCmd = $settings['ffmpegPath']
302
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
303 303
                 . ' -i ' . escapeshellarg($filePath)
304
-                . ' -acodec ' . $thisEncoder['audioCodec']
305
-                . ' ' . $thisEncoder['audioCodecOptions']
304
+                . ' -acodec ' . $thisEncoder[ 'audioCodec' ]
305
+                . ' ' . $thisEncoder[ 'audioCodecOptions' ]
306 306
                 . ' -bufsize 1000k'
307 307
                 . ' -threads 0';
308 308
 
309 309
             // Set the bitrate if desired
310
-            if (!empty($audioOptions['audioBitRate'])) {
311
-                $ffmpegCmd .= ' -b:a ' . $audioOptions['audioBitRate'];
310
+            if (!empty($audioOptions[ 'audioBitRate' ])) {
311
+                $ffmpegCmd .= ' -b:a ' . $audioOptions[ 'audioBitRate' ];
312 312
             }
313 313
             // Set the sample rate if desired
314
-            if (!empty($audioOptions['audioSampleRate'])) {
315
-                $ffmpegCmd .= ' -ar ' . $audioOptions['audioSampleRate'];
314
+            if (!empty($audioOptions[ 'audioSampleRate' ])) {
315
+                $ffmpegCmd .= ' -ar ' . $audioOptions[ 'audioSampleRate' ];
316 316
             }
317 317
             // Set the audio channels if desired
318
-            if (!empty($audioOptions['audioChannels'])) {
319
-                $ffmpegCmd .= ' -ac ' . $audioOptions['audioChannels'];
318
+            if (!empty($audioOptions[ 'audioChannels' ])) {
319
+                $ffmpegCmd .= ' -ac ' . $audioOptions[ 'audioChannels' ];
320 320
             }
321
-            $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions'];
321
+            $ffmpegCmd .= ' ' . $thisEncoder[ 'audioCodecOptions' ];
322 322
 
323 323
 
324 324
             // Create the directory if it isn't there already
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
             // Assemble the destination path and final ffmpeg command
335 335
             $destAudioPath = $destAudioPath . $destAudioFile;
336 336
             $ffmpegCmd .= ' -f '
337
-                . $thisEncoder['fileFormat']
337
+                . $thisEncoder[ 'fileFormat' ]
338 338
                 . ' -y ' . escapeshellarg($destAudioPath)
339 339
                 . ' 1> ' . $progressFile . ' 2>&1 & echo $!';
340 340
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
             // If the audio file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
355 355
             if (file_exists($destAudioPath) && (filemtime($destAudioPath) >= filemtime($filePath))) {
356
-                $result = Craft::getAlias($settings['transcoderUrls']['audio']) . $destAudioFile;
356
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'audio' ]) . $destAudioFile;
357 357
             } else {
358 358
                 // Kick off the transcoding
359 359
                 $pid = $this->executeShellCommand($ffmpegCmd);
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 
385 385
         if (!empty($filePath)) {
386 386
             // Build the basic command for ffprobe
387
-            $ffprobeOptions = $settings['ffprobeOptions'];
388
-            $ffprobeCmd = $settings['ffprobePath']
387
+            $ffprobeOptions = $settings[ 'ffprobeOptions' ];
388
+            $ffprobeCmd = $settings[ 'ffprobePath' ]
389 389
                 . ' ' . $ffprobeOptions
390 390
                 . ' ' . escapeshellarg($filePath);
391 391
 
@@ -396,24 +396,24 @@  discard block
 block discarded – undo
396 396
 
397 397
             // Trim down the arrays to just a summary
398 398
             if ($summary && !empty($result)) {
399
-                $summaryResult = [];
399
+                $summaryResult = [ ];
400 400
                 foreach ($result as $topLevelKey => $topLevelValue) {
401 401
                     switch ($topLevelKey) {
402 402
                         // Format info
403 403
                         case "format":
404
-                            foreach ($this->infoSummary['format'] as $settingKey => $settingValue) {
405
-                                if (!empty($topLevelValue[$settingKey])) {
406
-                                    $summaryResult[$settingValue] = $topLevelValue[$settingKey];
404
+                            foreach ($this->infoSummary[ 'format' ] as $settingKey => $settingValue) {
405
+                                if (!empty($topLevelValue[ $settingKey ])) {
406
+                                    $summaryResult[ $settingValue ] = $topLevelValue[ $settingKey ];
407 407
                                 }
408 408
                             }
409 409
                             break;
410 410
                         // Stream info
411 411
                         case "streams":
412 412
                             foreach ($topLevelValue as $stream) {
413
-                                $infoSummaryType = $stream['codec_type'];
414
-                                foreach ($this->infoSummary[$infoSummaryType] as $settingKey => $settingValue) {
415
-                                    if (!empty($stream[$settingKey])) {
416
-                                        $summaryResult[$settingValue] = $stream[$settingKey];
413
+                                $infoSummaryType = $stream[ 'codec_type' ];
414
+                                foreach ($this->infoSummary[ $infoSummaryType ] as $settingKey => $settingValue) {
415
+                                    if (!empty($stream[ $settingKey ])) {
416
+                                        $summaryResult[ $settingValue ] = $stream[ $settingKey ];
417 417
                                     }
418 418
                                 }
419 419
                             }
@@ -424,11 +424,11 @@  discard block
 block discarded – undo
424 424
                     }
425 425
                 }
426 426
                 // Handle cases where the framerate is returned as XX/YY
427
-                if (!empty($summaryResult['videoFrameRate'])
428
-                    && (strpos($summaryResult['videoFrameRate'], '/') !== false)
427
+                if (!empty($summaryResult[ 'videoFrameRate' ])
428
+                    && (strpos($summaryResult[ 'videoFrameRate' ], '/') !== false)
429 429
                 ) {
430
-                    $parts = explode('/', $summaryResult['videoFrameRate']);
431
-                    $summaryResult['videoFrameRate'] = floatval($parts[0]) / floatval($parts[1]);
430
+                    $parts = explode('/', $summaryResult[ 'videoFrameRate' ]);
431
+                    $summaryResult[ 'videoFrameRate' ] = floatval($parts[ 0 ]) / floatval($parts[ 1 ]);
432 432
                 }
433 433
                 $result = $summaryResult;
434 434
             }
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
         $videoOptions = $this->coalesceOptions("defaultVideoOptions", $videoOptions);
452 452
 
453 453
         // Get the video encoder presets to use
454
-        $videoEncoders = $settings['videoEncoders'];
455
-        $thisEncoder = $videoEncoders[$videoOptions['videoEncoder']];
454
+        $videoEncoders = $settings[ 'videoEncoders' ];
455
+        $thisEncoder = $videoEncoders[ $videoOptions[ 'videoEncoder' ] ];
456 456
 
457
-        $videoOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
457
+        $videoOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
458 458
 
459 459
         $result = $this->getFilename($filePath, $videoOptions);
460 460
 
@@ -475,10 +475,10 @@  discard block
 block discarded – undo
475 475
         $audioOptions = $this->coalesceOptions("defaultAudioOptions", $audioOptions);
476 476
 
477 477
         // Get the video encoder presets to use
478
-        $audioEncoders = $settings['audioEncoders'];
479
-        $thisEncoder = $audioEncoders[$audioOptions['audioEncoder']];
478
+        $audioEncoders = $settings[ 'audioEncoders' ];
479
+        $thisEncoder = $audioEncoders[ $audioOptions[ 'audioEncoder' ] ];
480 480
 
481
-        $audioOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
481
+        $audioOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
482 482
 
483 483
         $result = $this->getFilename($filePath, $audioOptions);
484 484
 
@@ -499,10 +499,10 @@  discard block
 block discarded – undo
499 499
         $gifOptions = $this->coalesceOptions("defaultGifOptions", $gifOptions);
500 500
 
501 501
         // Get the video encoder presets to use
502
-        $videoEncoders = $settings['videoEncoders'];
503
-        $thisEncoder = $videoEncoders[$gifOptions['videoEncoder']];
502
+        $videoEncoders = $settings[ 'videoEncoders' ];
503
+        $thisEncoder = $videoEncoders[ $gifOptions[ 'videoEncoder' ] ];
504 504
 
505
-        $gifOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
505
+        $gifOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
506 506
 
507 507
         $result = $this->getFilename($filePath, $gifOptions);
508 508
 
@@ -547,18 +547,18 @@  discard block
 block discarded – undo
547 547
         $error = '';
548 548
         if ($validator->validate($filePath, $error)) {
549 549
             $urlParts = parse_url($filePath);
550
-            $pathParts = pathinfo($urlParts['path']);
550
+            $pathParts = pathinfo($urlParts[ 'path' ]);
551 551
         } else {
552 552
             $pathParts = pathinfo($filePath);
553 553
         }
554
-        $fileName = $pathParts['filename'];
554
+        $fileName = $pathParts[ 'filename' ];
555 555
 
556 556
         // Add our options to the file name
557 557
         foreach ($options as $key => $value) {
558 558
             if (!empty($value)) {
559 559
                 $suffix = "";
560
-                if (!empty($this->suffixMap[$key])) {
561
-                    $suffix = $this->suffixMap[$key];
560
+                if (!empty($this->suffixMap[ $key ])) {
561
+                    $suffix = $this->suffixMap[ $key ];
562 562
                 }
563 563
                 if (is_bool($value)) {
564 564
                     $value = $value ? $key : 'no' . $key;
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
             }
570 570
         }
571 571
         // See if we should use a hash instead
572
-        if ($settings['useHashedNames']) {
573
-            $fileName = $pathParts['filename'] . md5($fileName);
572
+        if ($settings[ 'useHashedNames' ]) {
573
+            $fileName = $pathParts[ 'filename' ] . md5($fileName);
574 574
         }
575
-        $fileName .= $options['fileSuffix'];
575
+        $fileName .= $options[ 'fileSuffix' ];
576 576
 
577 577
         return $fileName;
578 578
     }
@@ -643,39 +643,39 @@  discard block
 block discarded – undo
643 643
      */
644 644
     protected function addScalingFfmpegArgs($options, $ffmpegCmd): string
645 645
     {
646
-        if (!empty($options['width']) && !empty($options['height'])) {
646
+        if (!empty($options[ 'width' ]) && !empty($options[ 'height' ])) {
647 647
             // Handle "none", "crop", and "letterbox" aspectRatios
648 648
             $aspectRatio = "";
649
-            if (!empty($options['aspectRatio'])) {
650
-                switch ($options['aspectRatio']) {
649
+            if (!empty($options[ 'aspectRatio' ])) {
650
+                switch ($options[ 'aspectRatio' ]) {
651 651
                     // Scale to the appropriate aspect ratio, padding
652 652
                     case "letterbox":
653 653
                         $letterboxColor = "";
654
-                        if (!empty($options['letterboxColor'])) {
655
-                            $letterboxColor = ":color=" . $options['letterboxColor'];
654
+                        if (!empty($options[ 'letterboxColor' ])) {
655
+                            $letterboxColor = ":color=" . $options[ 'letterboxColor' ];
656 656
                         }
657 657
                         $aspectRatio = ':force_original_aspect_ratio=decrease'
658
-                            . ',pad=' . $options['width'] . ':' . $options['height'] . ':(ow-iw)/2:(oh-ih)/2'
658
+                            . ',pad=' . $options[ 'width' ] . ':' . $options[ 'height' ] . ':(ow-iw)/2:(oh-ih)/2'
659 659
                             . $letterboxColor;
660 660
                         break;
661 661
                     // Scale to the appropriate aspect ratio, cropping
662 662
                     case "crop":
663 663
                         $aspectRatio = ':force_original_aspect_ratio=increase'
664
-                            . ',crop=' . $options['width'] . ':' . $options['height'];
664
+                            . ',crop=' . $options[ 'width' ] . ':' . $options[ 'height' ];
665 665
                         break;
666 666
                     // No aspect ratio scaling at all
667 667
                     default:
668 668
                         $aspectRatio = ':force_original_aspect_ratio=disable';
669
-                        $options['aspectRatio'] = "none";
669
+                        $options[ 'aspectRatio' ] = "none";
670 670
                         break;
671 671
                 }
672 672
             }
673 673
             $sharpen = "";
674
-            if (!empty($options['sharpen']) && ($options['sharpen'] !== false)) {
674
+            if (!empty($options[ 'sharpen' ]) && ($options[ 'sharpen' ] !== false)) {
675 675
                 $sharpen = ',unsharp=5:5:1.0:5:5:0.0';
676 676
             }
677 677
             $ffmpegCmd .= ' -vf "scale='
678
-                . $options['width'] . ':' . $options['height']
678
+                . $options[ 'width' ] . ':' . $options[ 'height' ]
679 679
                 . $aspectRatio
680 680
                 . $sharpen
681 681
                 . '"';
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
     {
697 697
         // Default options
698 698
         $settings = Transcoder::$plugin->getSettings();
699
-        $defaultOptions = $settings[$defaultName];
699
+        $defaultOptions = $settings[ $defaultName ];
700 700
 
701 701
         // Coalesce the passed in $options with the $defaultOptions
702 702
         $options = array_merge($defaultOptions, $options);
@@ -756,22 +756,22 @@  discard block
 block discarded – undo
756 756
         if (!empty($filePath)) {
757 757
 
758 758
 			// Dest path
759
-            $destVideoPath = Craft::getAlias($settings['transcoderPaths']['gif']);
759
+            $destVideoPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'gif' ]);
760 760
                         
761 761
             // Options
762 762
             $gifOptions = $this->coalesceOptions("defaultGifOptions", $gifOptions);
763 763
 
764 764
             // Get the video encoder presets to use
765
-            $videoEncoders = $settings['videoEncoders'];
766
-            $thisEncoder = $videoEncoders[$gifOptions['videoEncoder']];
767
-            $gifOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
765
+            $videoEncoders = $settings[ 'videoEncoders' ];
766
+            $thisEncoder = $videoEncoders[ $gifOptions[ 'videoEncoder' ] ];
767
+            $gifOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
768 768
 
769 769
             // Build the basic command for ffmpeg
770
-            $ffmpegCmd = $settings['ffmpegPath']
770
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
771 771
             	. ' -f gif' 
772 772
                 . ' -i ' . escapeshellarg($filePath)
773
-                . ' -vcodec ' . $thisEncoder['videoCodec']
774
-                . ' ' . $thisEncoder['videoCodecOptions'];
773
+                . ' -vcodec ' . $thisEncoder[ 'videoCodec' ]
774
+                . ' ' . $thisEncoder[ 'videoCodecOptions' ];
775 775
 
776 776
 
777 777
              // Create the directory if it isn't there already
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 
806 806
             // If the video file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
807 807
             if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
808
-                $result = Craft::getAlias($settings['transcoderUrls']['gif']) . $destVideoFile;
808
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'gif' ]) . $destVideoFile;
809 809
             } else {
810 810
 
811 811
                 // Kick off the transcoding
Please login to merge, or discard this patch.
src/models/Settings.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @var string
53 53
      */
54
-	 public $transcoderPaths = [];
54
+        public $transcoderPaths = [];
55 55
 	 
56 56
     /**
57 57
      * The URL where the transcoded videos are stored; must have a trailing /
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
             'audioCodecOptions' => '-async 1000',
92 92
         ],
93 93
         'gif' => [
94
-	        'fileSuffix' => '.mp4',
95
-	        'fileFormat' => 'mp4',
96
-	        'videoCodec' => 'libx264',
97
-	        'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
94
+            'fileSuffix' => '.mp4',
95
+            'fileFormat' => 'mp4',
96
+            'videoCodec' => 'libx264',
97
+            'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ',
98 98
         ]           
99 99
     ];
100 100
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * @var array
183 183
      */
184 184
     public $defaultGifOptions = [
185
-		'videoEncoder'    	=> 'gif',
185
+        'videoEncoder'    	=> 'gif',
186 186
         'fileSuffix'        => '',
187 187
         'fileFormat'        => '',
188 188
         'videoCodec'        => '',
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @var string
53 53
      */
54
-	 public $transcoderPaths = [];
54
+	 public $transcoderPaths = [ ];
55 55
 	 
56 56
     /**
57 57
      * The URL where the transcoded videos are stored; must have a trailing /
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @var string
61 61
      */
62
-    public $transcoderUrls = [];
62
+    public $transcoderUrls = [ ];
63 63
 
64 64
     /**
65 65
      * Use a md5 hash for the filenames instead of parameterized naming
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     public function init()
199 199
     {
200 200
         $tokens = [
201
-            '{DOCUMENT_ROOT}' => $_SERVER['DOCUMENT_ROOT'],
201
+            '{DOCUMENT_ROOT}' => $_SERVER[ 'DOCUMENT_ROOT' ],
202 202
         ];
203 203
         $this->transcoderPath = str_replace(array_keys($tokens), array_values($tokens), $this->transcoderPath);
204 204
     }
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
     public function rules()
210 210
     {
211 211
         return [
212
-            ['ffmpegPath', 'string'],
213
-            ['ffmpegPath', 'required'],
214
-            ['ffprobePath', 'string'],
215
-            ['ffprobePath', 'required'],
216
-            ['ffprobeOptions', 'string'],
217
-            ['ffprobeOptions', 'safe'],
218
-            ['transcoderPath', 'string'],
219
-            ['transcoderPath', 'required'],
220
-            ['transcoderPaths', 'array'],
221
-            ['transcoderPaths', 'required'],
222
-            ['transcoderUrls', 'array'],
223
-            ['transcoderUrls', 'required'],
224
-            ['useHashedNames', 'boolean'],
225
-            ['useHashedNames', 'default', 'value' => false],
226
-            ['videoEncoders', 'required'],
227
-            ['audioEncoders', 'required'],
228
-            ['defaultVideoOptions', 'required'],
229
-            ['defaultThumbnailOptions', 'required'],
230
-            ['defaultAudioOptions', 'required'],
212
+            [ 'ffmpegPath', 'string' ],
213
+            [ 'ffmpegPath', 'required' ],
214
+            [ 'ffprobePath', 'string' ],
215
+            [ 'ffprobePath', 'required' ],
216
+            [ 'ffprobeOptions', 'string' ],
217
+            [ 'ffprobeOptions', 'safe' ],
218
+            [ 'transcoderPath', 'string' ],
219
+            [ 'transcoderPath', 'required' ],
220
+            [ 'transcoderPaths', 'array' ],
221
+            [ 'transcoderPaths', 'required' ],
222
+            [ 'transcoderUrls', 'array' ],
223
+            [ 'transcoderUrls', 'required' ],
224
+            [ 'useHashedNames', 'boolean' ],
225
+            [ 'useHashedNames', 'default', 'value' => false ],
226
+            [ 'videoEncoders', 'required' ],
227
+            [ 'audioEncoders', 'required' ],
228
+            [ 'defaultVideoOptions', 'required' ],
229
+            [ 'defaultThumbnailOptions', 'required' ],
230
+            [ 'defaultAudioOptions', 'required' ],
231 231
         ];
232 232
     }
233 233
 }
Please login to merge, or discard this patch.
src/controllers/DefaultController.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
     public function actionDownloadFile($url)
50 50
     {
51 51
         $filePath = parse_url($url, PHP_URL_PATH);
52
-        $filePath = $_SERVER['DOCUMENT_ROOT'].$filePath;
52
+        $filePath = $_SERVER[ 'DOCUMENT_ROOT' ] . $filePath;
53 53
         Craft::$app->getResponse()->sendFile(
54 54
             $filePath,
55 55
             null,
56
-            ['inline' => false]
56
+            [ 'inline' => false ]
57 57
         );
58 58
         Craft::$app->end();
59 59
     }
@@ -72,24 +72,24 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function actionProgress($filename)
74 74
     {
75
-        $result = [];
76
-        $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename.'.progress';
75
+        $result = [ ];
76
+        $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename . '.progress';
77 77
         if (file_exists($progressFile)) {
78 78
             $content = @file_get_contents($progressFile);
79 79
             if ($content) {
80 80
                 // get duration of source
81 81
                 preg_match('/Duration: (.*?), start:/', $content, $matches);
82 82
                 if (\count($matches) > 0) {
83
-                    $rawDuration = $matches[1];
83
+                    $rawDuration = $matches[ 1 ];
84 84
 
85 85
                     // rawDuration is in 00:00:00.00 format. This converts it to seconds.
86 86
                     $ar = array_reverse(explode(':', $rawDuration));
87
-                    $duration = (float)$ar[0];
88
-                    if (!empty($ar[1])) {
89
-                        $duration += (int)$ar[1] * 60;
87
+                    $duration = (float) $ar[ 0 ];
88
+                    if (!empty($ar[ 1 ])) {
89
+                        $duration += (int) $ar[ 1 ] * 60;
90 90
                     }
91
-                    if (!empty($ar[2])) {
92
-                        $duration += (int)$ar[2] * 60 * 60;
91
+                    if (!empty($ar[ 2 ])) {
92
+                        $duration += (int) $ar[ 2 ] * 60 * 60;
93 93
                     }
94 94
                 } else {
95 95
                     $duration = 'unknown'; // with GIF as input, duration is unknown
@@ -106,12 +106,12 @@  discard block
 block discarded – undo
106 106
 
107 107
                 //rawTime is in 00:00:00.00 format. This converts it to seconds.
108 108
                 $ar = array_reverse(explode(':', $rawTime));
109
-                $time = (float)$ar[0];
110
-                if (!empty($ar[1])) {
111
-                    $time += (int)$ar[1] * 60;
109
+                $time = (float) $ar[ 0 ];
110
+                if (!empty($ar[ 1 ])) {
111
+                    $time += (int) $ar[ 1 ] * 60;
112 112
                 }
113
-                if (!empty($ar[2])) {
114
-                    $time += (int)$ar[2] * 60 * 60;
113
+                if (!empty($ar[ 2 ])) {
114
+                    $time += (int) $ar[ 2 ] * 60 * 60;
115 115
                 }
116 116
 
117 117
                 //calculate the progress
Please login to merge, or discard this patch.