Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.04 #20

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ $audio->getCover()->getHeight(); // `?int` in pixels
| MKV | ✅ | Matroska | `matroska` | _Cover not supported_ |
| APE | ❌ | Monkey's Audio | | |
| MP3 | ✅ | MPEG audio layer 3 | `id3v2`,`id3v1` | |
| MP4 | ✅ | Digital multimedia container format | `quicktime` | |
| MP4 | ✅ | Digital multimedia container format | `quicktime` | _Partially supported_ |
| M4A | ✅ | mpeg-4 audio | `quicktime` | |
| M4B | ✅ | Audiobook | `quicktime` | |
| M4V | ✅ | mpeg-4 video | `quicktime` | |
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": "3.0.03",
"version": "3.0.04",
"keywords": [
"audio",
"php",
Expand Down
12 changes: 10 additions & 2 deletions src/Models/AudioCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,21 @@ public static function toAsf(AudioCore $core): Id3TagAsf
);
}

public static function fromId3(?Id3AudioTagV1 $v1, Id3AudioTagV2 $v2): AudioCore
public static function fromId3(?Id3AudioTagV1 $v1, ?Id3AudioTagV2 $v2): AudioCore
{
if (! $v1) {
$v1 = new Id3AudioTagV1();
}

if (! $v2) {
$v2 = new Id3AudioTagV2();
}

return new AudioCore(
album: $v2->album() ?? $v1->album(),
artist: $v2->artist() ?? $v1->artist(),
albumArtist: $v2->band() ?? null,
comment: $v2 ? $v2->comment() : $v1->comment(),
comment: $v2->comment() ?? $v1->comment(),
composer: $v2->composer() ?? null,
discNumber: $v2->part_of_a_set() ?? null,
genre: $v2->genre() ?? $v1->genre(),
Expand Down
21 changes: 20 additions & 1 deletion tests/AudioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
expect($metadata->getPath())->toBeString();
expect($metadata->getFilesize())->toBeInt();
expect($metadata->getExtension())->toBeString();
// expect($metadata->getDataformat())->toBeString();
expect($metadata->getEncoding())->toBeString();
expect($metadata->getMimeType())->toBeString();
if ($metadata->getDurationSeconds()) {
Expand Down Expand Up @@ -136,3 +135,23 @@

expect($audio->isValid())->toBeFalse();
});

it('can read file id3v1', function (string $path) {
$audio = Audio::get($path);
$extension = pathinfo($path, PATHINFO_EXTENSION);
$format = AudioFormatEnum::tryFrom($extension);

expect($audio->getTitle())->toBeString();
expect($audio->getArtist())->toBeString();
expect($audio->getAlbum())->toBeString();
expect($audio->getTrackNumber())->toBeString();
expect($audio->getAlbumArtist())->toBeString();
expect($audio->getComposer())->toBeNull();

expect($audio->getgetExtension())->toBe($extension);
expect($audio->getFormat())->toBe($format);
expect($audio->getDuration())->toBeFloat();
expect($audio->getExtras())->toBeArray();

expect($audio)->toBeInstanceOf(Audio::class);
})->with([...AUDIO_ID3_V1]);
7 changes: 7 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function addWriterFilesForTests()
define('MKA', __DIR__.'/media/test.mka');
define('MKV', __DIR__.'/media/test.mkv');
define('MP3', __DIR__.'/media/test.mp3');
define('MP3_ID3_V1_1', __DIR__.'/media/id3-test-1.mp3');
define('MP3_ID3_V1_2', __DIR__.'/media/id3-test-2.mp3');
define('MP4', __DIR__.'/media/test.mp4');
define('OGG', __DIR__.'/media/test.ogg');
define('OPUS', __DIR__.'/media/test.opus');
Expand Down Expand Up @@ -96,6 +98,11 @@ function addWriterFilesForTests()
WV,
]);

define('AUDIO_ID3_V1', [
MP3_ID3_V1_1,
MP3_ID3_V1_2,
]);

define('AUDIO_WRITER', [
// ALAC_WRITER,
// AIF_WRITER,
Expand Down
1 change: 1 addition & 0 deletions tests/media/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test-writer-alac.*
test-writer-no-meta.*
test-writer.*
id3-test-writer*
Binary file added tests/media/id3-test-1.mp3
Binary file not shown.
Binary file added tests/media/id3-test-2.mp3
Binary file not shown.