Skip to content

Commit d4cce92

Browse files
Merge pull request #24 from kiwilan/develop
v3.0.06
2 parents 81fac0b + 87570ba commit d4cce92

File tree

10 files changed

+420
-170
lines changed

10 files changed

+420
-170
lines changed

README.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ $audio = Audio::get('path/to/audio.mp3');
7676

7777
$audio->getTags(); // `array` with all tags
7878
$title = $audio->getTag('title'); // `?string` to get title same as `$audio->getTitle()`
79+
80+
$formats = $audio->getAudioFormats(); // `array` with all audio formats
81+
82+
$format = $audio->getTags('id3v2'); // `?array` with all tags with format `id3v2`
83+
$title = $audio->getTag('title', 'id3v2'); // `?string` to get title with format `id3v2`
7984
```
8085

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

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

409-
| ID3 type | Original | New property |
410-
| :-------------: | :---------------------: | :-------------: |
411-
| `id3v2` | `band` | `albumArtist` |
412-
| `id3v2` | `track_number` | `trackNumber` |
413-
| `id3v2` | `part_of_a_set` | `discNumber` |
414-
| `id3v2` | `part_of_a_compilation` | `isCompilation` |
415-
| `quicktime` | `track_number` | `trackNumber` |
416-
| `quicktime` | `disc_number` | `discNumber` |
417-
| `quicktime` | `compilation` | `isCompilation` |
418-
| `quicktime` | `creation_date` | `creationDate` |
419-
| `quicktime` | `album_artist` | `albumArtist` |
420-
| `quicktime` | `encoded_by` | `encodingBy` |
421-
| `quicktime` | `encoding_tool` | `encoding` |
422-
| `quicktime` | `description_long` | `description`\* |
423-
| `asf` | `albumartist` | `albumArtist` |
424-
| `asf` | `partofset` | `discNumber` |
425-
| `asf` | `track_number` | `trackNumber` |
426-
| `asf` | `encodingsettings` | `encoding` |
427-
| `vorbiscomment` | `encoder` | `encoding` |
428-
| `vorbiscomment` | `albumartist` | `albumArtist` |
429-
| `vorbiscomment` | `discnumber` | `discNumber` |
430-
| `vorbiscomment` | `compilation` | `isCompilation` |
431-
| `vorbiscomment` | `tracknumber` | `trackNumber` |
432-
| `matroska` | `album_artist` | `albumArtist` |
433-
| `matroska` | `disc` | `discNumber` |
434-
| `matroska` | `part_number` | `trackNumber` |
435-
| `matroska` | `date` | `year` |
436-
| `matroska` | `compilation` | `isCompilation` |
437-
| `matroska` | `encoder` | `encoding` |
438-
| `ape` | `album_artist` | `albumArtist` |
439-
| `ape` | `disc` | `discNumber` |
440-
| `ape` | `compilation` | `isCompilation` |
441-
| `ape` | `track` | `trackNumber` |
442-
| `ape` | `date` | `year` |
443-
| `ape` | `encoder` | `encoding` |
444-
445-
\*: if `description_long` has more content than `description`, it replaces `description`.
414+
| ID3 type | Original | New property |
415+
| :-------------: | :---------------------: | :------------------: |
416+
| `id3v2` | `band` | `albumArtist` |
417+
| `id3v2` | `track_number` | `trackNumber` |
418+
| `id3v2` | `part_of_a_set` | `discNumber` |
419+
| `id3v2` | `part_of_a_compilation` | `isCompilation` |
420+
| `quicktime` | `track_number` | `trackNumber` |
421+
| `quicktime` | `disc_number` | `discNumber` |
422+
| `quicktime` | `compilation` | `isCompilation` |
423+
| `quicktime` | `creation_date` | `creationDate` |
424+
| `quicktime` | `album_artist` | `albumArtist` |
425+
| `quicktime` | `encoded_by` | `encodingBy` |
426+
| `quicktime` | `encoding_tool` | `encoding` |
427+
| `quicktime` | `description_long` | `podcastDescription` |
428+
| `asf` | `albumartist` | `albumArtist` |
429+
| `asf` | `partofset` | `discNumber` |
430+
| `asf` | `track_number` | `trackNumber` |
431+
| `asf` | `encodingsettings` | `encoding` |
432+
| `vorbiscomment` | `encoder` | `encoding` |
433+
| `vorbiscomment` | `albumartist` | `albumArtist` |
434+
| `vorbiscomment` | `discnumber` | `discNumber` |
435+
| `vorbiscomment` | `compilation` | `isCompilation` |
436+
| `vorbiscomment` | `tracknumber` | `trackNumber` |
437+
| `matroska` | `album_artist` | `albumArtist` |
438+
| `matroska` | `disc` | `discNumber` |
439+
| `matroska` | `part_number` | `trackNumber` |
440+
| `matroska` | `date` | `year` |
441+
| `matroska` | `compilation` | `isCompilation` |
442+
| `matroska` | `encoder` | `encoding` |
443+
| `ape` | `album_artist` | `albumArtist` |
444+
| `ape` | `disc` | `discNumber` |
445+
| `ape` | `compilation` | `isCompilation` |
446+
| `ape` | `track` | `trackNumber` |
447+
| `ape` | `date` | `year` |
448+
| `ape` | `encoder` | `encoding` |
446449

447450
## Testing
448451

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kiwilan/php-audio",
33
"description": "PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.",
4-
"version": "3.0.05",
4+
"version": "3.0.06",
55
"keywords": [
66
"audio",
77
"php",

src/Audio.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class Audio
4545

4646
protected ?string $description = null;
4747

48+
protected ?string $podcastDescription = null;
49+
50+
protected ?string $language = null;
51+
4852
protected ?string $lyrics = null;
4953

5054
protected ?string $stik = null;
@@ -260,6 +264,22 @@ public function getDescription(): ?string
260264
return $this->description;
261265
}
262266

267+
/**
268+
* Get `podcastDescription` metadata for audiobook.
269+
*/
270+
public function getPodcastDescription(): ?string
271+
{
272+
return $this->podcastDescription;
273+
}
274+
275+
/**
276+
* Get `language` metadata for audiobook.
277+
*/
278+
public function getLanguage(): ?string
279+
{
280+
return $this->language;
281+
}
282+
263283
/**
264284
* Get `lyrics` metadata for audiobook.
265285
*/
@@ -458,27 +478,46 @@ private function coreToProperties(?AudioCore $core): self
458478
$this->encoding = $core->getEncoding();
459479
$this->copyright = $core->getCopyright();
460480
$this->description = $core->getDescription();
481+
$this->podcastDescription = $core->getPodcastDescription();
482+
$this->language = $core->getLanguage();
461483
$this->lyrics = $core->getLyrics();
462484
$this->stik = $core->getStik();
463485

464486
return $this;
465487
}
466488

467-
public function getTag(string $tag): ?string
489+
/**
490+
* Get a specific tag.
491+
*
492+
* @param string $tag Tag name.
493+
* @param string|null $audioFormat Get a specific format, default format is format with maximum tags.
494+
*/
495+
public function getTag(string $tag, ?string $audioFormat = null): ?string
468496
{
469-
$tags = $this->reader->toTagsArray();
497+
$tags = $this->reader->toTags($audioFormat);
470498

471499
return $tags[$tag] ?? null;
472500
}
473501

474502
/**
475503
* Get all tags as array.
476504
*
505+
* @param string|null $tag Get a specific format, default format is format with maximum tags.
477506
* @return array<string, string>
478507
*/
479-
public function getTags(): array
508+
public function getTags(?string $audioFormat = null): array
509+
{
510+
return $this->reader->toTags($audioFormat);
511+
}
512+
513+
/**
514+
* Get all audio formats as array, with tags.
515+
*
516+
* @return array<string, array<string, string>>
517+
*/
518+
public function getAudioFormats(): array
480519
{
481-
return $this->reader->toTagsArray();
520+
return $this->reader->toAudioFormats();
482521
}
483522

484523
/**

src/Models/AudioCore.php

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function __construct(
2121
protected ?string $encodingBy = null,
2222
protected ?string $encoding = null,
2323
protected ?string $description = null,
24+
protected ?string $podcastDescription = null,
25+
protected ?string $language = null,
2426
protected ?string $lyrics = null,
2527
protected ?string $stik = null,
2628
protected bool $hasCover = false,
@@ -112,6 +114,16 @@ public function getDescription(): ?string
112114
return $this->description;
113115
}
114116

117+
public function getPodcastDescription(): ?string
118+
{
119+
return $this->podcastDescription;
120+
}
121+
122+
public function getLanguage(): ?string
123+
{
124+
return $this->language;
125+
}
126+
115127
public function getLyrics(): ?string
116128
{
117129
return $this->lyrics;
@@ -244,6 +256,20 @@ public function setDescription(?string $description): self
244256
return $this;
245257
}
246258

259+
public function setPodcastDescription(?string $podcastDescription): self
260+
{
261+
$this->podcastDescription = $podcastDescription;
262+
263+
return $this;
264+
}
265+
266+
public function setLanguage(?string $language): self
267+
{
268+
$this->language = $language;
269+
270+
return $this;
271+
}
272+
247273
public function setLyrics(?string $lyrics): self
248274
{
249275
$this->lyrics = $lyrics;
@@ -290,6 +316,8 @@ public function toArray(): array
290316
'encodingBy' => $this->encodingBy,
291317
'encoding' => $this->encoding,
292318
'description' => $this->description,
319+
'podcastDescription' => $this->podcastDescription,
320+
'language' => $this->language,
293321
'lyrics' => $this->lyrics,
294322
'stik' => $this->stik,
295323
'hasCover' => $this->hasCover,
@@ -311,6 +339,10 @@ public static function toId3v2(AudioCore $core): Id3AudioTagV2
311339
title: $core->getTitle(),
312340
track_number: $core->getTrackNumber(),
313341
year: $core->getYear(),
342+
copyright: $core->getCopyright(),
343+
text: $core->getPodcastDescription(),
344+
unsynchronised_lyric: $core->getLyrics(),
345+
language: $core->getLanguage(),
314346
);
315347
}
316348

@@ -363,7 +395,7 @@ public static function toQuicktime(AudioCore $core): Id3TagQuicktime
363395
encoded_by: $core->getEncoding(),
364396
encoding_tool: $core->getEncoding(),
365397
description: $core->getDescription(),
366-
description_long: $core->getDescription(),
398+
description_long: $core->getPodcastDescription(),
367399
lyrics: $core->getLyrics(),
368400
comment: $core->getComment(),
369401
stik: $core->getStik(),
@@ -443,6 +475,10 @@ public static function fromId3(?Id3AudioTagV1 $v1, ?Id3AudioTagV2 $v2): AudioCor
443475
title: $v2->title() ?? $v1->title(),
444476
trackNumber: $v2->track_number() ?? $v1->track_number(),
445477
year: $v2->year() ?? $v1->year(),
478+
copyright: $v2->copyright() ?? null,
479+
description: $v2->text() ?? null,
480+
lyrics: $v2->unsynchronised_lyric() ?? null,
481+
language: $v2->language() ?? null,
446482
);
447483
}
448484

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

486-
if ($description_long && $description && strlen($description_long) > strlen($description)) {
487-
$description = $description_long;
488-
}
489-
490522
$core = new AudioCore(
491523
title: $tag->title(),
492524
artist: $tag->artist(),
@@ -500,6 +532,7 @@ public static function fromQuicktime(Id3TagQuicktime $tag): AudioCore
500532
albumArtist: $tag->album_artist(),
501533
encodingBy: $tag->encoded_by(),
502534
encoding: $tag->encoding_tool(),
535+
language: $tag->language(),
503536
);
504537

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

515548
$core->setCopyright($tag->copyright());
516549
$core->setDescription($description);
550+
$core->setPodcastDescription($description_long);
517551
$core->setLyrics($tag->lyrics());
518552
$core->setStik($tag->stik());
519553

@@ -586,8 +620,14 @@ public static function fromApe(Id3TagApe $tag): AudioCore
586620
isCompilation: $tag->compilation() === '1',
587621
title: $tag->title(),
588622
trackNumber: $tag->track(),
589-
year: (int) $tag->date(),
623+
creationDate: $tag->date(),
624+
year: $tag->year() ?? (int) $tag->date(),
590625
encoding: $tag->encoder(),
626+
description: $tag->description(),
627+
copyright: $tag->copyright(),
628+
lyrics: $tag->lyrics(),
629+
podcastDescription: $tag->podcastdesc(),
630+
language: $tag->language(),
591631
);
592632
}
593633
}

0 commit comments

Comments
 (0)