Skip to content

Commit 5abc55a

Browse files
committed
Merge branch 'release/1.1.1' into v1
2 parents 5490768 + a860ae1 commit 5abc55a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Transcoder Changelog
22

3+
## 1.1.1 - 2018.02.03
4+
### Changed
5+
* Only generate a thumbnail when we're actually asked to do so via `$generate1`
6+
37
## 1.1.0 - 2018.02.02
48
### Added
59
* Transcoder now supports the transcoding of remote video & audio files

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft-transcoder",
33
"description": "Transcode video & audio files to various formats, and provide video thumbnails",
44
"type": "craft-plugin",
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"keywords": [
77
"craft",
88
"cms",

src/services/Transcode.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ public function getVideoUrl($filePath, $videoOptions): string
200200
/**
201201
* Returns a URL to a video thumbnail
202202
*
203-
* @param $filePath string path to the original video or an Asset
204-
* @param $thumbnailOptions array of options for the thumbnail
203+
* @param string $filePath path to the original video or an Asset
204+
* @param array $thumbnailOptions of options for the thumbnail
205+
* @param bool $generate whether the thumbnail should be
206+
* generated if it doesn't exists
205207
*
206-
* @return string URL of the video thumbnail
208+
* @return string URL of the video thumbnail
207209
*/
208-
public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
210+
public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = true): string
209211
{
210212

211213
$result = "";
@@ -248,8 +250,14 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
248250

249251
// If the thumbnail file already exists, return it. Otherwise, generate it and return it
250252
if (!file_exists($destThumbnailPath)) {
251-
$shellOutput = $this->executeShellCommand($ffmpegCmd);
252-
Craft::info($ffmpegCmd, __METHOD__);
253+
if ($generate) {
254+
$shellOutput = $this->executeShellCommand($ffmpegCmd);
255+
Craft::info($ffmpegCmd, __METHOD__);
256+
} else {
257+
Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__);
258+
// The file doesn't exist, and we weren't asked to generate it
259+
return '';
260+
}
253261
}
254262
$result = Craft::getAlias($settings['transcoderUrl']) . $destThumbnailFile;
255263
}
@@ -481,10 +489,10 @@ public function getAudioFilename($filePath, $audioOptions): string
481489
public function handleGetAssetThumbUrl(GetAssetThumbUrlEvent $event)
482490
{
483491
$options = [
484-
"width" => $event->width,
492+
"width" => $event->width,
485493
"height" => $event->height,
486494
];
487-
$thumbUrl = $this->getVideoThumbnailUrl($event->asset, $options);
495+
$thumbUrl = $this->getVideoThumbnailUrl($event->asset, $options, $event->generate);
488496

489497
return empty($thumbUrl) ? null : $thumbUrl;
490498
}

0 commit comments

Comments
 (0)