Skip to content

Commit

Permalink
improve update
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Sep 30, 2024
1 parent 22d19fd commit b0455e8
Show file tree
Hide file tree
Showing 23 changed files with 661 additions and 1,343 deletions.
58 changes: 32 additions & 26 deletions src/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kiwilan\Audio\Enums\AudioFormatEnum;
use Kiwilan\Audio\Enums\AudioTypeEnum;
use Kiwilan\Audio\Id3\Id3Reader;
use Kiwilan\Audio\Id3\Id3Writer;
use Kiwilan\Audio\Models\AudioCover;
use Kiwilan\Audio\Models\AudioMetadata;

Expand Down Expand Up @@ -134,6 +135,11 @@ public function getId3Reader(): ?Id3Reader
return Id3Reader::make($this->path);
}

public function update(): Id3Writer
{
return Id3Writer::make($this);
}

/**
* Get duration of the audio file in seconds, limited to 2 decimals, like `180.66`
*
Expand Down Expand Up @@ -465,7 +471,7 @@ private function parseTags(?\Kiwilan\Audio\Id3\Id3Reader $id3_reader): self
};

$tags = $id3_reader->getTags();
if (! $tags || $tags->isEmpty()) {
if (! $tags || $tags->is_empty) {
return $this;
}

Expand All @@ -475,12 +481,12 @@ private function parseTags(?\Kiwilan\Audio\Id3\Id3Reader $id3_reader): self
}

$core = match ($this->type) {
AudioTypeEnum::id3 => AudioCore::fromId3($tags->id3v1(), $tags->id3v2()),
AudioTypeEnum::vorbiscomment => AudioCore::fromVorbisComment($tags->vorbiscomment()),
AudioTypeEnum::quicktime => AudioCore::fromQuicktime($tags->quicktime()),
AudioTypeEnum::matroska => AudioCore::fromMatroska($tags->matroska()),
AudioTypeEnum::ape => AudioCore::fromApe($tags->ape()),
AudioTypeEnum::asf => AudioCore::fromAsf($tags->asf()),
AudioTypeEnum::id3 => AudioCore::fromId3($tags->id3v1, $tags->id3v2),
AudioTypeEnum::vorbiscomment => AudioCore::fromVorbisComment($tags->vorbiscomment),
AudioTypeEnum::quicktime => AudioCore::fromQuicktime($tags->quicktime),
AudioTypeEnum::matroska => AudioCore::fromMatroska($tags->matroska),
AudioTypeEnum::ape => AudioCore::fromApe($tags->ape),
AudioTypeEnum::asf => AudioCore::fromAsf($tags->asf),
default => null,
};

Expand All @@ -505,25 +511,25 @@ private function convertCore(?AudioCore $core): self
return $this;
}

$this->title = $core->getTitle();
$this->artist = $core->getArtist();
$this->album = $core->getAlbum();
$this->genre = $core->getGenre();
$this->year = $core->getYear();
$this->track_number = $core->getTrackNumber();
$this->comment = $core->getComment();
$this->album_artist = $core->getAlbumArtist();
$this->composer = $core->getComposer();
$this->disc_number = $core->getDiscNumber();
$this->is_compilation = $core->isCompilation();
$this->creation_date = $core->getCreationDate();
$this->encoding_by = $core->getEncodingBy();
$this->encoding = $core->getEncoding();
$this->copyright = $core->getCopyright();
$this->description = $core->getDescription();
$this->synopsis = $core->getSynopsis();
$this->language = $core->getLanguage();
$this->lyrics = $core->getLyrics();
$this->title = $core->title;
$this->artist = $core->artist;
$this->album = $core->album;
$this->genre = $core->genre;
$this->year = $core->year;
$this->track_number = $core->track_number;
$this->comment = $core->comment;
$this->album_artist = $core->album_artist;
$this->composer = $core->composer;
$this->disc_number = $core->disc_number;
$this->is_compilation = $core->is_compilation;
$this->creation_date = $core->creation_date;
$this->encoding_by = $core->encoding_by;
$this->encoding = $core->encoding;
$this->copyright = $core->copyright;
$this->description = $core->description;
$this->synopsis = $core->synopsis;
$this->language = $core->language;
$this->lyrics = $core->lyrics;

return $this;
}
Expand Down
Loading

0 comments on commit b0455e8

Please sign in to comment.