Skip to content

Commit 764431a

Browse files
committed
### Added
- Added `craft/cms` as a composer dependency - Added code inspection typehinting for the plugin & services ### Changed - Code refactor/cleanup
1 parent 17d13e6 commit 764431a

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

CHANGELOG.md

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

3+
## 1.0.4 - 2017.03.12
4+
### Added
5+
- Added `craft/cms` as a composer dependency
6+
- Added code inspection typehinting for the plugin & services
7+
8+
### Changed
9+
- Code refactor/cleanup
10+
311
## 1.0.3 - 2017.03.11
412
### Added
513
- Use `php-shellcommand` to allow for proper execution on Windows & Unix servers

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft3-transcoder",
33
"description": "Transcode video & audio files to various formats, and provide video thumbnails",
44
"type": "craft-plugin",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"keywords": [
77
"craft",
88
"cms",
@@ -22,6 +22,7 @@
2222
}
2323
],
2424
"require": {
25+
"craftcms/cms": "~3.0.0-beta.1",
2526
"mikehaertl/php-shellcommand": "~1.2"
2627
},
2728
"autoload": {

src/Transcoder.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,33 @@
1010

1111
namespace nystudio107\transcoder;
1212

13+
use nystudio107\transcoder\services\Transcoder as TranscoderService;
1314
use nystudio107\transcoder\variables\TranscoderVariable;
1415

1516
use Craft;
1617
use craft\base\Plugin;
1718
use craft\events\RegisterCacheOptionsEvent;
1819
use craft\utilities\ClearCaches;
20+
use craft\console\Application as ConsoleApplication;
21+
1922
use yii\base\Event;
2023

2124
/**
25+
* Class Transcoder
26+
*
2227
* @author nystudio107
2328
* @package Transcoder
2429
* @since 1.0.0
30+
*
31+
* @property TranscoderService transcoder
2532
*/
2633
class Transcoder extends Plugin
2734
{
2835
// Static Properties
2936
// =========================================================================
3037

3138
/**
32-
* @var static
39+
* @var Transcoder
3340
*/
3441
public static $plugin;
3542

@@ -57,7 +64,7 @@ function (RegisterCacheOptionsEvent $event) {
5764
$event->options[] = [
5865
'key' => 'transcoder',
5966
'label' => Craft::t('transcoder', 'Transcoder caches'),
60-
'action' => Craft::$app->config->get("transcoderPath", "transcoder")
67+
'action' => Craft::$app->config->get('transcoderPath', 'transcoder')
6168
];
6269
}
6370
);
@@ -72,5 +79,4 @@ public function defineTemplateComponent()
7279
{
7380
return TranscoderVariable::class;
7481
}
75-
7682
}

src/services/Transcoder.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class Transcoder extends Component
7777
* Returns a URL to the transcoded video or "" if it doesn't exist (at which
7878
* time it will create it).
7979
*
80-
* @param $filePath path to the original video -OR- an Asset
81-
* @param $videoOptions array of options for the video
80+
* @param $filePath string path to the original video -OR- an Asset
81+
* @param $videoOptions array of options for the video
8282
*
8383
* @return string URL of the transcoded video or ""
8484
*/
@@ -180,7 +180,7 @@ public function getVideoUrl($filePath, $videoOptions): string
180180
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destVideoFile;
181181
} else {
182182
// Kick off the transcoding
183-
$pid = $this->_executeShellCommand($ffmpegCmd);
183+
$pid = $this->executeShellCommand($ffmpegCmd);
184184
Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
185185

186186
// Create a lockfile in tmp
@@ -194,8 +194,8 @@ public function getVideoUrl($filePath, $videoOptions): string
194194
/**
195195
* Returns a URL to a video thumbnail
196196
*
197-
* @param $filePath path to the original video or an Asset
198-
* @param $thumbnailOptions array of options for the thumbnail
197+
* @param $filePath string path to the original video or an Asset
198+
* @param $thumbnailOptions array of options for the thumbnail
199199
*
200200
* @return string URL of the video thumbnail
201201
*/
@@ -241,7 +241,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
241241

242242
// If the thumbnail file already exists, return it. Otherwise, generate it and return it
243243
if (!file_exists($destThumbnailPath)) {
244-
$shellOutput = $this->_executeShellCommand($ffmpegCmd);
244+
$shellOutput = $this->executeShellCommand($ffmpegCmd);
245245
Craft::info($ffmpegCmd, __METHOD__);
246246
}
247247
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destThumbnailFile;
@@ -334,7 +334,7 @@ public function getAudioUrl($filePath, $audioOptions): string
334334
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destAudioFile;
335335
} else {
336336
// Kick off the transcoding
337-
$pid = $this->_executeShellCommand($ffmpegCmd);
337+
$pid = $this->executeShellCommand($ffmpegCmd);
338338
Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
339339

340340
// Create a lockfile in tmp
@@ -366,7 +366,7 @@ public function getFileInfo($filePath, $summary = false): array
366366
.' '.$ffprobeOptions
367367
.' '.escapeshellarg($filePath);
368368

369-
$shellOutput = $this->_executeShellCommand($ffprobeCmd);
369+
$shellOutput = $this->executeShellCommand($ffprobeCmd);
370370
Craft::info($ffprobeCmd, __METHOD__);
371371
$result = json_decode($shellOutput, true);
372372
Craft::info(print_r($result, true), __METHOD__);
@@ -393,7 +393,6 @@ public function getFileInfo($filePath, $summary = false): array
393393
$summaryResult[$settingValue] = $stream[$settingKey];
394394
}
395395
}
396-
397396
}
398397
break;
399398
// Unknown info
@@ -546,6 +545,7 @@ protected function addScalingFfmpegArgs($options, $ffmpegCmd): string
546545
{
547546
if (!empty($options['width']) && !empty($options['height'])) {
548547
// Handle "none", "crop", and "letterbox" aspectRatios
548+
$aspectRatio = "";
549549
if (!empty($options['aspectRatio'])) {
550550
switch ($options['aspectRatio']) {
551551
// Scale to the appropriate aspect ratio, padding
@@ -603,7 +603,7 @@ protected function coalesceOptions($defaultName, $options): array
603603
return $options;
604604
}
605605

606-
// Private Methods
606+
// Protected Methods
607607
// =========================================================================
608608

609609
/**
@@ -613,7 +613,7 @@ protected function coalesceOptions($defaultName, $options): array
613613
*
614614
* @return string
615615
*/
616-
private function _executeShellCommand(string $command): string
616+
protected function executeShellCommand(string $command): string
617617
{
618618
// Create the shell command
619619
$shellCommand = new ShellCommand();

src/variables/TranscoderVariable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function getAudioUrl($filePath, $audioOptions): string
7575
/**
7676
* Extract information from a video/audio file
7777
*
78-
* @param $filePath
78+
* @param $filePath
79+
* @param bool $summary
7980
*
8081
* @return array
8182
*/

0 commit comments

Comments
 (0)