Skip to content

Commit 5983a37

Browse files
committed
Merge branch 'release/1.1.2' into v1
2 parents 5abc55a + 070fa70 commit 5983a37

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

CHANGELOG.md

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

3+
## 1.1.2 - 2018.02.06
4+
### Changed
5+
* Switched video thumbnail generation to use `EVENT_GET_THUMB_PATH`
6+
* Transcoder now requires Craft CMS 3 RC 9 or later
7+
38
## 1.1.1 - 2018.02.03
49
### Changed
510
* Only generate a thumbnail when we're actually asked to do so via `$generate1`

composer.json

Lines changed: 2 additions & 2 deletions
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.1",
5+
"version": "1.1.2",
66
"keywords": [
77
"craft",
88
"cms",
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"require": {
25-
"craftcms/cms": "^3.0.0-RC1",
25+
"craftcms/cms": "^3.0.0-RC9",
2626
"mikehaertl/php-shellcommand": "~1.2"
2727
},
2828
"autoload": {

src/Transcoder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use craft\base\Plugin;
1919
use craft\console\Application as ConsoleApplication;
2020
use craft\elements\Asset;
21+
use craft\events\AssetThumbEvent;
2122
use craft\events\RegisterCacheOptionsEvent;
22-
use craft\events\GetAssetThumbUrlEvent;
2323
use craft\helpers\Assets as AssetsHelper;
2424
use craft\services\Assets;
2525
use craft\utilities\ClearCaches;
@@ -68,19 +68,19 @@ function (Event $event) {
6868
}
6969
);
7070

71-
// Handler: Elements::EVENT_AFTER_SAVE_ELEMENT
71+
// Handler: Assets::EVENT_GET_THUMB_PATH
7272
Event::on(
7373
Assets::class,
74-
Assets::EVENT_GET_ASSET_THUMB_URL,
75-
function (GetAssetThumbUrlEvent $event) {
74+
Assets::EVENT_GET_THUMB_PATH,
75+
function (AssetThumbEvent $event) {
7676
Craft::trace(
77-
'Assets::EVENT_GET_ASSET_THUMB_URL',
77+
'Assets::EVENT_GET_THUMB_PATH',
7878
__METHOD__
7979
);
8080
/** @var Asset $asset */
8181
$asset = $event->asset;
8282
if (AssetsHelper::getFileKindByExtension($asset->filename) == Asset::KIND_VIDEO) {
83-
$event->url = Transcoder::$plugin->transcode->handleGetAssetThumbUrl($event);
83+
$event->path = Transcoder::$plugin->transcode->handleGetAssetThumbPath($event);
8484
}
8585
}
8686
);

src/services/Transcode.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Craft;
1616
use craft\base\Component;
1717
use craft\elements\Asset;
18-
use craft\events\GetAssetThumbUrlEvent;
18+
use craft\events\AssetThumbEvent;
1919
use craft\volumes\Local;
2020

2121
use yii\base\Exception;
@@ -204,13 +204,14 @@ public function getVideoUrl($filePath, $videoOptions): string
204204
* @param array $thumbnailOptions of options for the thumbnail
205205
* @param bool $generate whether the thumbnail should be
206206
* generated if it doesn't exists
207+
* @param bool $asPath Whether we should return a path or not
207208
*
208-
* @return string URL of the video thumbnail
209+
* @return string|false|null URL or path of the video thumbnail
209210
*/
210-
public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = true): string
211+
public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = true, $asPath = false)
211212
{
212213

213-
$result = "";
214+
$result = null;
214215
$settings = Transcoder::$plugin->getSettings();
215216
$filePath = $this->getAssetPath($filePath);
216217

@@ -256,10 +257,15 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
256257
} else {
257258
Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__);
258259
// The file doesn't exist, and we weren't asked to generate it
259-
return '';
260+
return false;
260261
}
261262
}
262-
$result = Craft::getAlias($settings['transcoderUrl']) . $destThumbnailFile;
263+
// Return either a path or a URL
264+
if ($asPath) {
265+
$result = $destThumbnailPath;
266+
} else {
267+
$result = Craft::getAlias($settings['transcoderUrl']) . $destThumbnailFile;
268+
}
263269
}
264270

265271
return $result;
@@ -482,19 +488,19 @@ public function getAudioFilename($filePath, $audioOptions): string
482488
/**
483489
* Handle generated a thumbnail for the AdminCP
484490
*
485-
* @param GetAssetThumbUrlEvent $event
491+
* @param AssetThumbEvent $event
486492
*
487-
* @return null|string
493+
* @return null|false|string
488494
*/
489-
public function handleGetAssetThumbUrl(GetAssetThumbUrlEvent $event)
495+
public function handleGetAssetThumbPath(AssetThumbEvent $event)
490496
{
491497
$options = [
492498
"width" => $event->width,
493499
"height" => $event->height,
494500
];
495-
$thumbUrl = $this->getVideoThumbnailUrl($event->asset, $options, $event->generate);
501+
$thumbPath = $this->getVideoThumbnailUrl($event->asset, $options, $event->generate, true);
496502

497-
return empty($thumbUrl) ? null : $thumbUrl;
503+
return $thumbPath;
498504
}
499505

500506
// Protected Methods

0 commit comments

Comments
 (0)