Skip to content

Commit

Permalink
### Added
Browse files Browse the repository at this point in the history
- Added `craft/cms` as a composer dependency
- Added code inspection typehinting for the plugin & services

### Changed
- Code refactor/cleanup
  • Loading branch information
khalwat committed Mar 12, 2017
1 parent 17d13e6 commit 764431a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Transcoder Changelog

## 1.0.4 - 2017.03.12
### Added
- Added `craft/cms` as a composer dependency
- Added code inspection typehinting for the plugin & services

### Changed
- Code refactor/cleanup

## 1.0.3 - 2017.03.11
### Added
- Use `php-shellcommand` to allow for proper execution on Windows & Unix servers
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft3-transcoder",
"description": "Transcode video & audio files to various formats, and provide video thumbnails",
"type": "craft-plugin",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"craft",
"cms",
Expand All @@ -22,6 +22,7 @@
}
],
"require": {
"craftcms/cms": "~3.0.0-beta.1",
"mikehaertl/php-shellcommand": "~1.2"
},
"autoload": {
Expand Down
12 changes: 9 additions & 3 deletions src/Transcoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,33 @@

namespace nystudio107\transcoder;

use nystudio107\transcoder\services\Transcoder as TranscoderService;
use nystudio107\transcoder\variables\TranscoderVariable;

use Craft;
use craft\base\Plugin;
use craft\events\RegisterCacheOptionsEvent;
use craft\utilities\ClearCaches;
use craft\console\Application as ConsoleApplication;

use yii\base\Event;

/**
* Class Transcoder
*
* @author nystudio107
* @package Transcoder
* @since 1.0.0
*
* @property TranscoderService transcoder
*/
class Transcoder extends Plugin
{
// Static Properties
// =========================================================================

/**
* @var static
* @var Transcoder
*/
public static $plugin;

Expand Down Expand Up @@ -57,7 +64,7 @@ function (RegisterCacheOptionsEvent $event) {
$event->options[] = [
'key' => 'transcoder',
'label' => Craft::t('transcoder', 'Transcoder caches'),
'action' => Craft::$app->config->get("transcoderPath", "transcoder")
'action' => Craft::$app->config->get('transcoderPath', 'transcoder')
];
}
);
Expand All @@ -72,5 +79,4 @@ public function defineTemplateComponent()
{
return TranscoderVariable::class;
}

}
22 changes: 11 additions & 11 deletions src/services/Transcoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class Transcoder extends Component
* Returns a URL to the transcoded video or "" if it doesn't exist (at which
* time it will create it).
*
* @param $filePath path to the original video -OR- an Asset
* @param $videoOptions array of options for the video
* @param $filePath string path to the original video -OR- an Asset
* @param $videoOptions array of options for the video
*
* @return string URL of the transcoded video or ""
*/
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getVideoUrl($filePath, $videoOptions): string
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destVideoFile;
} else {
// Kick off the transcoding
$pid = $this->_executeShellCommand($ffmpegCmd);
$pid = $this->executeShellCommand($ffmpegCmd);
Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);

// Create a lockfile in tmp
Expand All @@ -194,8 +194,8 @@ public function getVideoUrl($filePath, $videoOptions): string
/**
* Returns a URL to a video thumbnail
*
* @param $filePath path to the original video or an Asset
* @param $thumbnailOptions array of options for the thumbnail
* @param $filePath string path to the original video or an Asset
* @param $thumbnailOptions array of options for the thumbnail
*
* @return string URL of the video thumbnail
*/
Expand Down Expand Up @@ -241,7 +241,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string

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

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

$shellOutput = $this->_executeShellCommand($ffprobeCmd);
$shellOutput = $this->executeShellCommand($ffprobeCmd);
Craft::info($ffprobeCmd, __METHOD__);
$result = json_decode($shellOutput, true);
Craft::info(print_r($result, true), __METHOD__);
Expand All @@ -393,7 +393,6 @@ public function getFileInfo($filePath, $summary = false): array
$summaryResult[$settingValue] = $stream[$settingKey];
}
}

}
break;
// Unknown info
Expand Down Expand Up @@ -546,6 +545,7 @@ protected function addScalingFfmpegArgs($options, $ffmpegCmd): string
{
if (!empty($options['width']) && !empty($options['height'])) {
// Handle "none", "crop", and "letterbox" aspectRatios
$aspectRatio = "";
if (!empty($options['aspectRatio'])) {
switch ($options['aspectRatio']) {
// Scale to the appropriate aspect ratio, padding
Expand Down Expand Up @@ -603,7 +603,7 @@ protected function coalesceOptions($defaultName, $options): array
return $options;
}

// Private Methods
// Protected Methods
// =========================================================================

/**
Expand All @@ -613,7 +613,7 @@ protected function coalesceOptions($defaultName, $options): array
*
* @return string
*/
private function _executeShellCommand(string $command): string
protected function executeShellCommand(string $command): string
{
// Create the shell command
$shellCommand = new ShellCommand();
Expand Down
3 changes: 2 additions & 1 deletion src/variables/TranscoderVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function getAudioUrl($filePath, $audioOptions): string
/**
* Extract information from a video/audio file
*
* @param $filePath
* @param $filePath
* @param bool $summary
*
* @return array
*/
Expand Down

0 comments on commit 764431a

Please sign in to comment.