Skip to content

Commit

Permalink
Merge pull request #1 from denisyilmaz/patch-1
Browse files Browse the repository at this point in the history
fix: honor subpath of volume
  • Loading branch information
riccardolardi authored Oct 13, 2024
2 parents bff6e44 + ac0fce4 commit b2be255
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/VideoDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use craft\base\Plugin;
use craft\elements\Asset;
use craft\events\ModelEvent;
use craft\helpers\FileHelper;
use yii\base\Event;
use getID3;

Expand All @@ -21,7 +22,7 @@
*/
class VideoDimensions extends Plugin
{
public string $schemaVersion = '1.0.0';
public string $schemaVersion = '1.0.1';

public static function config(): array
{
Expand Down Expand Up @@ -57,10 +58,15 @@ function (ModelEvent $event) {
// get asset file path
$assetFilePath = '';
$fsPath = Craft::getAlias($asset->getVolume()->fs->path);
$assetFilePath = $fsPath . DIRECTORY_SEPARATOR . $asset->getPath();
$subPath = Craft::getAlias($asset->getVolume()->subpath);
$assetFilePath = FileHelper::normalizePath(($fsPath . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR . $asset->getPath()));
// get video dimensions
$getID3 = new getID3;
$file = $getID3->analyze($assetFilePath);
if (isset($file['error'])) {
Craft::error('Error analyzing video file: ' . $file['error'], __METHOD__);
return;
}
$width = $file['video']['resolution_x'];
$height = $file['video']['resolution_y'];
// get asset record
Expand Down

0 comments on commit b2be255

Please sign in to comment.