Skip to content

Commit

Permalink
v4.0.01
Browse files Browse the repository at this point in the history
Add `toArray()` to `quicktime` for `AudioMetadata`
  • Loading branch information
ewilan-riviere committed Oct 3, 2024
1 parent 2c83129 commit c05b4d2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 31 additions & 0 deletions src/Id3/Reader/Id3AudioQuicktime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
8 changes: 8 additions & 0 deletions src/Id3/Reader/Id3AudioQuicktimeChapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public function getTitle(): ?string
{
return $this->title;
}

public function toArray(): array
{
return [
'timestamp' => $this->timestamp,
'title' => $this->title,
];
}
}
13 changes: 13 additions & 0 deletions src/Id3/Reader/Id3AudioQuicktimeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
2 changes: 2 additions & 0 deletions src/Models/AudioMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/AudioMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@
expect($quicktime->getWide())->toBeInstanceOf(Id3AudioQuicktimeItem::class);
expect($quicktime->getMdat())->toBeInstanceOf(Id3AudioQuicktimeItem::class);
expect($quicktime->getEncoding())->toBeString();

expect($quicktime->toArray())->toBeArray();
});
2 changes: 1 addition & 1 deletion tests/AudiobookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit c05b4d2

Please sign in to comment.