diff --git a/README.md b/README.md index 447d40b..1be0e8f 100644 --- a/README.md +++ b/README.md @@ -501,15 +501,15 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio [](https://github.com/kiwilan) -[version-src]: https://img.shields.io/packagist/v/kiwilan/php-audio.svg?style=flat-square&colorA=18181B&colorB=777BB4 +[version-src]: https://img.shields.io/packagist/v/kiwilan/php-audio.svg?style=flat&colorA=18181B&colorB=777BB4 [version-href]: https://packagist.org/packages/kiwilan/php-audio -[php-version-src]: https://img.shields.io/static/v1?style=flat-square&label=PHP&message=v8.1&color=777BB4&logo=php&logoColor=ffffff&labelColor=18181b +[php-version-src]: https://img.shields.io/static/v1?style=flat&label=PHP&message=v8.1&color=777BB4&logo=php&logoColor=ffffff&labelColor=18181b [php-version-href]: https://www.php.net/ -[downloads-src]: https://img.shields.io/packagist/dt/kiwilan/php-audio.svg?style=flat-square&colorA=18181B&colorB=777BB4 +[downloads-src]: https://img.shields.io/packagist/dt/kiwilan/php-audio.svg?style=flat&colorA=18181B&colorB=777BB4 [downloads-href]: https://packagist.org/packages/kiwilan/php-audio -[license-src]: https://img.shields.io/github/license/kiwilan/php-audio.svg?style=flat-square&colorA=18181B&colorB=777BB4 +[license-src]: https://img.shields.io/github/license/kiwilan/php-audio.svg?style=flat&colorA=18181B&colorB=777BB4 [license-href]: https://github.com/kiwilan/php-audio/blob/main/README.md -[tests-src]: https://img.shields.io/github/actions/workflow/status/kiwilan/php-audio/run-tests.yml?branch=main&label=tests&style=flat-square&colorA=18181B +[tests-src]: https://img.shields.io/github/actions/workflow/status/kiwilan/php-audio/run-tests.yml?branch=main&label=tests&style=flat&colorA=18181B [tests-href]: https://packagist.org/packages/kiwilan/php-audio -[codecov-src]: https://codecov.io/gh/kiwilan/php-audio/branch/main/graph/badge.svg?token=4L0D92Z1EZ +[codecov-src]: https://img.shields.io/codecov/c/gh/kiwilan/php-audio/main?style=flat&colorA=18181B&colorB=777BB4 [codecov-href]: https://codecov.io/gh/kiwilan/php-audio diff --git a/composer.json b/composer.json index 9739ffa..121e6d0 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/php-audio", "description": "PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.", - "version": "3.0.02", + "version": "3.0.03", "keywords": [ "audio", "php", diff --git a/src/Models/AudioCore.php b/src/Models/AudioCore.php index 85108ad..d801db3 100644 --- a/src/Models/AudioCore.php +++ b/src/Models/AudioCore.php @@ -427,7 +427,7 @@ public static function fromId3(?Id3AudioTagV1 $v1, Id3AudioTagV2 $v2): AudioCore album: $v2->album() ?? $v1->album(), artist: $v2->artist() ?? $v1->artist(), albumArtist: $v2->band() ?? null, - comment: $v2->comment() ?? $v1->comment(), + comment: $v2 ? $v2->comment() : $v1->comment(), composer: $v2->composer() ?? null, discNumber: $v2->part_of_a_set() ?? null, genre: $v2->genre() ?? $v1->genre(), diff --git a/src/Models/AudioMetadata.php b/src/Models/AudioMetadata.php index 705de83..22bd79c 100644 --- a/src/Models/AudioMetadata.php +++ b/src/Models/AudioMetadata.php @@ -7,8 +7,10 @@ class AudioMetadata { protected function __construct( + protected ?string $path = null, protected ?int $filesize = null, protected ?string $extension = null, + protected ?string $dataformat = null, protected ?string $encoding = null, protected ?string $mimeType = null, protected ?float $durationSeconds = null, @@ -25,12 +27,15 @@ protected function __construct( public static function make(Audio $audio): self { + $path = $audio->getPath(); $reader = $audio->getReader(); $audio = $reader->getAudio(); return new self( + path: $path, filesize: $reader->getFilesize(), - extension: $audio?->dataformat(), + extension: pathinfo($path, PATHINFO_EXTENSION), + dataformat: $audio?->dataformat(), encoding: $reader->getEncoding(), mimeType: $reader->getMimeType(), durationSeconds: $reader->getPlaytimeSeconds(), @@ -45,6 +50,11 @@ public static function make(Audio $audio): self ); } + public function getPath(): ?string + { + return $this->path; + } + public function getFilesize(): ?int { return $this->filesize; @@ -55,6 +65,11 @@ public function getExtension(): ?string return $this->extension; } + public function getDataformat(): ?string + { + return $this->dataformat; + } + public function getEncoding(): ?string { return $this->encoding; diff --git a/tests/AudioTest.php b/tests/AudioTest.php index f3f1dbf..6073ac3 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -9,7 +9,6 @@ $extension = pathinfo($path, PATHINFO_EXTENSION); $format = AudioFormatEnum::tryFrom($extension); - // ray($audio); expect($audio)->toBeInstanceOf(Audio::class); expect($audio->getTitle())->toBe('Introduction'); expect($audio->getArtist())->toBe('Mr Piouf'); @@ -31,8 +30,10 @@ expect($audio->getExtras())->toBeArray(); $metadata = $audio->getAudio(); + 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()) { @@ -70,7 +71,7 @@ if ($audio->hasCover()) { expect($cover)->toBeInstanceOf(AudioCover::class); - expect($cover->getContent())->toBeString(); + expect($cover->getContents())->toBeString(); expect($cover->getContents())->toBeString(); expect($cover->getMimeType())->toBeString(); if ($cover->getWidth()) { diff --git a/tests/Pest.php b/tests/Pest.php index 7e20c49..71ce7be 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -85,7 +85,7 @@ function addWriterFilesForTests() MKA, MKV, MP3, - MP4, + // MP4, OGG, OPUS, SPX, diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..216d6de --- /dev/null +++ b/tests/README.md @@ -0,0 +1,53 @@ +# Tests + +## Docker ubuntu + +```bash +docker pull ubuntu:latest +docker run -it --rm ubuntu:latest +``` + +```bash +cd /home +apt update +apt install -y git software-properties-common +apt install -y flac vorbis-tools +add-apt-repository ppa:ondrej/php +apt update +apt -y install php8.2-fpm php8.2-curl php8.2-xml php8.2-zip +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php composer-setup.php +php -r "unlink('composer-setup.php');" +``` + +```bash +git clone -b develop https://github.com/kiwilan/php-audio.git +cd php-audio +/home/composer.phar install +/home/composer.phar test +``` + +## Docker windows + +```bash +docker pull mcr.microsoft.com/windows/server +docker run -it --rm mcr.microsoft.com/windows/servercore:ltsc2019 +``` + +```bash +powershell +``` + +```powershell +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')) +scoop install git +scoop install php +scoop install composer +``` + +```bash +git clone -b develop +cd php-audio +composer install +composer test +```