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.06 #24

Merged
merged 2 commits into from
Feb 4, 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
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 @@
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 @@
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 @@
return $this;
}

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

return $this;
}

public function setLanguage(?string $language): self

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

View check run for this annotation

Codecov / codecov/patch

src/Models/AudioCore.php#L266

Added line #L266 was not covered by tests
{
$this->language = $language;

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

View check run for this annotation

Codecov / codecov/patch

src/Models/AudioCore.php#L268

Added line #L268 was not covered by tests

return $this;

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

View check run for this annotation

Codecov / codecov/patch

src/Models/AudioCore.php#L270

Added line #L270 was not covered by tests
}

public function setLyrics(?string $lyrics): self
{
$this->lyrics = $lyrics;
Expand Down Expand Up @@ -290,6 +316,8 @@
'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 @@
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 @@
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 @@
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 @@
$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 @@
albumArtist: $tag->album_artist(),
encodingBy: $tag->encoded_by(),
encoding: $tag->encoding_tool(),
language: $tag->language(),
);

if ($creation_date) {
Expand All @@ -514,6 +547,7 @@

$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 @@
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
Loading