Skip to content

Commit

Permalink
Merge pull request #36 from kiwilan/develop
Browse files Browse the repository at this point in the history
v4.0.01
  • Loading branch information
ewilan-riviere authored Oct 3, 2024
2 parents 215be57 + c05b4d2 commit 028842c
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
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
24 changes: 12 additions & 12 deletions src/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Audio
{
/**
* @param array<string, string[]> $raw_tags_all
* @param array<string, string[]> $raw_all
*/
protected function __construct(
protected string $path,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -411,7 +411,7 @@ public function getLyrics(): ?string
*/
public function getRawAll(): array
{
return $this->raw_tags_all;
return $this->raw_all;
}

/**
Expand 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 => [],
};

Expand Down Expand Up @@ -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,
];
}

Expand Down Expand Up @@ -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) {
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 028842c

Please sign in to comment.