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
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
use Illuminate\Support\Arr;
|
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
|
|
|
{
|
|
|
|
// ID3 Object
|
|
|
|
private $_o = NULL;
|
2020-01-05 07:02:32 +00:00
|
|
|
protected $dates = ['created','created_manual'];
|
2016-07-04 06:00:33 +00:00
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
public function getIDLinkAttribute()
|
|
|
|
{
|
2020-01-04 13:28:00 +00:00
|
|
|
return $this->HTMLLinkAttribute($this->id,'v/info');
|
2019-12-15 12:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHtmlImageURL()
|
|
|
|
{
|
|
|
|
return sprintf('<video width="320" height="240" src="%s" controls></video>',url('/v/view/'.$this->id));
|
|
|
|
}
|
2016-07-04 06:00:33 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-11 12:59:53 +00:00
|
|
|
* Return an GetID3 object or attribute
|
2016-07-04 06:00:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function o($attr=NULL)
|
|
|
|
{
|
|
|
|
if (! $this->filename OR ! file_exists($this->file_path()) OR ! is_readable($this->file_path()))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (is_null($this->_o))
|
|
|
|
{
|
2019-12-21 11:57:34 +00:00
|
|
|
/*
|
|
|
|
* @todo There is a bug with getID3, where the second iteration yields different results
|
|
|
|
* this is problematic when video:scanall is run from a queue and there is more than 1 job.
|
|
|
|
* It also appears that only 1.9.18 gets date/gps data, a later version doesnt get gps data.
|
|
|
|
*/
|
2016-07-04 06:00:33 +00:00
|
|
|
$this->_o = new \getID3;
|
|
|
|
$this->_o->analyze($this->file_path());
|
|
|
|
$this->_o->getHashdata('sha1');
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_null($attr) ? $this->_o : (array_key_exists($attr,$this->_o->info) ? $this->_o->info[$attr] : NULL);
|
|
|
|
}
|
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
public function property(string $property)
|
2016-07-04 06:00:33 +00:00
|
|
|
{
|
|
|
|
if (! $this->o())
|
|
|
|
return NULL;
|
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
switch ($property) {
|
2016-07-04 06:00:33 +00:00
|
|
|
case 'creationdate':
|
|
|
|
// Try creation_Data
|
2019-12-15 12:34:42 +00:00
|
|
|
$x = Arr::get($this->_o->info,'quicktime.comments.creation_date.0');
|
2016-07-04 06:00:33 +00:00
|
|
|
|
|
|
|
// Try creation_Data
|
|
|
|
if (is_null($x))
|
2019-12-15 12:34:42 +00:00
|
|
|
$x = Arr::get($this->_o->info,'quicktime.comments.creationdate.0');
|
2016-07-04 06:00:33 +00:00
|
|
|
|
|
|
|
return $x;
|
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
case 'make': return Arr::get($this->_o->info,'quicktime.comments.make.0');
|
|
|
|
case 'model': return Arr::get($this->_o->info,'quicktime.comments.model.0');
|
|
|
|
case 'software': return Arr::get($this->_o->info,'quicktime.comments.software.0');
|
|
|
|
case 'signature': return Arr::get($this->_o->info,'sha1_data');
|
2016-07-04 06:00:33 +00:00
|
|
|
#case 'height': return $this->subatomsearch('quicktime.moov.subatoms',['trak','tkhd'],'height'); break;
|
|
|
|
#case 'width': return $this->subatomsearch('quicktime.moov.subatoms',['trak','tkhd'],'width'); break;
|
2019-12-15 12:34:42 +00:00
|
|
|
case 'height': return Arr::get($this->_o->info,'video.resolution_y');
|
|
|
|
case 'width': return Arr::get($this->_o->info,'video.resolution_x');
|
|
|
|
case 'length': return Arr::get($this->_o->info,'playtime_seconds');
|
|
|
|
case 'type': return Arr::get($this->_o->info,'video.dataformat');
|
|
|
|
case 'codec': return Arr::get($this->_o->info,'audio.codec');
|
|
|
|
case 'audiochannels': return Arr::get($this->_o->info,'audio.channels');
|
|
|
|
case 'samplerate': return Arr::get($this->_o->info,'audio.sample_rate');
|
|
|
|
case 'channelmode': return Arr::get($this->_o->info,'audio.channelmode');
|
|
|
|
case 'gps_lat': return Arr::get($this->_o->info,'quicktime.comments.gps_latitude.0');
|
|
|
|
case 'gps_lon': return Arr::get($this->_o->info,'quicktime.comments.gps_longitude.0');
|
|
|
|
case 'gps_altitude': return Arr::get($this->_o->info,'quicktime.comments.gps_altitude.0');
|
|
|
|
case 'identifier':
|
|
|
|
if ($x=Arr::get($this->_o->info,'quicktime.comments')) {
|
|
|
|
return Arr::get(Arr::flatten(Arr::only($x,'content.identifier')),0);
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-12-15 12:34:42 +00:00
|
|
|
|
2016-07-04 06:00:33 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
public function properties()
|
|
|
|
{
|
|
|
|
return $this->o() ? $this->_o->info : [];
|
|
|
|
}
|
|
|
|
|
2016-07-04 06:00:33 +00:00
|
|
|
/**
|
2018-01-11 12:59:53 +00:00
|
|
|
* Navigate through ID3 data to find the value.
|
2016-07-04 06:00:33 +00:00
|
|
|
*/
|
|
|
|
private function subatomsearch($atom,array $paths,$key,array $data=[]) {
|
2019-12-15 12:34:42 +00:00
|
|
|
if (! $data AND is_null($data = Arr::get($this->_o->info,$atom))) {
|
2016-07-04 06:00:33 +00:00
|
|
|
// Didnt find it.
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
foreach ($paths as $path) {
|
2016-07-04 06:00:33 +00:00
|
|
|
$found = FALSE;
|
2019-12-15 12:34:42 +00:00
|
|
|
|
|
|
|
foreach ($data as $array) {
|
|
|
|
if ($array['name'] === $path) {
|
2016-07-04 06:00:33 +00:00
|
|
|
$found = TRUE;
|
2019-12-15 12:34:42 +00:00
|
|
|
|
2016-07-04 06:00:33 +00:00
|
|
|
if ($path != last($paths))
|
|
|
|
$data = $array['subatoms'];
|
|
|
|
else
|
|
|
|
$data = $array;
|
2019-12-15 12:34:42 +00:00
|
|
|
|
2016-07-04 06:00:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isset($data[$key]) ? $data[$key] : NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-05 07:02:32 +00:00
|
|
|
public function setDateCreated()
|
|
|
|
{
|
|
|
|
$this->created = strtotime($this->property('creationdate'));
|
|
|
|
}
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
public function setLocation()
|
2016-07-04 06:00:33 +00:00
|
|
|
{
|
2018-01-11 12:59:53 +00:00
|
|
|
$this->gps_lat = $this->property('gps_lat');
|
|
|
|
$this->gps_lon = $this->property('gps_lon');
|
|
|
|
$this->gps_altitude = $this->property('gps_altitude');
|
2016-07-04 06:00:33 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
public function setMakeModel()
|
|
|
|
{
|
2019-12-27 02:32:42 +00:00
|
|
|
$ma = NULL;
|
|
|
|
|
|
|
|
if ($this->property('make'))
|
|
|
|
$ma = Make::firstOrCreate([
|
|
|
|
'name'=>$this->property('make'),
|
|
|
|
]);
|
2019-12-26 04:56:31 +00:00
|
|
|
|
|
|
|
$mo = Model::firstOrCreate([
|
|
|
|
'name'=>$this->property('model') ?: NULL,
|
2019-12-27 02:32:42 +00:00
|
|
|
'make_id'=>$ma ? $ma->id : NULL,
|
2019-12-26 04:56:31 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$so = Software::firstOrCreate([
|
|
|
|
'name'=>$this->property('software') ?: NULL,
|
|
|
|
'model_id'=>$mo->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->software_id = $so->id;
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
$this->type = $this->property('type');
|
2019-12-21 11:57:34 +00:00
|
|
|
$this->length = round($this->property('length'),2);
|
2018-01-11 12:59:53 +00:00
|
|
|
$this->codec = $this->property('codec');
|
|
|
|
$this->audiochannels = $this->property('audiochannels');
|
|
|
|
$this->channelmode = $this->property('channelmode');
|
|
|
|
$this->samplerate = $this->property('samplerate');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSignature()
|
|
|
|
{
|
2020-01-04 13:28:00 +00:00
|
|
|
parent::setSignature();
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
$this->identifier = $this->property('identifier');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubSecTime()
|
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setThumbnail()
|
2016-07-04 06:00:33 +00:00
|
|
|
{
|
2018-01-11 12:59:53 +00:00
|
|
|
// NOOP
|
2016-07-04 06:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the extension of the image
|
|
|
|
*/
|
|
|
|
public function type($mime=FALSE)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|