From c05b4d2f8d8d55f40f9f9f8c31e03222e7dd27d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Thu, 3 Oct 2024 18:54:26 +0200 Subject: [PATCH] v4.0.01 Add `toArray()` to `quicktime` for `AudioMetadata` --- composer.json | 2 +- src/Id3/Reader/Id3AudioQuicktime.php | 31 +++++++++++++++++++++ src/Id3/Reader/Id3AudioQuicktimeChapter.php | 8 ++++++ src/Id3/Reader/Id3AudioQuicktimeItem.php | 13 +++++++++ src/Models/AudioMetadata.php | 2 ++ tests/AudioMetadataTest.php | 2 ++ tests/AudiobookTest.php | 2 +- 7 files changed, 58 insertions(+), 2 deletions(-) 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/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'); });