diff --git a/README.md b/README.md index 0db74de..2838a35 100644 --- a/README.md +++ b/README.md @@ -235,9 +235,9 @@ $tag = $audio->write() ### Raw tags -Audio files format metadata with different methods, `JamesHeinrich/getID3` offer to check these metadatas by different methods. In `extras` property of `Audio::class`, you will find raw metadata from `JamesHeinrich/getID3` package, like `id3v2`, `id3v1`, `riff`, `asf`, `quicktime`, `matroska`, `ape`, `vorbiscomment`... +Audio files format metadata with different methods, `JamesHeinrich/getID3` offer to check these metadatas by different methods. In `raw_all` property of `Audio::class`, you will find raw metadata from `JamesHeinrich/getID3` package, like `id3v2`, `id3v1`, `riff`, `asf`, `quicktime`, `matroska`, `ape`, `vorbiscomment`... -If you want to extract specific field which can be skipped by `Audio::class`, you can use `extras` property. +If you want to extract specific field which can be skipped by `Audio::class`, you can use `raw_all` property. ```php use Kiwilan\Audio\Audio; @@ -446,7 +446,7 @@ composer test ### I have a specific metadata field in my audio files, what can I do? -In `Audio::class`, you have a property `extras` which contains all raw metadata, if `JamesHeinrich/getID3` support this field, you will find it in this property. +In `Audio::class`, you have a property `raw_all` which contains all raw metadata, if `JamesHeinrich/getID3` support this field, you will find it in this property. ```php use Kiwilan\Audio\Audio; @@ -473,8 +473,8 @@ use Kiwilan\Audio\Audio; $audio = Audio::read('path/to/audio.mp3'); -$extras = $audio->getRawAll(); -var_dump($extras); +$raw_all = $audio->getRawAll(); +var_dump($raw_all); ``` If you find metadata which are not parsed by `Audio::class`, you can create [an issue](https://github.com/kiwilan/php-audio/issues/new/choose), otherwise `JamesHeinrich/getID3` doesn't support this metadata.z diff --git a/composer.json b/composer.json index 346ddc6..3be8b8d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/php-audio", "description": "PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.", - "version": "4.0.0", + "version": "4.0.01", "keywords": [ "audio", "php", diff --git a/src/Audio.php b/src/Audio.php index b3525fe..2047ae5 100755 --- a/src/Audio.php +++ b/src/Audio.php @@ -13,7 +13,7 @@ class Audio { /** - * @param array $raw_tags_all + * @param array $raw_all */ protected function __construct( protected string $path, @@ -47,7 +47,7 @@ protected function __construct( protected ?string $language = null, protected ?string $lyrics = null, - protected array $raw_tags_all = [], + protected array $raw_all = [], ) {} public static function read(string $path): self @@ -411,7 +411,7 @@ public function getLyrics(): ?string */ public function getRawAll(): array { - return $this->raw_tags_all; + return $this->raw_all; } /** @@ -425,16 +425,16 @@ public function getRawAll(): array public function getRaw(?string $format = null): ?array { if ($format) { - return $this->raw_tags_all[$format] ?? null; + return $this->raw_all[$format] ?? null; } $tags = match ($this->type) { - AudioTypeEnum::id3 => $this->raw_tags_all['id3v2'] ?? [], - AudioTypeEnum::vorbiscomment => $this->raw_tags_all['vorbiscomment'] ?? [], - AudioTypeEnum::quicktime => $this->raw_tags_all['quicktime'] ?? [], - AudioTypeEnum::matroska => $this->raw_tags_all['matroska'] ?? [], - AudioTypeEnum::ape => $this->raw_tags_all['ape'] ?? [], - AudioTypeEnum::asf => $this->raw_tags_all['asf'] ?? [], + AudioTypeEnum::id3 => $this->raw_all['id3v2'] ?? [], + AudioTypeEnum::vorbiscomment => $this->raw_all['vorbiscomment'] ?? [], + AudioTypeEnum::quicktime => $this->raw_all['quicktime'] ?? [], + AudioTypeEnum::matroska => $this->raw_all['matroska'] ?? [], + AudioTypeEnum::ape => $this->raw_all['ape'] ?? [], + AudioTypeEnum::asf => $this->raw_all['asf'] ?? [], default => [], }; @@ -485,7 +485,7 @@ public function toArray(): array 'synopsis' => $this->synopsis, 'language' => $this->language, 'lyrics' => $this->lyrics, - 'raw_tags_all' => $this->raw_tags_all, + 'raw_all' => $this->raw_all, ]; } @@ -522,7 +522,7 @@ private function parseTags(?\Kiwilan\Audio\Id3\Id3Reader $id3_reader): self $raw_tags = $id3_reader->getRaw()['tags'] ?? []; foreach ($raw_tags as $name => $raw_tag) { - $this->raw_tags_all[$name] = Id3Reader::cleanTags($raw_tag); + $this->raw_all[$name] = Id3Reader::cleanTags($raw_tag); } $core = match ($this->type) { diff --git a/src/Id3/Reader/Id3AudioQuicktime.php b/src/Id3/Reader/Id3AudioQuicktime.php index 87ea32e..9c3d28c 100644 --- a/src/Id3/Reader/Id3AudioQuicktime.php +++ b/src/Id3/Reader/Id3AudioQuicktime.php @@ -171,4 +171,35 @@ public function getMdat(): ?Id3AudioQuicktimeItem { return $this->mdat; } + + public function getChapter(int $index): ?Id3AudioQuicktimeChapter + { + return $this->chapters[$index] ?? null; + } + + public function toArray(): array + { + $chapters = []; + foreach ($this->chapters as $chapter) { + $chapters[] = $chapter->toArray(); + } + + return [ + 'hinting' => $this->hinting, + 'controller' => $this->controller, + 'ftyp' => $this->ftyp?->toArray(), + 'timestamps_unix' => $this->timestamps_unix, + 'time_scale' => $this->time_scale, + 'display_scale' => $this->display_scale, + 'video' => $this->video, + 'audio' => $this->audio, + 'stts_framecount' => $this->stts_framecount, + 'comments' => $this->comments, + 'chapters' => $chapters, + 'free' => $this->free?->toArray(), + 'wide' => $this->wide?->toArray(), + 'mdat' => $this->mdat?->toArray(), + 'encoding' => $this->encoding, + ]; + } } diff --git a/src/Id3/Reader/Id3AudioQuicktimeChapter.php b/src/Id3/Reader/Id3AudioQuicktimeChapter.php index be6c790..65017a2 100644 --- a/src/Id3/Reader/Id3AudioQuicktimeChapter.php +++ b/src/Id3/Reader/Id3AudioQuicktimeChapter.php @@ -35,4 +35,12 @@ public function getTitle(): ?string { return $this->title; } + + public function toArray(): array + { + return [ + 'timestamp' => $this->timestamp, + 'title' => $this->title, + ]; + } } diff --git a/src/Id3/Reader/Id3AudioQuicktimeItem.php b/src/Id3/Reader/Id3AudioQuicktimeItem.php index 4980e98..dd6915e 100644 --- a/src/Id3/Reader/Id3AudioQuicktimeItem.php +++ b/src/Id3/Reader/Id3AudioQuicktimeItem.php @@ -75,4 +75,17 @@ public function getFourcc(): ?string { return $this->fourcc; } + + public function toArray(): array + { + return [ + 'hierarchy' => $this->hierarchy, + 'name' => $this->name, + 'size' => $this->size, + 'offset' => $this->offset, + 'signature' => $this->signature, + 'unknown_1' => $this->unknown_1, + 'fourcc' => $this->fourcc, + ]; + } } diff --git a/src/Models/AudioMetadata.php b/src/Models/AudioMetadata.php index 6900d6a..08ecf04 100644 --- a/src/Models/AudioMetadata.php +++ b/src/Models/AudioMetadata.php @@ -293,6 +293,8 @@ public function toArray(): array 'data_format' => $this->data_format, 'encoding' => $this->encoding, 'mime_type' => $this->mime_type, + 'quicktime' => $this->quicktime?->toArray(), + 'warning' => $this->warning, 'duration_seconds' => $this->duration_seconds, 'bitrate' => $this->bitrate, 'bitrate_mode' => $this->bitrate_mode, diff --git a/tests/AudioMetadataTest.php b/tests/AudioMetadataTest.php index 005c930..33a4163 100644 --- a/tests/AudioMetadataTest.php +++ b/tests/AudioMetadataTest.php @@ -139,4 +139,6 @@ expect($quicktime->getWide())->toBeInstanceOf(Id3AudioQuicktimeItem::class); expect($quicktime->getMdat())->toBeInstanceOf(Id3AudioQuicktimeItem::class); expect($quicktime->getEncoding())->toBeString(); + + expect($quicktime->toArray())->toBeArray(); }); diff --git a/tests/AudiobookTest.php b/tests/AudiobookTest.php index b91796a..6b1227c 100644 --- a/tests/AudiobookTest.php +++ b/tests/AudiobookTest.php @@ -148,7 +148,7 @@ expect($quicktime->getChapters())->toBeArray(); expect($quicktime->getChapters())->each(fn (Pest\Expectation $chapter) => expect($chapter->value)->toBeInstanceOf(Id3AudioQuicktimeChapter::class)); - $first = $quicktime->getChapters()[0]; + $first = $quicktime->getChapter(0); expect($first->getTimestamp())->toBe(0); expect($first->getTitle())->toBe('Chapter 01'); });