2016-07-04 06:00:33 +00:00
|
|
|
<?php
|
|
|
|
|
2019-11-08 12:51:47 +00:00
|
|
|
namespace App\Models;
|
2016-07-04 06:00:33 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
use App\Media\{Base,Factory};
|
2016-07-04 06:00:33 +00:00
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
class Video extends Abstracted\Catalog
|
2016-07-04 06:00:33 +00:00
|
|
|
{
|
2024-09-16 13:17:51 +00:00
|
|
|
public const config = 'video';
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'created'=>'datetime:Y-m-d H:i:s',
|
|
|
|
];
|
|
|
|
|
|
|
|
// Media Object
|
|
|
|
private ?Base $_o;
|
|
|
|
protected array $init = [
|
|
|
|
'creation_date',
|
|
|
|
'gps',
|
|
|
|
'heightwidth',
|
|
|
|
'signature',
|
|
|
|
'software',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __get($key): mixed
|
2018-01-11 12:59:53 +00:00
|
|
|
{
|
2024-09-16 13:17:51 +00:00
|
|
|
if ($key === 'o') {
|
|
|
|
if (isset($this->_o))
|
|
|
|
return $this->_o;
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
if ((! file_exists($this->file_name(FALSE))) || (! is_readable($this->file_name(FALSE))))
|
|
|
|
return $this->_o = NULL;
|
2019-12-15 12:34:42 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
if (! isset($this->_o)) {
|
|
|
|
$this->_o = Factory::create($this->file_name(FALSE));
|
2019-12-15 12:34:42 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
return $this->_o;
|
2016-07-04 06:00:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
return parent::__get($key);
|
2016-07-04 06:00:33 +00:00
|
|
|
}
|
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
/* METHODS */
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
public function custom_init()
|
2018-01-11 12:59:53 +00:00
|
|
|
{
|
2024-09-16 13:17:51 +00:00
|
|
|
$this->audio_channels = $this->getObjectOriginal('audio_channels');
|
|
|
|
$this->audio_codec = $this->getObjectOriginal('audio_codec');
|
|
|
|
$this->audio_samplerate = $this->getObjectOriginal('audio_samplerate');
|
|
|
|
$this->gps_altitude = $this->getObjectOriginal('gps_altitude');
|
|
|
|
$this->length = round($this->getObjectOriginal('length'),2);
|
|
|
|
$this->type = $this->getObjectOriginal('type');
|
|
|
|
$this->video_codec = $this->getObjectOriginal('video_codec');
|
|
|
|
$this->video_framerate = $this->getObjectOriginal('video_framerate');
|
|
|
|
|
|
|
|
/*
|
|
|
|
$x = new \getID3;
|
|
|
|
$x->analyze($this->file_name(FALSE));
|
2024-09-18 08:16:31 +00:00
|
|
|
dump(['id3'=>$x,'me'=>$this]);
|
2024-09-16 13:17:51 +00:00
|
|
|
*/
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
public function getObjectOriginal(string $property): mixed
|
2018-01-11 12:59:53 +00:00
|
|
|
{
|
2024-09-16 13:17:51 +00:00
|
|
|
switch ($property) {
|
|
|
|
case 'file_signature':
|
|
|
|
return md5_file($this->file_name(FALSE));
|
|
|
|
|
|
|
|
case 'length':
|
|
|
|
return $this->o?->duration;
|
|
|
|
|
|
|
|
case 'audio_channels':
|
|
|
|
case 'audio_codec':
|
|
|
|
case 'audio_samplerate':
|
|
|
|
case 'creation_date':
|
|
|
|
case 'gps_altitude':
|
|
|
|
case 'gps_lat':
|
|
|
|
case 'gps_lon':
|
|
|
|
case 'height':
|
|
|
|
case 'make':
|
|
|
|
case 'model':
|
|
|
|
case 'signature':
|
|
|
|
case 'software':
|
|
|
|
case 'type':
|
|
|
|
case 'width':
|
|
|
|
case 'video_codec':
|
|
|
|
case 'video_framerate':
|
|
|
|
return $this->o?->{$property};
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2024-09-16 13:17:51 +00:00
|
|
|
default:
|
|
|
|
throw new \Exception('To implement: '.$property);
|
|
|
|
}
|
2016-07-04 06:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-09-16 13:17:51 +00:00
|
|
|
* Return the extension of the video
|
2016-07-04 06:00:33 +00:00
|
|
|
*/
|
2024-09-16 13:17:51 +00:00
|
|
|
public function type($mime=FALSE): string
|
2016-07-04 06:00:33 +00:00
|
|
|
{
|
|
|
|
return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION));
|
|
|
|
}
|
2019-11-08 12:51:47 +00:00
|
|
|
}
|