Skip to content

Commit b147233

Browse files
committed
Handle default settings better
Signed-off-by: Andrew Welch <andrew@nystudio107.com>
1 parent 570e060 commit b147233

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/services/Transcode.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function getVideoUrl($filePath, $videoOptions): string
9696
$filePath = $this->getAssetPath($filePath);
9797

9898
if (!empty($filePath)) {
99-
$destVideoPath = Craft::getAlias($settings['transcoderPaths']['video']);
99+
$destVideoPath = $settings['transcoderPaths']['video'] ?? $settings['transcoderPaths']['default'];
100+
$destVideoPath = Craft::getAlias($destVideoPath);
100101
$videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions);
101102

102103
// Get the video encoder presets to use
@@ -187,7 +188,8 @@ public function getVideoUrl($filePath, $videoOptions): string
187188

188189
// If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
189190
if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
190-
$result = Craft::getAlias($settings['transcoderUrls']['video']).$destVideoFile;
191+
$url = $settings['transcoderUrls']['video'] ?? $settings['transcoderUrls']['default'];
192+
$result = Craft::getAlias($url).$destVideoFile;
191193
} else {
192194
// Kick off the transcoding
193195
$pid = $this->executeShellCommand($ffmpegCmd);
@@ -220,7 +222,8 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
220222
$filePath = $this->getAssetPath($filePath);
221223

222224
if (!empty($filePath)) {
223-
$destThumbnailPath = Craft::getAlias($settings['transcoderPaths']['thumbnail']);
225+
$destThumbnailPath = $settings['transcoderPaths']['thumbnail'] ?? $settings['transcoderPaths']['default'];
226+
$destThumbnailPath = Craft::getAlias($destThumbnailPath);
224227

225228
$thumbnailOptions = $this->coalesceOptions('defaultThumbnailOptions', $thumbnailOptions);
226229

@@ -274,7 +277,8 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
274277
if ($asPath) {
275278
$result = $destThumbnailPath;
276279
} else {
277-
$result = Craft::getAlias($settings['transcoderUrls']['thumbnail']).$destThumbnailFile;
280+
$url = $settings['transcoderUrls']['thumbnail'] ?? $settings['transcoderUrls']['default'];
281+
$result = Craft::getAlias($url).$destThumbnailFile;
278282
}
279283
}
280284

@@ -298,7 +302,8 @@ public function getAudioUrl($filePath, $audioOptions): string
298302
$filePath = $this->getAssetPath($filePath);
299303

300304
if (!empty($filePath)) {
301-
$destAudioPath = Craft::getAlias($settings['transcoderPaths']['audio']);
305+
$destAudioPath = $settings['transcoderPaths']['audio'] ?? $settings['transcoderPaths']['default'];
306+
$destAudioPath = Craft::getAlias($destAudioPath);
302307

303308
$audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions);
304309

@@ -367,7 +372,8 @@ public function getAudioUrl($filePath, $audioOptions): string
367372

368373
// If the audio file already exists and hasn't been modified, return it. Otherwise, start it transcoding
369374
if (file_exists($destAudioPath) && (filemtime($destAudioPath) >= filemtime($filePath))) {
370-
$result = Craft::getAlias($settings['transcoderUrls']['audio']).$destAudioFile;
375+
$url = $settings['transcoderUrls']['audio'] ?? $settings['transcoderUrls']['default'];
376+
$result = Craft::getAlias($url).$destAudioFile;
371377
} else {
372378
// Kick off the transcoding
373379
$pid = $this->executeShellCommand($ffmpegCmd);
@@ -555,7 +561,8 @@ public function getGifUrl($filePath, $gifOptions): string
555561

556562
if (!empty($filePath)) {
557563
// Dest path
558-
$destVideoPath = Craft::getAlias($settings['transcoderPaths']['gif']);
564+
$destVideoPath = $settings['transcoderPaths']['gif'] ?? $settings['transcoderPaths']['default'];
565+
$destVideoPath = Craft::getAlias($destVideoPath);
559566

560567
// Options
561568
$gifOptions = $this->coalesceOptions('defaultGifOptions', $gifOptions);
@@ -608,7 +615,8 @@ public function getGifUrl($filePath, $gifOptions): string
608615

609616
// If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
610617
if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
611-
$result = Craft::getAlias($settings['transcoderUrls']['gif']).$destVideoFile;
618+
$url = $settings['transcoderUrls']['gif'] ?? $settings['transcoderUrls']['default'];
619+
$result = Craft::getAlias($url).$destVideoFile;
612620
} else {
613621
// Kick off the transcoding
614622
$pid = $this->executeShellCommand($ffmpegCmd);

0 commit comments

Comments
 (0)