Skip to content

Commit c05b4d2

Browse files
v4.0.01
Add `toArray()` to `quicktime` for `AudioMetadata`
1 parent 2c83129 commit c05b4d2

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kiwilan/php-audio",
33
"description": "PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.",
4-
"version": "4.0.0",
4+
"version": "4.0.01",
55
"keywords": [
66
"audio",
77
"php",

src/Id3/Reader/Id3AudioQuicktime.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,35 @@ public function getMdat(): ?Id3AudioQuicktimeItem
171171
{
172172
return $this->mdat;
173173
}
174+
175+
public function getChapter(int $index): ?Id3AudioQuicktimeChapter
176+
{
177+
return $this->chapters[$index] ?? null;
178+
}
179+
180+
public function toArray(): array
181+
{
182+
$chapters = [];
183+
foreach ($this->chapters as $chapter) {
184+
$chapters[] = $chapter->toArray();
185+
}
186+
187+
return [
188+
'hinting' => $this->hinting,
189+
'controller' => $this->controller,
190+
'ftyp' => $this->ftyp?->toArray(),
191+
'timestamps_unix' => $this->timestamps_unix,
192+
'time_scale' => $this->time_scale,
193+
'display_scale' => $this->display_scale,
194+
'video' => $this->video,
195+
'audio' => $this->audio,
196+
'stts_framecount' => $this->stts_framecount,
197+
'comments' => $this->comments,
198+
'chapters' => $chapters,
199+
'free' => $this->free?->toArray(),
200+
'wide' => $this->wide?->toArray(),
201+
'mdat' => $this->mdat?->toArray(),
202+
'encoding' => $this->encoding,
203+
];
204+
}
174205
}

src/Id3/Reader/Id3AudioQuicktimeChapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ public function getTitle(): ?string
3535
{
3636
return $this->title;
3737
}
38+
39+
public function toArray(): array
40+
{
41+
return [
42+
'timestamp' => $this->timestamp,
43+
'title' => $this->title,
44+
];
45+
}
3846
}

src/Id3/Reader/Id3AudioQuicktimeItem.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,17 @@ public function getFourcc(): ?string
7575
{
7676
return $this->fourcc;
7777
}
78+
79+
public function toArray(): array
80+
{
81+
return [
82+
'hierarchy' => $this->hierarchy,
83+
'name' => $this->name,
84+
'size' => $this->size,
85+
'offset' => $this->offset,
86+
'signature' => $this->signature,
87+
'unknown_1' => $this->unknown_1,
88+
'fourcc' => $this->fourcc,
89+
];
90+
}
7891
}

src/Models/AudioMetadata.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public function toArray(): array
293293
'data_format' => $this->data_format,
294294
'encoding' => $this->encoding,
295295
'mime_type' => $this->mime_type,
296+
'quicktime' => $this->quicktime?->toArray(),
297+
'warning' => $this->warning,
296298
'duration_seconds' => $this->duration_seconds,
297299
'bitrate' => $this->bitrate,
298300
'bitrate_mode' => $this->bitrate_mode,

tests/AudioMetadataTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,6 @@
139139
expect($quicktime->getWide())->toBeInstanceOf(Id3AudioQuicktimeItem::class);
140140
expect($quicktime->getMdat())->toBeInstanceOf(Id3AudioQuicktimeItem::class);
141141
expect($quicktime->getEncoding())->toBeString();
142+
143+
expect($quicktime->toArray())->toBeArray();
142144
});

tests/AudiobookTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
expect($quicktime->getChapters())->toBeArray();
149149
expect($quicktime->getChapters())->each(fn (Pest\Expectation $chapter) => expect($chapter->value)->toBeInstanceOf(Id3AudioQuicktimeChapter::class));
150150

151-
$first = $quicktime->getChapters()[0];
151+
$first = $quicktime->getChapter(0);
152152
expect($first->getTimestamp())->toBe(0);
153153
expect($first->getTitle())->toBe('Chapter 01');
154154
});

0 commit comments

Comments
 (0)