@@ -81,33 +81,34 @@ class Transcode extends Component
8181 // =========================================================================
8282
8383 /**
84- * Returns a URL to the transcoded video or "" if it doesn't exist (at which
84+ * Returns a URL to the transcoded video or "" if it doesn't exist (at
85+ * which
8586 * time it will create it).
8687 *
87- * @param $filePath string path to the original video -OR- an Asset
88- * @param $videoOptions array of options for the video
89- * @param bool $generate whether the video should be encoded
88+ * @param $filePath string path to the original video -OR- an
89+ * Asset
90+ * @param $videoOptions array of options for the video
91+ * @param bool $generate whether the video should be encoded
9092 *
9193 * @return string URL of the transcoded video or ""
9294 */
9395 public function getVideoUrl ($ filePath , $ videoOptions , $ generate = true ): string
9496 {
95-
9697 $ result = '' ;
9798 $ settings = Transcoder::$ plugin ->getSettings ();
98- $ subfolder = '' ;
99-
100- // sub folder check
101- if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
102- $ subfolder = $ filePath ->folderPath ;
103- }
104-
105- // file path
99+ $ subfolder = '' ;
100+
101+ // sub folder check
102+ if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
103+ $ subfolder = $ filePath ->folderPath ;
104+ }
105+
106+ // file path
106107 $ filePath = $ this ->getAssetPath ($ filePath );
107-
108+
108109 if (!empty ($ filePath )) {
109- $ destVideoPath = $ settings ['transcoderPaths ' ]['video ' ] . $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
110- $ destVideoPath = Craft::getAlias ($ destVideoPath );
110+ $ destVideoPath = $ settings ['transcoderPaths ' ]['video ' ]. $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
111+ $ destVideoPath = Craft::getAlias ($ destVideoPath );
111112 $ videoOptions = $ this ->coalesceOptions ('defaultVideoOptions ' , $ videoOptions );
112113
113114 // Get the video encoder presets to use
@@ -198,12 +199,11 @@ public function getVideoUrl($filePath, $videoOptions, $generate = true): string
198199
199200 // If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
200201 if (file_exists ($ destVideoPath ) && (@filemtime ($ destVideoPath ) >= @filemtime ($ filePath ))) {
201- $ url = $ settings ['transcoderUrls ' ]['video ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
202+ $ url = $ settings ['transcoderUrls ' ]['video ' ]. $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
202203 $ result = Craft::getAlias ($ url ).$ destVideoFile ;
203-
204- // skip encoding
204+ // skip encoding
205205 } elseif (!$ generate ) {
206- $ result = "" ;
206+ $ result = "" ;
207207 } else {
208208 // Kick off the transcoding
209209 $ pid = $ this ->executeShellCommand ($ ffmpegCmd );
@@ -229,20 +229,20 @@ public function getVideoUrl($filePath, $videoOptions, $generate = true): string
229229 * @return string|false|null URL or path of the video thumbnail
230230 */
231231 public function getVideoThumbnailUrl ($ filePath , $ thumbnailOptions , $ generate = true , $ asPath = false )
232- {
232+ {
233233 $ result = null ;
234234 $ settings = Transcoder::$ plugin ->getSettings ();
235- $ subfolder = '' ;
236-
237- // sub folder check
238- if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
239- $ subfolder = $ filePath ->folderPath ;
240- }
241-
235+ $ subfolder = '' ;
236+
237+ // sub folder check
238+ if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
239+ $ subfolder = $ filePath ->folderPath ;
240+ }
241+
242242 $ filePath = $ this ->getAssetPath ($ filePath );
243243
244244 if (!empty ($ filePath )) {
245- $ destThumbnailPath = $ settings ['transcoderPaths ' ]['thumbnail ' ] . $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
245+ $ destThumbnailPath = $ settings ['transcoderPaths ' ]['thumbnail ' ]. $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
246246 $ destThumbnailPath = Craft::getAlias ($ destThumbnailPath );
247247
248248 $ thumbnailOptions = $ this ->coalesceOptions ('defaultThumbnailOptions ' , $ thumbnailOptions );
@@ -286,12 +286,11 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
286286 /** @noinspection PhpUnusedLocalVariableInspection */
287287 $ shellOutput = $ this ->executeShellCommand ($ ffmpegCmd );
288288 Craft::info ($ ffmpegCmd , __METHOD__ );
289-
289+
290290 // if ffmpeg fails which we can't check because the process is ran in the background
291- // dont return the future path of the image or else we can't check this in the front end
291+ // dont return the future path of the image or else we can't check this in the front end
292292
293- return false ;
294-
293+ return false ;
295294 } else {
296295 Craft::info ('Thumbnail does not exist, but not asked to generate it: ' .$ filePath , __METHOD__ );
297296
@@ -303,7 +302,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
303302 if ($ asPath ) {
304303 $ result = $ destThumbnailPath ;
305304 } else {
306- $ url = $ settings ['transcoderUrls ' ]['thumbnail ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
305+ $ url = $ settings ['transcoderUrls ' ]['thumbnail ' ]. $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
307306 $ result = Craft::getAlias ($ url ).$ destThumbnailFile ;
308307 }
309308 }
@@ -324,17 +323,17 @@ public function getAudioUrl($filePath, $audioOptions): string
324323 {
325324 $ result = '' ;
326325 $ settings = Transcoder::$ plugin ->getSettings ();
327- $ subfolder = '' ;
328-
329- // sub folder check
330- if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
331- $ subfolder = $ filePath ->folderPath ;
332- }
333-
326+ $ subfolder = '' ;
327+
328+ // sub folder check
329+ if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
330+ $ subfolder = $ filePath ->folderPath ;
331+ }
332+
334333 $ filePath = $ this ->getAssetPath ($ filePath );
335334
336335 if (!empty ($ filePath )) {
337- $ destAudioPath = $ settings ['transcoderPaths ' ]['audio ' ] . $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
336+ $ destAudioPath = $ settings ['transcoderPaths ' ]['audio ' ]. $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
338337 $ destAudioPath = Craft::getAlias ($ destAudioPath );
339338
340339 $ audioOptions = $ this ->coalesceOptions ('defaultAudioOptions ' , $ audioOptions );
@@ -404,7 +403,7 @@ public function getAudioUrl($filePath, $audioOptions): string
404403
405404 // If the audio file already exists and hasn't been modified, return it. Otherwise, start it transcoding
406405 if (file_exists ($ destAudioPath ) && (@filemtime ($ destAudioPath ) >= @filemtime ($ filePath ))) {
407- $ url = $ settings ['transcoderUrls ' ]['audio ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
406+ $ url = $ settings ['transcoderUrls ' ]['audio ' ]. $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
408407 $ result = Craft::getAlias ($ url ).$ destAudioFile ;
409408 } else {
410409 // Kick off the transcoding
@@ -580,8 +579,8 @@ public function handleGetAssetThumbPath(AssetThumbEvent $event)
580579 /**
581580 * Returns a URL to a encoded GIF file (mp4)
582581 *
583- * @param string $filePath path to the original video or an Asset
584- * @param array $gifOptions of options for the GIF file
582+ * @param string $filePath path to the original video or an Asset
583+ * @param array $gifOptions of options for the GIF file
585584 *
586585 * @return string|false|null URL or path of the GIF file
587586 */
@@ -590,18 +589,18 @@ public function getGifUrl($filePath, $gifOptions): string
590589 {
591590 $ result = '' ;
592591 $ settings = Transcoder::$ plugin ->getSettings ();
593- $ subfolder = '' ;
594-
595- // sub folder check
596- if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
597- $ subfolder = $ filePath ->folderPath ;
598- }
599-
592+ $ subfolder = '' ;
593+
594+ // sub folder check
595+ if (\is_object ($ filePath ) && ($ filePath instanceof Asset) && $ settings ['createSubfolders ' ]) {
596+ $ subfolder = $ filePath ->folderPath ;
597+ }
598+
600599 $ filePath = $ this ->getAssetPath ($ filePath );
601600
602601 if (!empty ($ filePath )) {
603602 // Dest path
604- $ destVideoPath = $ settings ['transcoderPaths ' ]['gif ' ] . $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
603+ $ destVideoPath = $ settings ['transcoderPaths ' ]['gif ' ]. $ subfolder ?? $ settings ['transcoderPaths ' ]['default ' ];
605604 $ destVideoPath = Craft::getAlias ($ destVideoPath );
606605
607606 // Options
@@ -655,7 +654,7 @@ public function getGifUrl($filePath, $gifOptions): string
655654
656655 // If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
657656 if (file_exists ($ destVideoPath ) && (@filemtime ($ destVideoPath ) >= @filemtime ($ filePath ))) {
658- $ url = $ settings ['transcoderUrls ' ]['gif ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
657+ $ url = $ settings ['transcoderUrls ' ]['gif ' ]. $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
659658 $ result = Craft::getAlias ($ url ).$ destVideoFile ;
660659 } else {
661660 // Kick off the transcoding
@@ -741,14 +740,14 @@ protected function getAssetPath($filePath): string
741740 // If it's local, get a path to the file
742741 if ($ assetVolume instanceof Local) {
743742 $ sourcePath = rtrim ($ assetVolume ->path , DIRECTORY_SEPARATOR );
744- $ sourcePath .= '' === $ sourcePath ? '' : DIRECTORY_SEPARATOR ;
743+ $ sourcePath .= '' === $ sourcePath ? '' : DIRECTORY_SEPARATOR ;
745744 $ folderPath = '' ;
746745 try {
747746 $ folderPath = rtrim ($ asset ->getFolder ()->path , DIRECTORY_SEPARATOR );
748747 } catch (InvalidConfigException $ e ) {
749748 Craft::error ($ e ->getMessage (), __METHOD__ );
750749 }
751- $ folderPath .= '' === $ folderPath ? '' : DIRECTORY_SEPARATOR ;
750+ $ folderPath .= '' === $ folderPath ? '' : DIRECTORY_SEPARATOR ;
752751
753752 $ filePath = $ sourcePath .$ folderPath .$ asset ->filename ;
754753 } else {
0 commit comments