Skip to content

Commit

Permalink
Merge pull request #24 from kiwilan/develop
Browse files Browse the repository at this point in the history
v3.0.06
  • Loading branch information
ewilan-riviere authored Feb 4, 2024
2 parents 81fac0b + 87570ba commit d4cce92
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 170 deletions.
77 changes: 40 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ $audio = Audio::get('path/to/audio.mp3');

$audio->getTags(); // `array` with all tags
$title = $audio->getTag('title'); // `?string` to get title same as `$audio->getTitle()`

$formats = $audio->getAudioFormats(); // `array` with all audio formats

$format = $audio->getTags('id3v2'); // `?array` with all tags with format `id3v2`
$title = $audio->getTag('title', 'id3v2'); // `?string` to get title with format `id3v2`
```

Additional metadata:
Expand Down Expand Up @@ -406,43 +411,41 @@ You want to add a format? [See FAQ](#faq)

`Audio::class` convert some properties to be more readable.

| ID3 type | Original | New property |
| :-------------: | :---------------------: | :-------------: |
| `id3v2` | `band` | `albumArtist` |
| `id3v2` | `track_number` | `trackNumber` |
| `id3v2` | `part_of_a_set` | `discNumber` |
| `id3v2` | `part_of_a_compilation` | `isCompilation` |
| `quicktime` | `track_number` | `trackNumber` |
| `quicktime` | `disc_number` | `discNumber` |
| `quicktime` | `compilation` | `isCompilation` |
| `quicktime` | `creation_date` | `creationDate` |
| `quicktime` | `album_artist` | `albumArtist` |
| `quicktime` | `encoded_by` | `encodingBy` |
| `quicktime` | `encoding_tool` | `encoding` |
| `quicktime` | `description_long` | `description`\* |
| `asf` | `albumartist` | `albumArtist` |
| `asf` | `partofset` | `discNumber` |
| `asf` | `track_number` | `trackNumber` |
| `asf` | `encodingsettings` | `encoding` |
| `vorbiscomment` | `encoder` | `encoding` |
| `vorbiscomment` | `albumartist` | `albumArtist` |
| `vorbiscomment` | `discnumber` | `discNumber` |
| `vorbiscomment` | `compilation` | `isCompilation` |
| `vorbiscomment` | `tracknumber` | `trackNumber` |
| `matroska` | `album_artist` | `albumArtist` |
| `matroska` | `disc` | `discNumber` |
| `matroska` | `part_number` | `trackNumber` |
| `matroska` | `date` | `year` |
| `matroska` | `compilation` | `isCompilation` |
| `matroska` | `encoder` | `encoding` |
| `ape` | `album_artist` | `albumArtist` |
| `ape` | `disc` | `discNumber` |
| `ape` | `compilation` | `isCompilation` |
| `ape` | `track` | `trackNumber` |
| `ape` | `date` | `year` |
| `ape` | `encoder` | `encoding` |

\*: if `description_long` has more content than `description`, it replaces `description`.
| ID3 type | Original | New property |
| :-------------: | :---------------------: | :------------------: |
| `id3v2` | `band` | `albumArtist` |
| `id3v2` | `track_number` | `trackNumber` |
| `id3v2` | `part_of_a_set` | `discNumber` |
| `id3v2` | `part_of_a_compilation` | `isCompilation` |
| `quicktime` | `track_number` | `trackNumber` |
| `quicktime` | `disc_number` | `discNumber` |
| `quicktime` | `compilation` | `isCompilation` |
| `quicktime` | `creation_date` | `creationDate` |
| `quicktime` | `album_artist` | `albumArtist` |
| `quicktime` | `encoded_by` | `encodingBy` |
| `quicktime` | `encoding_tool` | `encoding` |
| `quicktime` | `description_long` | `podcastDescription` |
| `asf` | `albumartist` | `albumArtist` |
| `asf` | `partofset` | `discNumber` |
| `asf` | `track_number` | `trackNumber` |
| `asf` | `encodingsettings` | `encoding` |
| `vorbiscomment` | `encoder` | `encoding` |
| `vorbiscomment` | `albumartist` | `albumArtist` |
| `vorbiscomment` | `discnumber` | `discNumber` |
| `vorbiscomment` | `compilation` | `isCompilation` |
| `vorbiscomment` | `tracknumber` | `trackNumber` |
| `matroska` | `album_artist` | `albumArtist` |
| `matroska` | `disc` | `discNumber` |
| `matroska` | `part_number` | `trackNumber` |
| `matroska` | `date` | `year` |
| `matroska` | `compilation` | `isCompilation` |
| `matroska` | `encoder` | `encoding` |
| `ape` | `album_artist` | `albumArtist` |
| `ape` | `disc` | `discNumber` |
| `ape` | `compilation` | `isCompilation` |
| `ape` | `track` | `trackNumber` |
| `ape` | `date` | `year` |
| `ape` | `encoder` | `encoding` |

## Testing

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.05",
"version": "3.0.06",
"keywords": [
"audio",
"php",
Expand Down
47 changes: 43 additions & 4 deletions src/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Audio

protected ?string $description = null;

protected ?string $podcastDescription = null;

protected ?string $language = null;

protected ?string $lyrics = null;

protected ?string $stik = null;
Expand Down Expand Up @@ -260,6 +264,22 @@ public function getDescription(): ?string
return $this->description;
}

/**
* Get `podcastDescription` metadata for audiobook.
*/
public function getPodcastDescription(): ?string
{
return $this->podcastDescription;
}

/**
* Get `language` metadata for audiobook.
*/
public function getLanguage(): ?string
{
return $this->language;
}

/**
* Get `lyrics` metadata for audiobook.
*/
Expand Down Expand Up @@ -458,27 +478,46 @@ private function coreToProperties(?AudioCore $core): self
$this->encoding = $core->getEncoding();
$this->copyright = $core->getCopyright();
$this->description = $core->getDescription();
$this->podcastDescription = $core->getPodcastDescription();
$this->language = $core->getLanguage();
$this->lyrics = $core->getLyrics();
$this->stik = $core->getStik();

return $this;
}

public function getTag(string $tag): ?string
/**
* Get a specific tag.
*
* @param string $tag Tag name.
* @param string|null $audioFormat Get a specific format, default format is format with maximum tags.
*/
public function getTag(string $tag, ?string $audioFormat = null): ?string
{
$tags = $this->reader->toTagsArray();
$tags = $this->reader->toTags($audioFormat);

return $tags[$tag] ?? null;
}

/**
* Get all tags as array.
*
* @param string|null $tag Get a specific format, default format is format with maximum tags.
* @return array<string, string>
*/
public function getTags(): array
public function getTags(?string $audioFormat = null): array
{
return $this->reader->toTags($audioFormat);
}

/**
* Get all audio formats as array, with tags.
*
* @return array<string, array<string, string>>
*/
public function getAudioFormats(): array
{
return $this->reader->toTagsArray();
return $this->reader->toAudioFormats();
}

/**
Expand Down
52 changes: 46 additions & 6 deletions src/Models/AudioCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct(
protected ?string $encodingBy = null,
protected ?string $encoding = null,
protected ?string $description = null,
protected ?string $podcastDescription = null,
protected ?string $language = null,
protected ?string $lyrics = null,
protected ?string $stik = null,
protected bool $hasCover = false,
Expand Down Expand Up @@ -112,6 +114,16 @@ public function getDescription(): ?string
return $this->description;
}

public function getPodcastDescription(): ?string
{
return $this->podcastDescription;
}

public function getLanguage(): ?string
{
return $this->language;
}

public function getLyrics(): ?string
{
return $this->lyrics;
Expand Down Expand Up @@ -244,6 +256,20 @@ public function setDescription(?string $description): self
return $this;
}

public function setPodcastDescription(?string $podcastDescription): self
{
$this->podcastDescription = $podcastDescription;

return $this;
}

public function setLanguage(?string $language): self
{
$this->language = $language;

return $this;
}

public function setLyrics(?string $lyrics): self
{
$this->lyrics = $lyrics;
Expand Down Expand Up @@ -290,6 +316,8 @@ public function toArray(): array
'encodingBy' => $this->encodingBy,
'encoding' => $this->encoding,
'description' => $this->description,
'podcastDescription' => $this->podcastDescription,
'language' => $this->language,
'lyrics' => $this->lyrics,
'stik' => $this->stik,
'hasCover' => $this->hasCover,
Expand All @@ -311,6 +339,10 @@ public static function toId3v2(AudioCore $core): Id3AudioTagV2
title: $core->getTitle(),
track_number: $core->getTrackNumber(),
year: $core->getYear(),
copyright: $core->getCopyright(),
text: $core->getPodcastDescription(),
unsynchronised_lyric: $core->getLyrics(),
language: $core->getLanguage(),
);
}

Expand Down Expand Up @@ -363,7 +395,7 @@ public static function toQuicktime(AudioCore $core): Id3TagQuicktime
encoded_by: $core->getEncoding(),
encoding_tool: $core->getEncoding(),
description: $core->getDescription(),
description_long: $core->getDescription(),
description_long: $core->getPodcastDescription(),
lyrics: $core->getLyrics(),
comment: $core->getComment(),
stik: $core->getStik(),
Expand Down Expand Up @@ -443,6 +475,10 @@ public static function fromId3(?Id3AudioTagV1 $v1, ?Id3AudioTagV2 $v2): AudioCor
title: $v2->title() ?? $v1->title(),
trackNumber: $v2->track_number() ?? $v1->track_number(),
year: $v2->year() ?? $v1->year(),
copyright: $v2->copyright() ?? null,
description: $v2->text() ?? null,
lyrics: $v2->unsynchronised_lyric() ?? null,
language: $v2->language() ?? null,
);
}

Expand Down Expand Up @@ -483,10 +519,6 @@ public static function fromQuicktime(Id3TagQuicktime $tag): AudioCore
$description = $tag->description();
$description_long = $tag->description_long();

if ($description_long && $description && strlen($description_long) > strlen($description)) {
$description = $description_long;
}

$core = new AudioCore(
title: $tag->title(),
artist: $tag->artist(),
Expand All @@ -500,6 +532,7 @@ public static function fromQuicktime(Id3TagQuicktime $tag): AudioCore
albumArtist: $tag->album_artist(),
encodingBy: $tag->encoded_by(),
encoding: $tag->encoding_tool(),
language: $tag->language(),
);

if ($creation_date) {
Expand All @@ -514,6 +547,7 @@ public static function fromQuicktime(Id3TagQuicktime $tag): AudioCore

$core->setCopyright($tag->copyright());
$core->setDescription($description);
$core->setPodcastDescription($description_long);
$core->setLyrics($tag->lyrics());
$core->setStik($tag->stik());

Expand Down Expand Up @@ -586,8 +620,14 @@ public static function fromApe(Id3TagApe $tag): AudioCore
isCompilation: $tag->compilation() === '1',
title: $tag->title(),
trackNumber: $tag->track(),
year: (int) $tag->date(),
creationDate: $tag->date(),
year: $tag->year() ?? (int) $tag->date(),
encoding: $tag->encoder(),
description: $tag->description(),
copyright: $tag->copyright(),
lyrics: $tag->lyrics(),
podcastDescription: $tag->podcastdesc(),
language: $tag->language(),
);
}
}
Expand Down
Loading

0 comments on commit d4cce92

Please sign in to comment.