2021-12-14 16:41:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-12-14 16:41:10 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2023-03-16 13:00:05 +00:00
|
|
|
namespace Modules\Media\Entities;
|
2021-12-14 16:41:10 +00:00
|
|
|
|
|
|
|
use CodeIgniter\Files\File;
|
|
|
|
use JamesHeinrich\GetID3\GetID3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property float $duration
|
|
|
|
* @property int $header_size
|
|
|
|
*/
|
2021-12-17 17:14:37 +00:00
|
|
|
class Audio extends BaseMedia
|
2021-12-14 16:41:10 +00:00
|
|
|
{
|
|
|
|
protected string $type = 'audio';
|
|
|
|
|
2023-08-05 10:06:49 +00:00
|
|
|
public function initFileProperties(): void
|
2021-12-14 16:41:10 +00:00
|
|
|
{
|
2023-08-05 10:06:49 +00:00
|
|
|
parent::initFileProperties();
|
2021-12-14 16:41:10 +00:00
|
|
|
|
2023-08-05 10:06:49 +00:00
|
|
|
if ($this->file_metadata !== null) {
|
2021-12-14 16:41:10 +00:00
|
|
|
$this->duration = (float) $this->file_metadata['playtime_seconds'];
|
|
|
|
$this->header_size = (int) $this->file_metadata['avdataoffset'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFile(File $file): self
|
|
|
|
{
|
|
|
|
parent::setFile($file);
|
|
|
|
|
|
|
|
$getID3 = new GetID3();
|
2023-03-16 13:00:05 +00:00
|
|
|
$audioMetadata = $getID3->analyze($file->getRealPath());
|
2021-12-14 16:41:10 +00:00
|
|
|
|
2021-12-20 17:12:12 +00:00
|
|
|
$this->attributes['file_mimetype'] = $audioMetadata['mime_type'];
|
2021-12-14 16:41:10 +00:00
|
|
|
$this->attributes['file_size'] = $audioMetadata['filesize'];
|
2021-12-21 13:42:31 +00:00
|
|
|
$this->attributes['description'] = @$audioMetadata['id3v2']['comments']['comment'][0];
|
2023-06-21 16:17:11 +00:00
|
|
|
$this->attributes['file_metadata'] = json_encode([
|
|
|
|
'playtime_seconds' => $audioMetadata['playtime_seconds'],
|
|
|
|
'avdataoffset' => $audioMetadata['avdataoffset'],
|
|
|
|
], JSON_INVALID_UTF8_SUBSTITUTE);
|
2021-12-14 16:41:10 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|