Skip to content

Commit 04077ce

Browse files
Merge pull request #2 from kiwilan/develop
1.0.0
2 parents 1a3b3ec + 837dd38 commit 04077ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1760
-393
lines changed

README.md

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
[![tests][tests-src]][tests-href]
99
[![codecov][codecov-src]][codecov-href]
1010

11-
PHP package to parse audio files metadata, with [JamesHeinrich/getID3](https://github.com/JamesHeinrich/getID3).
11+
PHP package to parse and update audio files metadata, with [`JamesHeinrich/getID3`](https://github.com/JamesHeinrich/getID3).
1212

1313
## Supported formats
1414

15+
### Readable formats
16+
17+
- `id3v2` will be selected before `id3v1` or `riff` if both are available.
18+
1519
| Format | Supported | About | ID3 type | Notes |
1620
| :----: | :-------: | :----------------------------------: | :-------------: | :-------------------: |
1721
| AAC || Advanced Audio Coding | | |
@@ -24,7 +28,7 @@ PHP package to parse audio files metadata, with [JamesHeinrich/getID3](https://g
2428
| MKA || Matroska | `matroska` | _Cover not supported_ |
2529
| MKV || Matroska | `matroska` | _Cover not supported_ |
2630
| APE || Monkey's Audio | | |
27-
| MP3 || MPEG audio layer 3 | `id3v1`,`id3v2` | |
31+
| MP3 || MPEG audio layer 3 | `id3v2`,`id3v1` | |
2832
| MP4 || Digital multimedia container format | `quicktime` | |
2933
| M4A || mpeg-4 audio | `quicktime` | |
3034
| M4B || Audiobook | `quicktime` | |
@@ -44,13 +48,38 @@ PHP package to parse audio files metadata, with [JamesHeinrich/getID3](https://g
4448

4549
You want to add a format? [See FAQ](#faq)
4650

47-
## Requirements
51+
### Updatable formats
4852

49-
- PHP >= 8.1
53+
`JamesHeinrich/getID3` can update some formats, but not all.
54+
55+
> - ID3v1 (v1 & v1.1)
56+
> - ID3v2 (v2.3, v2.4)
57+
> - APE (v2)
58+
> - Ogg Vorbis comments (need `vorbis-tools`)
59+
> - FLAC comments
60+
61+
| Format | Notes |
62+
| :----: | :-------------------: |
63+
| FLAC | _Cover not supported_ |
64+
| MP3 | |
65+
| OGG | _Cover not supported_ |
66+
67+
### Convert properties
68+
69+
`Audio::class` convert some properties to be more readable.
70+
71+
| ID3 type | Original | New property |
72+
| :------: | :------------: | :-----------: |
73+
| `id3v2` | `band` | `albumArtist` |
74+
| `id3v2` | `track_number` | `trackNumber` |
5075

5176
## About
5277

53-
Audio files can use different formats, this package aims to provide a simple way to read them with [JamesHeinrich/getID3](https://github.com/JamesHeinrich/getID3). The `JamesHeinrich/getID3` package is excellent to read metadata from audio files, but output is just an array, current package aims to provide a simple way to read audio files with a beautiful API.
78+
Audio files can use different formats, this package aims to provide a simple way to read them with [`JamesHeinrich/getID3`](https://github.com/JamesHeinrich/getID3). The `JamesHeinrich/getID3` package is excellent to read metadata from audio files, but output is just an array, current package aims to provide a simple way to read audio files with a beautiful API.
79+
80+
## Requirements
81+
82+
- PHP >= 8.1
5483

5584
## Installation
5685

@@ -62,8 +91,10 @@ composer require kiwilan/php-audio
6291

6392
## Usage
6493

94+
Core metadata:
95+
6596
```php
66-
$audio = Audio::read('path/to/audio.mp3');
97+
$audio = Audio::get('path/to/audio.mp3');
6798

6899
$audio->title(); // `?string` to get title
69100
$audio->artist(); // `?string` to get artist
@@ -83,48 +114,80 @@ $audio->description(); // `?string` to get description (audiobook)
83114
$audio->lyrics(); // `?string` (audiobook)
84115
$audio->stik(); // `?string` (audiobook)
85116
$audio->duration(); // `?float` to get duration in seconds
117+
```
118+
119+
Additional metadata:
120+
121+
```php
122+
$audio = Audio::get('path/to/audio.mp3');
86123

87124
$audio->path(); // `string` to get path
88-
$audio->extension(); // `string` to get extension
89125
$audio->hasCover(); // `bool` to know if has cover
90126
$audio->isValid(); // `bool` to know if file is valid audio file
127+
$audio->format(); // `AudioFormatEnum` to get format (mp3, m4a, ...)
128+
$audio->type(); // `?AudioTypeEnum` ID3 type (id3, riff, asf, quicktime, matroska, ape, vorbiscomment)
91129

92130
$audio->extras(); // `array` with raw metadata (could contains some metadata not parsed)
93-
$audio->id3(); // `Id3` metadata
131+
$audio->reader(); // `?Id3Reader` reader based on `getID3`
132+
$audio->writer(); // `?Id3Writer` writer based on `getid3_writetags`
94133
$audio->stat(); // `FileStat` (from `stat` function)
95134
$audio->audio(); // `?AudioMetadata` with audio metadata
96135
$audio->cover(); // `?AudioCover` with cover metadata
97136
```
98137

138+
### Update
139+
140+
You can update audio files metadata with `Audio::class`, but not all formats are supported. [See supported formats](#updatable-formats)
141+
142+
```php
143+
$audio = Audio::get('path/to/audio.mp3');
144+
145+
// you can use file content
146+
$cover = file_get_contents('path/to/cover.jpg');
147+
// or file path
148+
$cover = 'path/to/cover.jpg';
149+
150+
$tag = $audio->update()
151+
->setTitle('New Title')
152+
->setArtist('New Artist')
153+
->setAlbum('New Album')
154+
->setGenre('New Genre')
155+
->setYear('2022')
156+
->setTrackNumber('2/10')
157+
->setAlbumArtist('New Album Artist')
158+
->setComment('New Comment')
159+
->setComposer('New Composer')
160+
->setCreationDate('2021-01-01')
161+
->setDescription('New Description')
162+
->setDiscNumber('2/2')
163+
->setEncodingBy('New Encoding By')
164+
->setEncoding('New Encoding')
165+
->setIsCompilation(false)
166+
->setLyrics('New Lyrics')
167+
->setStik('New Stik')
168+
->setCover($cover)
169+
->save();
170+
```
171+
172+
Some properties are not supported by all formats, for example `MP3` can't handle `lyrics` or `stik` properties, if you try to update these properties, they will be ignored.
173+
99174
### Extras
100175

101176
Audio files format metadata with different methods, `JamesHeinrich/getID3` offer to check these metadatas by different methods. In `extras` property of `Audio::class`, you will find raw metadata from `JamesHeinrich/getID3` package, like `id3v2`, `id3v1`, `riff`, `asf`, `quicktime`, `matroska`, `ape`, `vorbiscomment`...
102177

103178
If you want to extract specific field which can be skipped by `Audio::class`, you can use `extras` property.
104179

105180
```php
106-
$audio = Audio::read('path/to/audio.mp3');
181+
$audio = Audio::get('path/to/audio.mp3');
107182
$extras = $audio->extras();
108183

109184
$id3v2 = $extras['id3v2'] ?? [];
110185
```
111186

112-
### ID3
113-
114-
Data from `JamesHeinrich/getID3` package with formatting.
115-
116-
```php
117-
$audio = Audio::read('path/to/audio.mp3');
118-
119-
$audio->id3()->raw(); // `array` with raw metadata
120-
$audio->id3()->item(); // `?Id3Item` with item metadata
121-
$audio->id3()->instance(); // `getID3` instance
122-
```
123-
124187
### AudioMetadata
125188

126189
```php
127-
$audio = Audio::read('path/to/audio.mp3');
190+
$audio = Audio::get('path/to/audio.mp3');
128191

129192
$audio->audio()->filesize(); // `?int` in bytes
130193
$audio->audio()->extension(); // `?string` (mp3, m4a, ...)
@@ -144,7 +207,7 @@ $audio->audio()->compressionRatio(); // `?float`
144207
### AudioCover
145208

146209
```php
147-
$audio = Audio::read('path/to/audio.mp3');
210+
$audio = Audio::get('path/to/audio.mp3');
148211

149212
$audio->cover()->content(); // `?string` raw file
150213
$audio->cover()->mimeType(); // `?string` (image/jpeg, image/png, ...)
@@ -171,7 +234,7 @@ composer test
171234
In `Audio::class`, you have a property `extras` which contains all raw metadata, if `JamesHeinrich/getID3` support this field, you will find it in this property.
172235

173236
```php
174-
$audio = Audio::read('path/to/audio.mp3');
237+
$audio = Audio::get('path/to/audio.mp3');
175238
$extras = $audio->extras();
176239

177240
$custom = null;

composer.json

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

0 commit comments

Comments
 (0)