Skip to content

Commit af14b61

Browse files
Merge pull request #12 from kiwilan/develop
3.0.0
2 parents 903dd90 + 58a9f6c commit af14b61

15 files changed

+533
-503
lines changed

README.md

Lines changed: 85 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,57 @@ composer require kiwilan/php-audio
5353
Core metadata:
5454

5555
```php
56+
use Kiwilan\Audio\Audio;
57+
5658
$audio = Audio::get('path/to/audio.mp3');
5759

58-
$audio->title(); // `?string` to get title
59-
$audio->artist(); // `?string` to get artist
60-
$audio->album(); // `?string` to get album
61-
$audio->genre(); // `?string` to get genre
62-
$audio->year(); // `?int` to get year
63-
$audio->trackNumber(); // `?string` to get track number
64-
$audio->comment(); // `?string` to get comment
65-
$audio->albumArtist(); // `?string` to get album artist
66-
$audio->composer(); // `?string` to get composer
67-
$audio->discNumber(); // `?string` to get disc number
60+
$audio->getTitle(); // `?string` to get title
61+
$audio->getArtist(); // `?string` to get artist
62+
$audio->getAlbum(); // `?string` to get album
63+
$audio->getGenre(); // `?string` to get genre
64+
$audio->getYear(); // `?int` to get year
65+
$audio->getTrackNumber(); // `?string` to get track number
66+
$audio->getComment(); // `?string` to get comment
67+
$audio->getAlbumArtist(); // `?string` to get album artist
68+
$audio->getComposer(); // `?string` to get composer
69+
$audio->getDiscNumber(); // `?string` to get disc number
6870
$audio->isCompilation(); // `bool` to know if is compilation
69-
$audio->creationDate(); // `?string` to get creation date (audiobook)
70-
$audio->copyright(); // `?string` to get copyright (audiobook)
71-
$audio->encoding(); // `?string` to get encoding
72-
$audio->description(); // `?string` to get description (audiobook)
73-
$audio->lyrics(); // `?string` (audiobook)
74-
$audio->stik(); // `?string` (audiobook)
75-
$audio->duration(); // `?float` to get duration in seconds
71+
$audio->getCreationDate(); // `?string` to get creation date (audiobook)
72+
$audio->getCopyright(); // `?string` to get copyright (audiobook)
73+
$audio->getEncoding(); // `?string` to get encoding
74+
$audio->getDescription(); // `?string` to get description (audiobook)
75+
$audio->getLyrics(); // `?string` (audiobook)
76+
$audio->getStik(); // `?string` (audiobook)
77+
$audio->getDuration(); // `?float` to get duration in seconds
7678
```
7779

7880
Additional metadata:
7981

8082
```php
83+
use Kiwilan\Audio\Audio;
84+
8185
$audio = Audio::get('path/to/audio.mp3');
8286

83-
$audio->path(); // `string` to get path
87+
$audio->getPath(); // `string` to get path
8488
$audio->hasCover(); // `bool` to know if has cover
8589
$audio->isValid(); // `bool` to know if file is valid audio file
86-
$audio->format(); // `AudioFormatEnum` to get format (mp3, m4a, ...)
87-
$audio->type(); // `?AudioTypeEnum` ID3 type (id3, riff, asf, quicktime, matroska, ape, vorbiscomment)
90+
$audio->getFormat(); // `AudioFormatEnum` to get format (mp3, m4a, ...)
91+
$audio->getType(); // `?AudioTypeEnum` ID3 type (id3, riff, asf, quicktime, matroska, ape, vorbiscomment)
92+
$audio->getExtras(); // `array` with raw metadata (could contains some metadata not parsed)
8893
```
8994

9095
Advanced properties:
9196

9297
```php
98+
use Kiwilan\Audio\Audio;
99+
93100
$audio = Audio::get('path/to/audio.mp3');
94101

95-
$audio->extras(); // `array` with raw metadata (could contains some metadata not parsed)
96-
$audio->reader(); // `?Id3Reader` reader based on `getID3`
97-
$audio->writer(); // `?Id3Writer` writer based on `getid3_writetags`
98-
$audio->stat(); // `FileStat` (from `stat` function)
99-
$audio->audio(); // `?AudioMetadata` with audio metadata
100-
$audio->cover(); // `?AudioCover` with cover metadata
102+
$audio->getReader(); // `?Id3Reader` reader based on `getID3`
103+
$audio->getWriter(); // `?Id3Writer` writer based on `getid3_writetags`
104+
$audio->getStat(); // `AudioStat` (from `stat` function)
105+
$audio->getAudio(); // `?AudioMetadata` with audio metadata
106+
$audio->getCover(); // `?AudioCover` with cover metadata
101107
```
102108

103109
### Update
@@ -109,8 +115,10 @@ You can update audio files metadata with `Audio::class`, but not all formats are
109115
> You can use any property of `Audio::class` but if you use a property not supported by the format, it will be ignored.
110116
111117
```php
118+
use Kiwilan\Audio\Audio;
119+
112120
$audio = Audio::get('path/to/audio.mp3');
113-
$audio->title(); // `Title`
121+
$audio->getTitle(); // `Title`
114122

115123
$tag = $audio->update()
116124
->title('New Title')
@@ -134,8 +142,8 @@ $tag = $audio->update()
134142
->save();
135143

136144
$audio = Audio::get('path/to/audio.mp3');
137-
$audio->title(); // `New Title`
138-
$audio->creationDate(); // `null` because `creationDate` is not supported by `MP3`
145+
$audio->getTitle(); // `New Title`
146+
$audio->getCreationDate(); // `null` because `creationDate` is not supported by `MP3`
139147
```
140148

141149
Some properties are not supported by all formats, for example `MP3` can't handle some properties like `lyrics` or `stik`, if you try to update these properties, they will be ignored.
@@ -151,8 +159,10 @@ You can set tags manually with `tags` method, but you need to know the format of
151159
> If your key is not supported, `save` method will throw an exception, unless you use `preventFailOnErrors`.
152160
153161
```php
162+
use Kiwilan\Audio\Audio;
163+
154164
$audio = Audio::get('path/to/audio.mp3');
155-
$audio->albumArtist(); // `Band`
165+
$audio->getAlbumArtist(); // `Band`
156166

157167
$tag = $audio->update()
158168
->tags([
@@ -163,29 +173,33 @@ $tag = $audio->update()
163173
->save();
164174

165175
$audio = Audio::get('path/to/audio.mp3');
166-
$audio->albumArtist(); // `New Band`
176+
$audio->getAlbumArtist(); // `New Band`
167177
```
168178

169179
#### Arrow functions
170180

171181
```php
182+
use Kiwilan\Audio\Audio;
183+
172184
$audio = Audio::get('path/to/audio.mp3');
173-
$audio->albumArtist(); // `Band`
185+
$audio->getAlbumArtist(); // `Band`
174186

175187
$tag = $audio->update()
176188
->title('New Title')
177189
->albumArtist('New Band') // `albumArtist` will set `band` for `id3v2`, exception safe
178190
->save();
179191

180192
$audio = Audio::get('path/to/audio.mp3');
181-
$audio->albumArtist(); // `New Band`
193+
$audio->getAlbumArtist(); // `New Band`
182194
```
183195

184196
#### Prevent fail on errors
185197

186198
You can use `preventFailOnError` to prevent exception if you use unsupported format.
187199

188200
```php
201+
use Kiwilan\Audio\Audio;
202+
189203
$audio = Audio::get('path/to/audio.mp3');
190204

191205
$tag = $audio->update()
@@ -200,6 +214,8 @@ $tag = $audio->update()
200214
Arrow functions are exception safe for properties but not for unsupported formats.
201215

202216
```php
217+
use Kiwilan\Audio\Audio;
218+
203219
$audio = Audio::get('path/to/audio.mp3');
204220

205221
$tag = $audio->update()
@@ -213,6 +229,8 @@ $tag = $audio->update()
213229
Of course you can add cover with `tags` method.
214230

215231
```php
232+
use Kiwilan\Audio\Audio;
233+
216234
$audio = Audio::get('path/to/audio.mp3');
217235
$cover = 'path/to/cover.jpg';
218236

@@ -243,6 +261,8 @@ $tag = $audio->update()
243261
Merge `tags` with arrow functions.
244262

245263
```php
264+
use Kiwilan\Audio\Audio;
265+
246266
$audio = Audio::get($path);
247267

248268
$tag = $audio->update()
@@ -255,8 +275,8 @@ $tag = $audio->update()
255275
$tag->save();
256276

257277
$audio = Audio::get($path);
258-
expect($audio->title())->toBe('New Title');
259-
expect($audio->albumArtist())->toBe('New Band');
278+
expect($audio->getTitle())->toBe('New Title');
279+
expect($audio->getAlbumArtist())->toBe('New Band');
260280
```
261281

262282
### Extras
@@ -266,41 +286,47 @@ Audio files format metadata with different methods, `JamesHeinrich/getID3` offer
266286
If you want to extract specific field which can be skipped by `Audio::class`, you can use `extras` property.
267287

268288
```php
289+
use Kiwilan\Audio\Audio;
290+
269291
$audio = Audio::get('path/to/audio.mp3');
270-
$extras = $audio->extras();
292+
$extras = $audio->getExtras();
271293

272294
$id3v2 = $extras['id3v2'] ?? [];
273295
```
274296

275297
### AudioMetadata
276298

277299
```php
300+
use Kiwilan\Audio\Audio;
301+
278302
$audio = Audio::get('path/to/audio.mp3');
279303

280-
$audio->audio()->filesize(); // `?int` in bytes
281-
$audio->audio()->extension(); // `?string` (mp3, m4a, ...)
282-
$audio->audio()->encoding(); // `?string` (UTF-8...)
283-
$audio->audio()->mimeType(); // `?string` (audio/mpeg, audio/mp4, ...)
284-
$audio->audio()->durationSeconds(); // `?float` in seconds
285-
$audio->audio()->durationReadable(); // `?string` (00:00:00)
286-
$audio->audio()->bitrate(); // `?int` in kbps
287-
$audio->audio()->bitrateMode(); // `?string` (cbr, vbr, ...)
288-
$audio->audio()->sampleRate(); // `?int` in Hz
289-
$audio->audio()->channels(); // `?int` (1, 2, ...)
290-
$audio->audio()->channelMode(); // `?string` (mono, stereo, ...)
291-
$audio->audio()->lossless(); // `bool` to know if is lossless
292-
$audio->audio()->compressionRatio(); // `?float`
304+
$audio->getAudio()->getFilesize(); // `?int` in bytes
305+
$audio->getAudio()->getExtension(); // `?string` (mp3, m4a, ...)
306+
$audio->getAudio()->getEncoding(); // `?string` (UTF-8...)
307+
$audio->getAudio()->getMimeType(); // `?string` (audio/mpeg, audio/mp4, ...)
308+
$audio->getAudio()->getDurationSeconds(); // `?float` in seconds
309+
$audio->getAudio()->getDurationReadable(); // `?string` (00:00:00)
310+
$audio->getAudio()->getBitrate(); // `?int` in kbps
311+
$audio->getAudio()->getBitrateMode(); // `?string` (cbr, vbr, ...)
312+
$audio->getAudio()->getSampleRate(); // `?int` in Hz
313+
$audio->getAudio()->getChannels(); // `?int` (1, 2, ...)
314+
$audio->getAudio()->getChannelMode(); // `?string` (mono, stereo, ...)
315+
$audio->getAudio()->getLossless(); // `bool` to know if is lossless
316+
$audio->getAudio()->getCompressionRatio(); // `?float`
293317
```
294318

295319
### AudioCover
296320

297321
```php
322+
use Kiwilan\Audio\Audio;
323+
298324
$audio = Audio::get('path/to/audio.mp3');
299325

300-
$audio->cover()->content(); // `?string` raw file
301-
$audio->cover()->mimeType(); // `?string` (image/jpeg, image/png, ...)
302-
$audio->cover()->width(); // `?int` in pixels
303-
$audio->cover()->height(); // `?int` in pixels
326+
$audio->getCover()->getContent(); // `?string` raw file
327+
$audio->getCover()->getMimeType(); // `?string` (image/jpeg, image/png, ...)
328+
$audio->getCover()->getWidth(); // `?int` in pixels
329+
$audio->getCover()->getHeight(); // `?int` in pixels
304330
```
305331

306332
## Supported formats
@@ -424,8 +450,10 @@ composer test
424450
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.
425451

426452
```php
453+
use Kiwilan\Audio\Audio;
454+
427455
$audio = Audio::get('path/to/audio.mp3');
428-
$extras = $audio->extras();
456+
$extras = $audio->getExtras();
429457

430458
$custom = null;
431459
$id3v2 = $extras['id3v2'] ?? [];
@@ -442,9 +470,11 @@ If your field could be added to global properties of `Audio::class`, you could c
442470
You can check `extras` property to know if some metadata are available.
443471

444472
```php
473+
use Kiwilan\Audio\Audio;
474+
445475
$audio = Audio::get('path/to/audio.mp3');
446476

447-
$extras = $audio->extras();
477+
$extras = $audio->getExtras();
448478
var_dump($extras);
449479
```
450480

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": "2.0.0",
4+
"version": "3.0.0",
55
"keywords": [
66
"audio",
77
"php",

0 commit comments

Comments
 (0)