Skip to content

Commit 028842c

Browse files
Merge pull request #36 from kiwilan/develop
v4.0.01
2 parents 215be57 + c05b4d2 commit 028842c

File tree

9 files changed

+75
-19
lines changed

9 files changed

+75
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ $tag = $audio->write()
235235
236236
### Raw tags
237237

238-
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`...
238+
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`...
239239

240-
If you want to extract specific field which can be skipped by `Audio::class`, you can use `extras` property.
240+
If you want to extract specific field which can be skipped by `Audio::class`, you can use `raw_all` property.
241241

242242
```php
243243
use Kiwilan\Audio\Audio;
@@ -446,7 +446,7 @@ composer test
446446

447447
### I have a specific metadata field in my audio files, what can I do?
448448

449-
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.
449+
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.
450450

451451
```php
452452
use Kiwilan\Audio\Audio;
@@ -473,8 +473,8 @@ use Kiwilan\Audio\Audio;
473473

474474
$audio = Audio::read('path/to/audio.mp3');
475475

476-
$extras = $audio->getRawAll();
477-
var_dump($extras);
476+
$raw_all = $audio->getRawAll();
477+
var_dump($raw_all);
478478
```
479479

480480
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

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/Audio.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class Audio
1414
{
1515
/**
16-
* @param array<string, string[]> $raw_tags_all
16+
* @param array<string, string[]> $raw_all
1717
*/
1818
protected function __construct(
1919
protected string $path,
@@ -47,7 +47,7 @@ protected function __construct(
4747
protected ?string $language = null,
4848
protected ?string $lyrics = null,
4949

50-
protected array $raw_tags_all = [],
50+
protected array $raw_all = [],
5151
) {}
5252

5353
public static function read(string $path): self
@@ -411,7 +411,7 @@ public function getLyrics(): ?string
411411
*/
412412
public function getRawAll(): array
413413
{
414-
return $this->raw_tags_all;
414+
return $this->raw_all;
415415
}
416416

417417
/**
@@ -425,16 +425,16 @@ public function getRawAll(): array
425425
public function getRaw(?string $format = null): ?array
426426
{
427427
if ($format) {
428-
return $this->raw_tags_all[$format] ?? null;
428+
return $this->raw_all[$format] ?? null;
429429
}
430430

431431
$tags = match ($this->type) {
432-
AudioTypeEnum::id3 => $this->raw_tags_all['id3v2'] ?? [],
433-
AudioTypeEnum::vorbiscomment => $this->raw_tags_all['vorbiscomment'] ?? [],
434-
AudioTypeEnum::quicktime => $this->raw_tags_all['quicktime'] ?? [],
435-
AudioTypeEnum::matroska => $this->raw_tags_all['matroska'] ?? [],
436-
AudioTypeEnum::ape => $this->raw_tags_all['ape'] ?? [],
437-
AudioTypeEnum::asf => $this->raw_tags_all['asf'] ?? [],
432+
AudioTypeEnum::id3 => $this->raw_all['id3v2'] ?? [],
433+
AudioTypeEnum::vorbiscomment => $this->raw_all['vorbiscomment'] ?? [],
434+
AudioTypeEnum::quicktime => $this->raw_all['quicktime'] ?? [],
435+
AudioTypeEnum::matroska => $this->raw_all['matroska'] ?? [],
436+
AudioTypeEnum::ape => $this->raw_all['ape'] ?? [],
437+
AudioTypeEnum::asf => $this->raw_all['asf'] ?? [],
438438
default => [],
439439
};
440440

@@ -485,7 +485,7 @@ public function toArray(): array
485485
'synopsis' => $this->synopsis,
486486
'language' => $this->language,
487487
'lyrics' => $this->lyrics,
488-
'raw_tags_all' => $this->raw_tags_all,
488+
'raw_all' => $this->raw_all,
489489
];
490490
}
491491

@@ -522,7 +522,7 @@ private function parseTags(?\Kiwilan\Audio\Id3\Id3Reader $id3_reader): self
522522

523523
$raw_tags = $id3_reader->getRaw()['tags'] ?? [];
524524
foreach ($raw_tags as $name => $raw_tag) {
525-
$this->raw_tags_all[$name] = Id3Reader::cleanTags($raw_tag);
525+
$this->raw_all[$name] = Id3Reader::cleanTags($raw_tag);
526526
}
527527

528528
$core = match ($this->type) {

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)