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.08 #33

Merged
merged 1 commit into from
Jul 28, 2024
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 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.07",
"version": "3.0.08",
"keywords": [
"audio",
"php",
Expand Down
11 changes: 9 additions & 2 deletions src/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ protected function __construct(
protected AudioStat $stat,
protected Id3Reader $reader,
protected ?Id3Writer $writer = null,
) {
}
) {}

public static function get(string $path): self
{
Expand Down Expand Up @@ -304,6 +303,14 @@ public function getDuration(): ?float
return $this->duration;
}

/**
* Get `duration` in human readable format: `00:00:00`.
*/
public function getDurationHumanReadable(): ?string
{
return gmdate('H:i:s', intval($this->duration));
}

/**
* Know if audio file is valid.
*/
Expand Down
12 changes: 5 additions & 7 deletions src/Models/AudioCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
protected ?string $stik = null,
protected bool $hasCover = false,
protected ?AudioCoreCover $cover = null,
) {
}
) {}

public function getTitle(): ?string
{
Expand Down Expand Up @@ -456,11 +455,11 @@
public static function fromId3(?Id3AudioTagV1 $v1, ?Id3AudioTagV2 $v2): AudioCore
{
if (! $v1) {
$v1 = new Id3AudioTagV1();
$v1 = new Id3AudioTagV1;
}

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

Check warning on line 462 in src/Models/AudioCore.php

View check run for this annotation

Codecov / codecov/patch

src/Models/AudioCore.php#L462

Added line #L462 was not covered by tests
}

return new AudioCore(
Expand Down Expand Up @@ -646,12 +645,11 @@
protected ?string $picturetypeid = null,
protected ?string $description = null,
protected ?string $mime = null,
) {
}
) {}

public static function make(string $pathOrData): self
{
$self = new self();
$self = new self;

if (file_exists($pathOrData)) {
$image = getimagesize($pathOrData);
Expand Down
2 changes: 1 addition & 1 deletion src/Models/AudioCover.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function make(?Id3Comments $comments): ?self
return null;
}

$self = new self();
$self = new self;

$self->contents = $comments->picture()->data();
$self->mimeType = $comments->picture()->image_mime();
Expand Down
3 changes: 1 addition & 2 deletions src/Models/AudioMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ protected function __construct(
protected ?string $channelMode = null,
protected bool $lossless = false,
protected ?float $compressionRatio = null,
) {
}
) {}

public static function make(Audio $audio): self
{
Expand Down
3 changes: 1 addition & 2 deletions src/Models/AudioStat.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ protected function __construct(
protected ?DateTime $modifiedAt = null,
protected ?int $blockSize = null,
protected ?int $numberOfBlocks = null,
) {
}
) {}

public static function make(string $path): self
{
Expand Down
50 changes: 17 additions & 33 deletions src/Models/Id3Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ protected function __construct(
protected ?Id3TagsHtml $tags_html = null,
protected ?float $bitrate = null,
protected ?string $playtime_string = null,
) {
}
) {}

public static function make(string $path): self
{
$self = new self(new getID3());
$self = new self(new getID3);

$self->raw = $self->instance->analyze($path);
$self->is_writable = $self->instance->is_writable($path);
Expand Down Expand Up @@ -260,8 +259,7 @@ protected function __construct(
protected bool $lossless = false,
protected ?string $encoder_options = null,
protected ?float $compression_ratio = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -369,8 +367,7 @@ protected function __construct(
protected ?float $resolution_x = null,
protected ?float $resolution_y = null,
protected ?float $frame_rate = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -429,8 +426,7 @@ protected function __construct(
protected bool $lossless = false,
protected ?string $encoder_options = null,
protected ?float $compression_ratio = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -522,8 +518,7 @@ protected function __construct(
protected ?Id3TagRiff $riff = null,
protected ?Id3TagMatroska $matroska = null,
protected ?Id3TagApe $ape = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -605,8 +600,7 @@ public function __construct(
protected ?string $genre = null,
protected ?string $comment = null,
protected ?string $track_number = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -694,8 +688,7 @@ public function __construct(
protected ?string $text = null,
protected ?string $unsynchronised_lyric = null,
protected ?string $language = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -826,8 +819,7 @@ class Id3Comments
protected function __construct(
protected ?string $language = null,
protected ?Id3CommentsPicture $picture = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -862,8 +854,7 @@ protected function __construct(
protected ?string $picturetype = null,
protected ?string $description = null,
protected ?int $datalength = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -942,8 +933,7 @@ public function __construct(
protected ?string $lyrics = null,
protected ?string $comment = null,
protected ?string $stik = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1110,8 +1100,7 @@ public function __construct(
protected ?string $track_number = null,
protected ?string $year = null,
protected ?string $encodingsettings = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1217,8 +1206,7 @@ public function __construct(
protected ?string $compilation = null,
protected ?string $date = null,
protected ?string $tracknumber = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1339,8 +1327,7 @@ public function __construct(
protected ?string $title = null,
protected ?string $product = null,
protected ?string $software = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1427,8 +1414,7 @@ public function __construct(
protected ?string $date = null,
protected ?string $encoder = null,
protected ?string $duration = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1575,8 +1561,7 @@ public function __construct(
protected ?string $podcastdesc = null,
protected ?string $language = null,
protected ?string $year = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down Expand Up @@ -1734,8 +1719,7 @@ protected function __construct(
protected ?Id3TagRiff $riff = null,
protected ?Id3TagMatroska $matroska = null,
protected ?Id3TagApe $ape = null,
) {
}
) {}

public static function make(?array $metadata): ?self
{
Expand Down
7 changes: 3 additions & 4 deletions src/Models/Id3Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ protected function __construct(
protected Audio $audio,
protected getid3_writetags $instance,
protected AudioCore $core,
) {
}
) {}

public static function make(Audio $audio): self
{
$self = new self(
audio: $audio,
instance: new getid3_writetags(),
core: new AudioCore()
instance: new getid3_writetags,
core: new AudioCore
);

return $self;
Expand Down
1 change: 1 addition & 0 deletions tests/AudioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
expect($audio->getgetExtension())->toBe($extension);
expect($audio->getFormat())->toBe($format);
expect($audio->getDuration())->toBeFloat();
expect($audio->getDurationHumanReadable())->toBe('00:00:11');
expect($audio->getExtras())->toBeArray();

expect($audio)->toBeInstanceOf(Audio::class);
Expand Down
1 change: 1 addition & 0 deletions tests/AudiobookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
expect($audio->getLyrics())->toBe('Lyrics');
expect($audio->getStik())->toBe('Audiobook');
expect($audio->getDuration())->toBe(11.00);
expect($audio->getDurationHumanReadable())->toBe('00:00:11');
expect($audio->getExtras())->toBeArray();
expect($audio->toArray())->toBeArray();

Expand Down
1 change: 1 addition & 0 deletions tests/Mp3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
expect($audio->getPath())->toBe(MP3);
expect($audio->getFormat())->toBe(AudioFormatEnum::mp3);
expect($audio->getDuration())->toBe(11.05);
expect($audio->getDurationHumanReadable())->toBe('00:00:11');
expect($audio->getExtras())->toBeArray();

$audio = $audio->getAudio();
Expand Down