@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * The actions must be in 'kebab-case' |
| 38 | 38 | * @access protected |
| 39 | 39 | */ |
| 40 | - protected array|bool|int $allowAnonymous = [ |
|
| 40 | + protected array | bool | int $allowAnonymous = [ |
|
| 41 | 41 | 'download-file', |
| 42 | 42 | 'progress', |
| 43 | 43 | ]; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $filePath = parse_url($url, PHP_URL_PATH); |
| 73 | 73 | // Remove any relative paths |
| 74 | 74 | if (!PathHelper::ensurePathIsContained($filePath)) { |
| 75 | - throw new BadRequestHttpException('Invalid resource path: ' . $filePath); |
|
| 75 | + throw new BadRequestHttpException('Invalid resource path: '.$filePath); |
|
| 76 | 76 | } |
| 77 | 77 | // Only work for `allowedFileExtensions` file extensions |
| 78 | 78 | $extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | throw new AssetDisallowedExtensionException("File “{$filePath}” cannot be downloaded because “{$extension}” is not allowed."); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $filePath = $_SERVER['DOCUMENT_ROOT'] . $filePath; |
|
| 84 | + $filePath = $_SERVER['DOCUMENT_ROOT'].$filePath; |
|
| 85 | 85 | Craft::$app->getResponse()->sendFile( |
| 86 | 86 | $filePath, |
| 87 | 87 | null, |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public function actionProgress($filename): Response |
| 106 | 106 | { |
| 107 | 107 | $result = []; |
| 108 | - $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename . '.progress'; |
|
| 108 | + $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename.'.progress'; |
|
| 109 | 109 | if (file_exists($progressFile)) { |
| 110 | 110 | $content = @file_get_contents($progressFile); |
| 111 | 111 | if ($content) { |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | // rawDuration is in 00:00:00.00 format. This converts it to seconds. |
| 118 | 118 | $ar = array_reverse(explode(':', $rawDuration)); |
| 119 | - $duration = (float)$ar[0]; |
|
| 119 | + $duration = (float) $ar[0]; |
|
| 120 | 120 | if (!empty($ar[1])) { |
| 121 | - $duration += (int)$ar[1] * 60; |
|
| 121 | + $duration += (int) $ar[1] * 60; |
|
| 122 | 122 | } |
| 123 | 123 | if (!empty($ar[2])) { |
| 124 | - $duration += (int)$ar[2] * 60 * 60; |
|
| 124 | + $duration += (int) $ar[2] * 60 * 60; |
|
| 125 | 125 | } |
| 126 | 126 | } else { |
| 127 | 127 | $duration = 'unknown'; // with GIF as input, duration is unknown |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | //rawTime is in 00:00:00.00 format. This converts it to seconds. |
| 140 | 140 | $ar = array_reverse(explode(':', $rawTime)); |
| 141 | - $time = (float)$ar[0]; |
|
| 141 | + $time = (float) $ar[0]; |
|
| 142 | 142 | if (!empty($ar[1])) { |
| 143 | - $time += (int)$ar[1] * 60; |
|
| 143 | + $time += (int) $ar[1] * 60; |
|
| 144 | 144 | } |
| 145 | 145 | if (!empty($ar[2])) { |
| 146 | - $time += (int)$ar[2] * 60 * 60; |
|
| 146 | + $time += (int) $ar[2] * 60 * 60; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | //calculate the progress |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return string URL of the transcoded video or "" |
| 98 | 98 | * @throws InvalidConfigException |
| 99 | 99 | */ |
| 100 | - public function getVideoUrl(string|Asset $filePath, array $videoOptions, bool $generate = true): string |
|
| 100 | + public function getVideoUrl(string | Asset $filePath, array $videoOptions, bool $generate = true): string |
|
| 101 | 101 | { |
| 102 | 102 | $result = ''; |
| 103 | 103 | $settings = Transcoder::$plugin->getSettings(); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $filePath = $this->getAssetPath($filePath); |
| 113 | 113 | |
| 114 | 114 | if (!empty($filePath)) { |
| 115 | - $destVideoPath = $settings['transcoderPaths']['video'] . $subfolder ?? $settings['transcoderPaths']['default']; |
|
| 115 | + $destVideoPath = $settings['transcoderPaths']['video'].$subfolder ?? $settings['transcoderPaths']['default']; |
|
| 116 | 116 | $destVideoPath = App::parseEnv($destVideoPath); |
| 117 | 117 | $videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions); |
| 118 | 118 | |
@@ -124,20 +124,20 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | // Build the basic command for ffmpeg |
| 126 | 126 | $ffmpegCmd = $settings['ffmpegPath'] |
| 127 | - . ' -i ' . escapeshellarg($filePath) |
|
| 128 | - . ' -vcodec ' . $thisEncoder['videoCodec'] |
|
| 129 | - . ' ' . $thisEncoder['videoCodecOptions'] |
|
| 127 | + . ' -i '.escapeshellarg($filePath) |
|
| 128 | + . ' -vcodec '.$thisEncoder['videoCodec'] |
|
| 129 | + . ' '.$thisEncoder['videoCodecOptions'] |
|
| 130 | 130 | . ' -bufsize 1000k' |
| 131 | - . ' -threads ' . $thisEncoder['threads']; |
|
| 131 | + . ' -threads '.$thisEncoder['threads']; |
|
| 132 | 132 | |
| 133 | 133 | // Set the framerate if desired |
| 134 | 134 | if (!empty($videoOptions['videoFrameRate'])) { |
| 135 | - $ffmpegCmd .= ' -r ' . $videoOptions['videoFrameRate']; |
|
| 135 | + $ffmpegCmd .= ' -r '.$videoOptions['videoFrameRate']; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Set the bitrate if desired |
| 139 | 139 | if (!empty($videoOptions['videoBitRate'])) { |
| 140 | - $ffmpegCmd .= ' -b:v ' . $videoOptions['videoBitRate'] . ' -maxrate ' . $videoOptions['videoBitRate']; |
|
| 140 | + $ffmpegCmd .= ' -b:v '.$videoOptions['videoBitRate'].' -maxrate '.$videoOptions['videoBitRate']; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Adjust the scaling if desired |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | $ffmpegCmd .= ' -c:a copy'; |
| 156 | 156 | } else { |
| 157 | 157 | // Do audio transcoding based on the settings |
| 158 | - $ffmpegCmd .= ' -acodec ' . $thisEncoder['audioCodec']; |
|
| 158 | + $ffmpegCmd .= ' -acodec '.$thisEncoder['audioCodec']; |
|
| 159 | 159 | if (!empty($videoOptions['audioBitRate'])) { |
| 160 | - $ffmpegCmd .= ' -b:a ' . $videoOptions['audioBitRate']; |
|
| 160 | + $ffmpegCmd .= ' -b:a '.$videoOptions['audioBitRate']; |
|
| 161 | 161 | } |
| 162 | 162 | if (!empty($videoOptions['audioSampleRate'])) { |
| 163 | - $ffmpegCmd .= ' -ar ' . $videoOptions['audioSampleRate']; |
|
| 163 | + $ffmpegCmd .= ' -ar '.$videoOptions['audioSampleRate']; |
|
| 164 | 164 | } |
| 165 | 165 | if (!empty($videoOptions['audioChannels'])) { |
| 166 | - $ffmpegCmd .= ' -ac ' . $videoOptions['audioChannels']; |
|
| 166 | + $ffmpegCmd .= ' -ac '.$videoOptions['audioChannels']; |
|
| 167 | 167 | } |
| 168 | - $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions']; |
|
| 168 | + $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions']; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Create the directory if it isn't there already |
@@ -180,17 +180,17 @@ discard block |
||
| 180 | 180 | $destVideoFile = $this->getFilename($filePath, $videoOptions); |
| 181 | 181 | |
| 182 | 182 | // File to store the video encoding progress in |
| 183 | - $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress'; |
|
| 183 | + $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress'; |
|
| 184 | 184 | |
| 185 | 185 | // Assemble the destination path and final ffmpeg command |
| 186 | 186 | $destVideoPath .= $destVideoFile; |
| 187 | 187 | $ffmpegCmd .= ' -f ' |
| 188 | 188 | . $thisEncoder['fileFormat'] |
| 189 | - . ' -y ' . escapeshellarg($destVideoPath) |
|
| 190 | - . ' 1> ' . $progressFile . ' 2>&1 & echo $!'; |
|
| 189 | + . ' -y '.escapeshellarg($destVideoPath) |
|
| 190 | + . ' 1> '.$progressFile.' 2>&1 & echo $!'; |
|
| 191 | 191 | |
| 192 | 192 | // Make sure there isn't a lockfile for this video already |
| 193 | - $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock'; |
|
| 193 | + $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock'; |
|
| 194 | 194 | $oldPid = @file_get_contents($lockFile); |
| 195 | 195 | if ($oldPid !== false) { |
| 196 | 196 | // See if the process is running, and empty result means the process is still running |
@@ -206,15 +206,15 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding |
| 208 | 208 | if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) { |
| 209 | - $url = $settings['transcoderUrls']['video'] . $subfolder ?? $settings['transcoderUrls']['default']; |
|
| 210 | - $result = App::parseEnv($url) . $destVideoFile; |
|
| 209 | + $url = $settings['transcoderUrls']['video'].$subfolder ?? $settings['transcoderUrls']['default']; |
|
| 210 | + $result = App::parseEnv($url).$destVideoFile; |
|
| 211 | 211 | // skip encoding |
| 212 | 212 | } elseif (!$generate) { |
| 213 | 213 | $result = ''; |
| 214 | 214 | } else { |
| 215 | 215 | // Kick off the transcoding |
| 216 | 216 | $pid = $this->executeShellCommand($ffmpegCmd); |
| 217 | - Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__); |
|
| 217 | + Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__); |
|
| 218 | 218 | |
| 219 | 219 | // Create a lockfile in tmp |
| 220 | 220 | file_put_contents($lockFile, $pid); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @return string|false|null URL or path of the video thumbnail |
| 237 | 237 | * @throws InvalidConfigException |
| 238 | 238 | */ |
| 239 | - public function getVideoThumbnailUrl(Asset|string $filePath, array $thumbnailOptions, bool $generate = true, bool $asPath = false): string|false|null |
|
| 239 | + public function getVideoThumbnailUrl(Asset | string $filePath, array $thumbnailOptions, bool $generate = true, bool $asPath = false): string | false | null |
|
| 240 | 240 | { |
| 241 | 241 | $result = null; |
| 242 | 242 | $settings = Transcoder::$plugin->getSettings(); |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | $filePath = $this->getAssetPath($filePath); |
| 251 | 251 | |
| 252 | 252 | if (!empty($filePath)) { |
| 253 | - $destThumbnailPath = $settings['transcoderPaths']['thumbnail'] . $subfolder ?? $settings['transcoderPaths']['default']; |
|
| 253 | + $destThumbnailPath = $settings['transcoderPaths']['thumbnail'].$subfolder ?? $settings['transcoderPaths']['default']; |
|
| 254 | 254 | $destThumbnailPath = App::parseEnv($destThumbnailPath); |
| 255 | 255 | |
| 256 | 256 | $thumbnailOptions = $this->coalesceOptions('defaultThumbnailOptions', $thumbnailOptions); |
| 257 | 257 | |
| 258 | 258 | // Build the basic command for ffmpeg |
| 259 | 259 | $ffmpegCmd = $settings['ffmpegPath'] |
| 260 | - . ' -i ' . escapeshellarg($filePath) |
|
| 260 | + . ' -i '.escapeshellarg($filePath) |
|
| 261 | 261 | . ' -vcodec mjpeg' |
| 262 | 262 | . ' -vframes 1'; |
| 263 | 263 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | // Set the timecode to get the thumbnail from if desired |
| 271 | 271 | if (!empty($thumbnailOptions['timeInSecs'])) { |
| 272 | 272 | $timeCode = gmdate('H:i:s', $thumbnailOptions['timeInSecs']); |
| 273 | - $ffmpegCmd .= ' -ss ' . $timeCode . '.00'; |
|
| 273 | + $ffmpegCmd .= ' -ss '.$timeCode.'.00'; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Create the directory if it isn't there already |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | // Assemble the destination path and final ffmpeg command |
| 288 | 288 | $destThumbnailPath .= $destThumbnailFile; |
| 289 | - $ffmpegCmd .= ' -f image2 -y ' . escapeshellarg($destThumbnailPath) . ' >/dev/null 2>/dev/null &'; |
|
| 289 | + $ffmpegCmd .= ' -f image2 -y '.escapeshellarg($destThumbnailPath).' >/dev/null 2>/dev/null &'; |
|
| 290 | 290 | |
| 291 | 291 | // If the thumbnail file already exists, return it. Otherwise, generate it and return it |
| 292 | 292 | if (!file_exists($destThumbnailPath)) { |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | // don't return the future path of the image or else we can't check this in the front end |
| 300 | 300 | |
| 301 | 301 | } else { |
| 302 | - Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__); |
|
| 302 | + Craft::info('Thumbnail does not exist, but not asked to generate it: '.$filePath, __METHOD__); |
|
| 303 | 303 | |
| 304 | 304 | // The file doesn't exist, and we weren't asked to generate it |
| 305 | 305 | } |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | if ($asPath) { |
| 310 | 310 | $result = $destThumbnailPath; |
| 311 | 311 | } else { |
| 312 | - $url = $settings['transcoderUrls']['thumbnail'] . $subfolder ?? $settings['transcoderUrls']['default']; |
|
| 313 | - $result = App::parseEnv($url) . $destThumbnailFile; |
|
| 312 | + $url = $settings['transcoderUrls']['thumbnail'].$subfolder ?? $settings['transcoderUrls']['default']; |
|
| 313 | + $result = App::parseEnv($url).$destThumbnailFile; |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @return string URL of the transcoded audio file or "" |
| 328 | 328 | * @throws InvalidConfigException |
| 329 | 329 | */ |
| 330 | - public function getAudioUrl(Asset|string $filePath, array $audioOptions): string |
|
| 330 | + public function getAudioUrl(Asset | string $filePath, array $audioOptions): string |
|
| 331 | 331 | { |
| 332 | 332 | $result = ''; |
| 333 | 333 | $settings = Transcoder::$plugin->getSettings(); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | $filePath = $this->getAssetPath($filePath); |
| 342 | 342 | |
| 343 | 343 | if (!empty($filePath)) { |
| 344 | - $destAudioPath = $settings['transcoderPaths']['audio'] . $subfolder ?? $settings['transcoderPaths']['default']; |
|
| 344 | + $destAudioPath = $settings['transcoderPaths']['audio'].$subfolder ?? $settings['transcoderPaths']['default']; |
|
| 345 | 345 | $destAudioPath = App::parseEnv($destAudioPath); |
| 346 | 346 | |
| 347 | 347 | $audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions); |
@@ -354,33 +354,33 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | // Build the basic command for ffmpeg |
| 356 | 356 | $ffmpegCmd = $settings['ffmpegPath'] |
| 357 | - . ' -i ' . escapeshellarg($filePath) |
|
| 358 | - . ' -acodec ' . $thisEncoder['audioCodec'] |
|
| 359 | - . ' ' . $thisEncoder['audioCodecOptions'] |
|
| 357 | + . ' -i '.escapeshellarg($filePath) |
|
| 358 | + . ' -acodec '.$thisEncoder['audioCodec'] |
|
| 359 | + . ' '.$thisEncoder['audioCodecOptions'] |
|
| 360 | 360 | . ' -bufsize 1000k' |
| 361 | 361 | . ' -vn' |
| 362 | - . ' -threads ' . $thisEncoder['threads']; |
|
| 362 | + . ' -threads '.$thisEncoder['threads']; |
|
| 363 | 363 | |
| 364 | 364 | // Set the bitrate if desired |
| 365 | 365 | if (!empty($audioOptions['audioBitRate'])) { |
| 366 | - $ffmpegCmd .= ' -b:a ' . $audioOptions['audioBitRate']; |
|
| 366 | + $ffmpegCmd .= ' -b:a '.$audioOptions['audioBitRate']; |
|
| 367 | 367 | } |
| 368 | 368 | // Set the sample rate if desired |
| 369 | 369 | if (!empty($audioOptions['audioSampleRate'])) { |
| 370 | - $ffmpegCmd .= ' -ar ' . $audioOptions['audioSampleRate']; |
|
| 370 | + $ffmpegCmd .= ' -ar '.$audioOptions['audioSampleRate']; |
|
| 371 | 371 | } |
| 372 | 372 | // Set the audio channels if desired |
| 373 | 373 | if (!empty($audioOptions['audioChannels'])) { |
| 374 | - $ffmpegCmd .= ' -ac ' . $audioOptions['audioChannels']; |
|
| 374 | + $ffmpegCmd .= ' -ac '.$audioOptions['audioChannels']; |
|
| 375 | 375 | } |
| 376 | - $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions']; |
|
| 376 | + $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions']; |
|
| 377 | 377 | |
| 378 | 378 | if (!empty($audioOptions['seekInSecs'])) { |
| 379 | - $ffmpegCmd .= ' -ss ' . $audioOptions['seekInSecs']; |
|
| 379 | + $ffmpegCmd .= ' -ss '.$audioOptions['seekInSecs']; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | if (!empty($audioOptions['timeInSecs'])) { |
| 383 | - $ffmpegCmd .= ' -t ' . $audioOptions['timeInSecs']; |
|
| 383 | + $ffmpegCmd .= ' -t '.$audioOptions['timeInSecs']; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // Create the directory if it isn't there already |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | $destAudioFile = $this->getFilename($filePath, $audioOptions); |
| 396 | 396 | |
| 397 | 397 | // File to store the audio encoding progress in |
| 398 | - $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.progress'; |
|
| 398 | + $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.progress'; |
|
| 399 | 399 | |
| 400 | 400 | // Assemble the destination path and final ffmpeg command |
| 401 | 401 | $destAudioPath .= $destAudioFile; |
@@ -410,16 +410,16 @@ discard block |
||
| 410 | 410 | // Add the file format |
| 411 | 411 | $ffmpegCmd .= ' -f ' |
| 412 | 412 | . $thisEncoder['fileFormat'] |
| 413 | - . ' -y ' . escapeshellarg($destAudioPath); |
|
| 413 | + . ' -y '.escapeshellarg($destAudioPath); |
|
| 414 | 414 | // Handle the `synchronous` setting |
| 415 | 415 | $synchronous = false; |
| 416 | 416 | if (!empty($audioOptions['synchronous'])) { |
| 417 | 417 | $synchronous = $audioOptions['synchronous']; |
| 418 | 418 | } |
| 419 | 419 | if (!$synchronous) { |
| 420 | - $ffmpegCmd .= ' 1> ' . $progressFile . ' 2>&1 & echo $!'; |
|
| 420 | + $ffmpegCmd .= ' 1> '.$progressFile.' 2>&1 & echo $!'; |
|
| 421 | 421 | // Make sure there isn't a lockfile for this audio file already |
| 422 | - $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.lock'; |
|
| 422 | + $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.lock'; |
|
| 423 | 423 | $oldPid = @file_get_contents($lockFile); |
| 424 | 424 | if ($oldPid !== false) { |
| 425 | 425 | // See if the process is running, and empty result means the process is still running |
@@ -436,18 +436,18 @@ discard block |
||
| 436 | 436 | |
| 437 | 437 | // If the audio file already exists and hasn't been modified, return it. Otherwise, start it transcoding |
| 438 | 438 | if (file_exists($destAudioPath) && (@filemtime($destAudioPath) >= @filemtime($filePath))) { |
| 439 | - $url = $settings['transcoderUrls']['audio'] . $subfolder ?? $settings['transcoderUrls']['default']; |
|
| 440 | - $result = App::parseEnv($url) . $destAudioFile; |
|
| 439 | + $url = $settings['transcoderUrls']['audio'].$subfolder ?? $settings['transcoderUrls']['default']; |
|
| 440 | + $result = App::parseEnv($url).$destAudioFile; |
|
| 441 | 441 | } else { |
| 442 | 442 | // Kick off the transcoding |
| 443 | 443 | $pid = $this->executeShellCommand($ffmpegCmd); |
| 444 | 444 | |
| 445 | 445 | if ($synchronous) { |
| 446 | 446 | Craft::info($ffmpegCmd, __METHOD__); |
| 447 | - $url = $settings['transcoderUrls']['audio'] . $subfolder ?? $settings['transcoderUrls']['default']; |
|
| 448 | - $result = App::parseEnv($url) . $destAudioFile; |
|
| 447 | + $url = $settings['transcoderUrls']['audio'].$subfolder ?? $settings['transcoderUrls']['default']; |
|
| 448 | + $result = App::parseEnv($url).$destAudioFile; |
|
| 449 | 449 | } else { |
| 450 | - Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__); |
|
| 450 | + Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__); |
|
| 451 | 451 | // Create a lockfile in tmp |
| 452 | 452 | file_put_contents($lockFile, $pid); |
| 453 | 453 | } |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @return null|array |
| 467 | 467 | * @throws InvalidConfigException |
| 468 | 468 | */ |
| 469 | - public function getFileInfo(Asset|string $filePath, bool $summary = false): ?array |
|
| 469 | + public function getFileInfo(Asset | string $filePath, bool $summary = false): ?array |
|
| 470 | 470 | { |
| 471 | 471 | $result = null; |
| 472 | 472 | $settings = Transcoder::$plugin->getSettings(); |
@@ -476,8 +476,8 @@ discard block |
||
| 476 | 476 | // Build the basic command for ffprobe |
| 477 | 477 | $ffprobeOptions = $settings['ffprobeOptions']; |
| 478 | 478 | $ffprobeCmd = $settings['ffprobePath'] |
| 479 | - . ' ' . $ffprobeOptions |
|
| 480 | - . ' ' . escapeshellarg($filePath); |
|
| 479 | + . ' '.$ffprobeOptions |
|
| 480 | + . ' '.escapeshellarg($filePath); |
|
| 481 | 481 | |
| 482 | 482 | $shellOutput = $this->executeShellCommand($ffprobeCmd); |
| 483 | 483 | Craft::info($ffprobeCmd, __METHOD__); |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | && (str_contains($summaryResult['videoFrameRate'], '/')) |
| 524 | 524 | ) { |
| 525 | 525 | $parts = explode('/', $summaryResult['videoFrameRate']); |
| 526 | - $summaryResult['videoFrameRate'] = (float)$parts[0] / (float)$parts[1]; |
|
| 526 | + $summaryResult['videoFrameRate'] = (float) $parts[0] / (float) $parts[1]; |
|
| 527 | 527 | } |
| 528 | 528 | $result = $summaryResult; |
| 529 | 529 | } |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | * @return string |
| 542 | 542 | * @throws InvalidConfigException |
| 543 | 543 | */ |
| 544 | - public function getVideoFilename(Asset|string $filePath, array $videoOptions): string |
|
| 544 | + public function getVideoFilename(Asset | string $filePath, array $videoOptions): string |
|
| 545 | 545 | { |
| 546 | 546 | $settings = Transcoder::$plugin->getSettings(); |
| 547 | 547 | $videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions); |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | * @return string |
| 565 | 565 | * @throws InvalidConfigException |
| 566 | 566 | */ |
| 567 | - public function getAudioFilename(Asset|string $filePath, array $audioOptions): string |
|
| 567 | + public function getAudioFilename(Asset | string $filePath, array $audioOptions): string |
|
| 568 | 568 | { |
| 569 | 569 | $settings = Transcoder::$plugin->getSettings(); |
| 570 | 570 | $audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions); |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * @return string |
| 588 | 588 | * @throws InvalidConfigException |
| 589 | 589 | */ |
| 590 | - public function getGifFilename(Asset|string $filePath, array $gifOptions): string |
|
| 590 | + public function getGifFilename(Asset | string $filePath, array $gifOptions): string |
|
| 591 | 591 | { |
| 592 | 592 | $settings = Transcoder::$plugin->getSettings(); |
| 593 | 593 | $gifOptions = $this->coalesceOptions('defaultGifOptions', $gifOptions); |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | * @return null|false|string |
| 610 | 610 | * @throws InvalidConfigException |
| 611 | 611 | */ |
| 612 | - public function handleGetAssetThumbPath(DefineAssetThumbUrlEvent $event): null|false|string |
|
| 612 | + public function handleGetAssetThumbPath(DefineAssetThumbUrlEvent $event): null | false | string |
|
| 613 | 613 | { |
| 614 | 614 | $options = [ |
| 615 | 615 | 'width' => $event->width, |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | * @throws InvalidConfigException |
| 632 | 632 | */ |
| 633 | 633 | |
| 634 | - public function getGifUrl(Asset|string $filePath, array $gifOptions): string|false|null |
|
| 634 | + public function getGifUrl(Asset | string $filePath, array $gifOptions): string | false | null |
|
| 635 | 635 | { |
| 636 | 636 | $result = ''; |
| 637 | 637 | $settings = Transcoder::$plugin->getSettings(); |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | |
| 647 | 647 | if (!empty($filePath)) { |
| 648 | 648 | // Dest path |
| 649 | - $destVideoPath = $settings['transcoderPaths']['gif'] . $subfolder ?? $settings['transcoderPaths']['default']; |
|
| 649 | + $destVideoPath = $settings['transcoderPaths']['gif'].$subfolder ?? $settings['transcoderPaths']['default']; |
|
| 650 | 650 | $destVideoPath = App::parseEnv($destVideoPath); |
| 651 | 651 | |
| 652 | 652 | // Options |
@@ -660,9 +660,9 @@ discard block |
||
| 660 | 660 | // Build the basic command for ffmpeg |
| 661 | 661 | $ffmpegCmd = $settings['ffmpegPath'] |
| 662 | 662 | . ' -f gif' |
| 663 | - . ' -i ' . escapeshellarg($filePath) |
|
| 664 | - . ' -vcodec ' . $thisEncoder['videoCodec'] |
|
| 665 | - . ' ' . $thisEncoder['videoCodecOptions']; |
|
| 663 | + . ' -i '.escapeshellarg($filePath) |
|
| 664 | + . ' -vcodec '.$thisEncoder['videoCodec'] |
|
| 665 | + . ' '.$thisEncoder['videoCodecOptions']; |
|
| 666 | 666 | |
| 667 | 667 | |
| 668 | 668 | // Create the directory if it isn't there already |
@@ -677,16 +677,16 @@ discard block |
||
| 677 | 677 | $destVideoFile = $this->getFilename($filePath, $gifOptions); |
| 678 | 678 | |
| 679 | 679 | // File to store the video encoding progress in |
| 680 | - $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress'; |
|
| 680 | + $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress'; |
|
| 681 | 681 | |
| 682 | 682 | // Assemble the destination path and final ffmpeg command |
| 683 | 683 | $destVideoPath .= $destVideoFile; |
| 684 | 684 | $ffmpegCmd .= ' ' |
| 685 | - . ' -y ' . escapeshellarg($destVideoPath) |
|
| 686 | - . ' 1> ' . $progressFile . ' 2>&1 & echo $!'; |
|
| 685 | + . ' -y '.escapeshellarg($destVideoPath) |
|
| 686 | + . ' 1> '.$progressFile.' 2>&1 & echo $!'; |
|
| 687 | 687 | |
| 688 | 688 | // Make sure there isn't a lockfile for this video already |
| 689 | - $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock'; |
|
| 689 | + $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock'; |
|
| 690 | 690 | $oldPid = @file_get_contents($lockFile); |
| 691 | 691 | if ($oldPid !== false) { |
| 692 | 692 | // See if the process is running, and empty result means the process is still running |
@@ -702,12 +702,12 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | // If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding |
| 704 | 704 | if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) { |
| 705 | - $url = $settings['transcoderUrls']['gif'] . $subfolder ?? $settings['transcoderUrls']['default']; |
|
| 706 | - $result = App::parseEnv($url) . $destVideoFile; |
|
| 705 | + $url = $settings['transcoderUrls']['gif'].$subfolder ?? $settings['transcoderUrls']['default']; |
|
| 706 | + $result = App::parseEnv($url).$destVideoFile; |
|
| 707 | 707 | } else { |
| 708 | 708 | // Kick off the transcoding |
| 709 | 709 | $pid = $this->executeShellCommand($ffmpegCmd); |
| 710 | - Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__); |
|
| 710 | + Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__); |
|
| 711 | 711 | |
| 712 | 712 | // Create a lockfile in tmp |
| 713 | 713 | file_put_contents($lockFile, $pid); |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | * @return string |
| 727 | 727 | * @throws InvalidConfigException |
| 728 | 728 | */ |
| 729 | - protected function getFilename(Asset|string $filePath, array $options): string |
|
| 729 | + protected function getFilename(Asset | string $filePath, array $options): string |
|
| 730 | 730 | { |
| 731 | 731 | $settings = Transcoder::$plugin->getSettings(); |
| 732 | 732 | $filePath = $this->getAssetPath($filePath); |
@@ -749,16 +749,16 @@ discard block |
||
| 749 | 749 | $suffix = self::SUFFIX_MAP[$key]; |
| 750 | 750 | } |
| 751 | 751 | if (is_bool($value)) { |
| 752 | - $value = $value ? $key : 'no' . $key; |
|
| 752 | + $value = $value ? $key : 'no'.$key; |
|
| 753 | 753 | } |
| 754 | 754 | if (!in_array($key, self::EXCLUDE_PARAMS, true)) { |
| 755 | - $fileName .= '_' . $value . $suffix; |
|
| 755 | + $fileName .= '_'.$value.$suffix; |
|
| 756 | 756 | } |
| 757 | 757 | } |
| 758 | 758 | } |
| 759 | 759 | // See if we should use a hash instead |
| 760 | 760 | if ($settings['useHashedNames']) { |
| 761 | - $fileName = $pathParts['filename'] . md5($fileName); |
|
| 761 | + $fileName = $pathParts['filename'].md5($fileName); |
|
| 762 | 762 | } |
| 763 | 763 | $fileName .= $options['fileSuffix']; |
| 764 | 764 | |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | * @return string |
| 774 | 774 | * @throws InvalidConfigException |
| 775 | 775 | */ |
| 776 | - protected function getAssetPath(Asset|string $filePath): string |
|
| 776 | + protected function getAssetPath(Asset | string $filePath): string |
|
| 777 | 777 | { |
| 778 | 778 | // If we're passed an Asset, extract the path from it |
| 779 | 779 | if (($filePath instanceof Asset)) { |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | } |
| 800 | 800 | $folderPath .= '' === $folderPath ? '' : DIRECTORY_SEPARATOR; |
| 801 | 801 | |
| 802 | - $filePath = $sourcePath . $folderPath . $asset->filename; |
|
| 802 | + $filePath = $sourcePath.$folderPath.$asset->filename; |
|
| 803 | 803 | } else { |
| 804 | 804 | // Otherwise, get a URL |
| 805 | 805 | $filePath = $asset->getUrl() ?? ''; |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - $filePath = (string)App::parseEnv($filePath); |
|
| 810 | + $filePath = (string) App::parseEnv($filePath); |
|
| 811 | 811 | |
| 812 | 812 | // Make sure that $filePath is either an existing file, or a valid URL |
| 813 | 813 | if (!file_exists($filePath)) { |
@@ -841,16 +841,16 @@ discard block |
||
| 841 | 841 | case 'letterbox': |
| 842 | 842 | $letterboxColor = ''; |
| 843 | 843 | if (!empty($options['letterboxColor'])) { |
| 844 | - $letterboxColor = ':color=' . $options['letterboxColor']; |
|
| 844 | + $letterboxColor = ':color='.$options['letterboxColor']; |
|
| 845 | 845 | } |
| 846 | 846 | $aspectRatio = ':force_original_aspect_ratio=decrease' |
| 847 | - . ',pad=' . $options['width'] . ':' . $options['height'] . ':(ow-iw)/2:(oh-ih)/2' |
|
| 847 | + . ',pad='.$options['width'].':'.$options['height'].':(ow-iw)/2:(oh-ih)/2' |
|
| 848 | 848 | . $letterboxColor; |
| 849 | 849 | break; |
| 850 | 850 | // Scale to the appropriate aspect ratio, cropping |
| 851 | 851 | case 'crop': |
| 852 | 852 | $aspectRatio = ':force_original_aspect_ratio=increase' |
| 853 | - . ',crop=' . $options['width'] . ':' . $options['height']; |
|
| 853 | + . ',crop='.$options['width'].':'.$options['height']; |
|
| 854 | 854 | break; |
| 855 | 855 | // No aspect ratio scaling at all |
| 856 | 856 | default: |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | $sharpen = ',unsharp=5:5:1.0:5:5:0.0'; |
| 865 | 865 | } |
| 866 | 866 | $ffmpegCmd .= ' -vf "scale=' |
| 867 | - . $options['width'] . ':' . $options['height'] |
|
| 867 | + . $options['width'].':'.$options['height'] |
|
| 868 | 868 | . $aspectRatio |
| 869 | 869 | . $sharpen |
| 870 | 870 | . '"'; |