1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Metadata package. |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Metadata\ID3v1; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Metadata\Exception\BadMethodCallException; |
11
|
|
|
use GravityMedia\Metadata\Exception\InvalidArgumentException; |
12
|
|
|
use GravityMedia\Metadata\ID3v1\Enum\Genre; |
13
|
|
|
use GravityMedia\Metadata\ID3v1\Enum\Version; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* ID3v1 tag class. |
17
|
|
|
* |
18
|
|
|
* @package GravityMedia\Metadata\ID3v1 |
19
|
|
|
*/ |
20
|
|
|
class Tag |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* String representations of genres |
24
|
|
|
* |
25
|
|
|
* @var string[] |
26
|
|
|
*/ |
27
|
|
|
protected static $genres = [ |
28
|
|
|
Genre::GENRE_BLUES => 'Blues', |
29
|
|
|
Genre::GENRE_CLASSIC_ROCK => 'Classic Rock', |
30
|
|
|
Genre::GENRE_COUNTRY => 'Country', |
31
|
|
|
Genre::GENRE_DANCE => 'Dance', |
32
|
|
|
Genre::GENRE_DISCO => 'Disco', |
33
|
|
|
Genre::GENRE_FUNK => 'Funk', |
34
|
|
|
Genre::GENRE_GRUNGE => 'Grunge', |
35
|
|
|
Genre::GENRE_HIP_HOP => 'Hip-Hop', |
36
|
|
|
Genre::GENRE_JAZZ => 'Jazz', |
37
|
|
|
Genre::GENRE_METAL => 'Metal', |
38
|
|
|
Genre::GENRE_NEW_AGE => 'New Age', |
39
|
|
|
Genre::GENRE_OLDIES => 'Oldies', |
40
|
|
|
Genre::GENRE_OTHER => 'Other', |
41
|
|
|
Genre::GENRE_POP => 'Pop', |
42
|
|
|
Genre::GENRE_R_AND_B => 'R&B', |
43
|
|
|
Genre::GENRE_RAP => 'Rap', |
44
|
|
|
Genre::GENRE_REGGAE => 'Reggae', |
45
|
|
|
Genre::GENRE_ROCK => 'Rock', |
46
|
|
|
Genre::GENRE_TECHNO => 'Techno', |
47
|
|
|
Genre::GENRE_INDUSTRIAL => 'Industrial', |
48
|
|
|
Genre::GENRE_ALTERNATIVE => 'Alternative', |
49
|
|
|
Genre::GENRE_SKA => 'Ska', |
50
|
|
|
Genre::GENRE_DEATH_METAL => 'Death Metal', |
51
|
|
|
Genre::GENRE_PRANKS => 'Pranks', |
52
|
|
|
Genre::GENRE_SOUNDTRACK => 'Soundtrack', |
53
|
|
|
Genre::GENRE_EURO_TECHNO => 'Euro-Techno', |
54
|
|
|
Genre::GENRE_AMBIENT => 'Ambient', |
55
|
|
|
Genre::GENRE_TRIP_HOP => 'Trip-Hop', |
56
|
|
|
Genre::GENRE_VOCAL => 'Vocal', |
57
|
|
|
Genre::GENRE_JAZZ_AND_FUNK => 'Jazz+Funk', |
58
|
|
|
Genre::GENRE_FUSION => 'Fusion', |
59
|
|
|
Genre::GENRE_TRANCE => 'Trance', |
60
|
|
|
Genre::GENRE_CLASSICAL => 'Classical', |
61
|
|
|
Genre::GENRE_INSTRUMENTAL => 'Instrumental', |
62
|
|
|
Genre::GENRE_ACID => 'Acid', |
63
|
|
|
Genre::GENRE_HOUSE => 'House', |
64
|
|
|
Genre::GENRE_GAME => 'Game', |
65
|
|
|
Genre::GENRE_SOUND_CLIP => 'Sound Clip', |
66
|
|
|
Genre::GENRE_GOSPEL => 'Gospel', |
67
|
|
|
Genre::GENRE_NOISE => 'Noise', |
68
|
|
|
Genre::GENRE_ALTERNATIVE_ROCK => 'Alt. Rock', |
69
|
|
|
Genre::GENRE_BASS => 'Bass', |
70
|
|
|
Genre::GENRE_SOUL => 'Soul', |
71
|
|
|
Genre::GENRE_PUNK => 'Punk', |
72
|
|
|
Genre::GENRE_SPACE => 'Space', |
73
|
|
|
Genre::GENRE_MEDITATIVE => 'Meditative', |
74
|
|
|
Genre::GENRE_INSTRUMENTAL_POP => 'Instrumental Pop', |
75
|
|
|
Genre::GENRE_INSTRUMENTAL_ROCK => 'Instrumental Rock', |
76
|
|
|
Genre::GENRE_ETHNIC => 'Ethnic', |
77
|
|
|
Genre::GENRE_GOTHIC => 'Gothic', |
78
|
|
|
Genre::GENRE_DARKWAVE => 'Darkwave', |
79
|
|
|
Genre::GENRE_TECHNO_INDUSTRIAL => 'Techno-Industrial', |
80
|
|
|
Genre::GENRE_ELECTRONIC => 'Electronic', |
81
|
|
|
Genre::GENRE_POP_FOLK => 'Pop-Folk', |
82
|
|
|
Genre::GENRE_EURODANCE => 'Eurodance', |
83
|
|
|
Genre::GENRE_DREAM => 'Dream', |
84
|
|
|
Genre::GENRE_SOUTHERN_ROCK => 'Southern Rock', |
85
|
|
|
Genre::GENRE_COMEDY => 'Comedy', |
86
|
|
|
Genre::GENRE_CULT => 'Cult', |
87
|
|
|
Genre::GENRE_GANGSTA_RAP => 'Gangsta Rap', |
88
|
|
|
Genre::GENRE_TOP_40 => 'Top 40', |
89
|
|
|
Genre::GENRE_CHRISTIAN_RAP => 'Christian Rap', |
90
|
|
|
Genre::GENRE_POP_OR_FUNK => 'Pop/Funk', |
91
|
|
|
Genre::GENRE_JUNGLE => 'Jungle', |
92
|
|
|
Genre::GENRE_NATIVE_AMERICAN => 'Native American', |
93
|
|
|
Genre::GENRE_CABARET => 'Cabaret', |
94
|
|
|
Genre::GENRE_NEW_WAVE => 'New Wave', |
95
|
|
|
Genre::GENRE_PSYCHEDELIC => 'Psychedelic', |
96
|
|
|
Genre::GENRE_RAVE => 'Rave', |
97
|
|
|
Genre::GENRE_SHOWTUNES => 'Showtunes', |
98
|
|
|
Genre::GENRE_TRAILER => 'Trailer', |
99
|
|
|
Genre::GENRE_LO_FI => 'Lo-Fi', |
100
|
|
|
Genre::GENRE_TRIBAL => 'Tribal', |
101
|
|
|
Genre::GENRE_ACID_PUNK => 'Acid Punk', |
102
|
|
|
Genre::GENRE_ACID_JAZZ => 'Acid Jazz', |
103
|
|
|
Genre::GENRE_POLKA => 'Polka', |
104
|
|
|
Genre::GENRE_RETRO => 'Retro', |
105
|
|
|
Genre::GENRE_MUSICAL => 'Musical', |
106
|
|
|
Genre::GENRE_ROCK_AND_ROLL => 'Rock & Roll', |
107
|
|
|
Genre::GENRE_HARD_ROCK => 'Hard Rock', |
108
|
|
|
Genre::GENRE_FOLK => 'Folk', |
109
|
|
|
Genre::GENRE_FOLK_OR_ROCK => 'Folk/Rock', |
110
|
|
|
Genre::GENRE_NATIONAL_FOLK => 'National Folk', |
111
|
|
|
Genre::GENRE_SWING => 'Swing', |
112
|
|
|
Genre::GENRE_FAST_FUSION => 'Fast-Fusion', |
113
|
|
|
Genre::GENRE_BEBOB => 'Bebob', |
114
|
|
|
Genre::GENRE_LATIN => 'Latin', |
115
|
|
|
Genre::GENRE_REVIVAL => 'Revival', |
116
|
|
|
Genre::GENRE_CELTIC => 'Celtic', |
117
|
|
|
Genre::GENRE_BLUEGRASS => 'Bluegrass', |
118
|
|
|
Genre::GENRE_AVANTGARDE => 'Avantgarde', |
119
|
|
|
Genre::GENRE_GOTHIC_ROCK => 'Gothic Rock', |
120
|
|
|
Genre::GENRE_PROGRESSIVE_ROCK => 'Progressive Rock', |
121
|
|
|
Genre::GENRE_PSYCHEDELIC_ROCK => 'Psychedelic Rock', |
122
|
|
|
Genre::GENRE_SYMPHONIC_ROCK => 'Symphonic Rock', |
123
|
|
|
Genre::GENRE_SLOW_ROCK => 'Slow Rock', |
124
|
|
|
Genre::GENRE_BIG_BAND => 'Big Band', |
125
|
|
|
Genre::GENRE_CHORUS => 'Chorus', |
126
|
|
|
Genre::GENRE_EASY_LISTENING => 'Easy Listening', |
127
|
|
|
Genre::GENRE_ACOUSTIC => 'Acoustic', |
128
|
|
|
Genre::GENRE_HUMOUR => 'Humour', |
129
|
|
|
Genre::GENRE_SPEECH => 'Speech', |
130
|
|
|
Genre::GENRE_CHANSON => 'Chanson', |
131
|
|
|
Genre::GENRE_OPERA => 'Opera', |
132
|
|
|
Genre::GENRE_CHAMBER_MUSIC => 'Chamber Music', |
133
|
|
|
Genre::GENRE_SONATA => 'Sonata', |
134
|
|
|
Genre::GENRE_SYMPHONY => 'Symphony', |
135
|
|
|
Genre::GENRE_BOOTY_BASS => 'Booty Bass', |
136
|
|
|
Genre::GENRE_PRIMUS => 'Primus', |
137
|
|
|
Genre::GENRE_PORN_GROOVE => 'Porn Groove', |
138
|
|
|
Genre::GENRE_SATIRE => 'Satire', |
139
|
|
|
Genre::GENRE_SLOW_JAM => 'Slow Jam', |
140
|
|
|
Genre::GENRE_CLUB => 'Club', |
141
|
|
|
Genre::GENRE_TANGO => 'Tango', |
142
|
|
|
Genre::GENRE_SAMBA => 'Samba', |
143
|
|
|
Genre::GENRE_FOLKLORE => 'Folklore', |
144
|
|
|
Genre::GENRE_BALLAD => 'Ballad', |
145
|
|
|
Genre::GENRE_POWER_BALLAD => 'Power Ballad', |
146
|
|
|
Genre::GENRE_RHYTHMIC_SOUL => 'Rhythmic Soul', |
147
|
|
|
Genre::GENRE_FREESTYLE => 'Freestyle', |
148
|
|
|
Genre::GENRE_DUET => 'Duet', |
149
|
|
|
Genre::GENRE_PUNK_ROCK => 'Punk Rock', |
150
|
|
|
Genre::GENRE_DRUM_SOLO => 'Drum Solo', |
151
|
|
|
Genre::GENRE_A_CAPPELLA => 'A Cappella', |
152
|
|
|
Genre::GENRE_EURO_HOUSE => 'Euro-House', |
153
|
|
|
Genre::GENRE_DANCE_HALL => 'Dance Hall', |
154
|
|
|
Genre::GENRE_GOA => 'Goa', |
155
|
|
|
Genre::GENRE_DRUM_AND_BASS => 'Drum & Bass', |
156
|
|
|
Genre::GENRE_CLUB_HOUSE => 'Club-House', |
157
|
|
|
Genre::GENRE_HARDCORE => 'Hardcore', |
158
|
|
|
Genre::GENRE_TERROR => 'Terror', |
159
|
|
|
Genre::GENRE_INDIE => 'Indie', |
160
|
|
|
Genre::GENRE_BRITPOP => 'BritPop', |
161
|
|
|
Genre::GENRE_NEGERPUNK => 'Negerpunk', |
162
|
|
|
Genre::GENRE_POLSK_PUNK => 'Polsk Punk', |
163
|
|
|
Genre::GENRE_BEAT => 'Beat', |
164
|
|
|
Genre::GENRE_CHRISTIAN_GANGSTA_RAP => 'Christian Gangsta Rap', |
165
|
|
|
Genre::GENRE_HEAVY_METAL => 'Heavy Metal', |
166
|
|
|
Genre::GENRE_BLACK_METAL => 'Black Metal', |
167
|
|
|
Genre::GENRE_CROSSOVER => 'Crossover', |
168
|
|
|
Genre::GENRE_CONTEMPORARY_CHRISTIAN => 'Contemporary Christian', |
169
|
|
|
Genre::GENRE_CHRISTIAN_ROCK => 'Christian Rock', |
170
|
|
|
Genre::GENRE_MERENGUE => 'Merengue', |
171
|
|
|
Genre::GENRE_SALSA => 'Salsa', |
172
|
|
|
Genre::GENRE_THRASH_METAL => 'Thrash Metal', |
173
|
|
|
Genre::GENRE_ANIME => 'Anime', |
174
|
|
|
Genre::GENRE_JPOP => 'JPop', |
175
|
|
|
Genre::GENRE_SYNTHPOP => 'Synthpop', |
176
|
|
|
Genre::GENRE_ABSTRACT => 'Abstract', |
177
|
|
|
Genre::GENRE_ART_ROCK => 'Art Rock', |
178
|
|
|
Genre::GENRE_BAROQUE => 'Baroque', |
179
|
|
|
Genre::GENRE_BHANGRA => 'Bhangra', |
180
|
|
|
Genre::GENRE_BIG_BEAT => 'Big Beat', |
181
|
|
|
Genre::GENRE_BREAKBEAT => 'Breakbeat', |
182
|
|
|
Genre::GENRE_CHILLOUT => 'Chillout', |
183
|
|
|
Genre::GENRE_DOWNTEMPO => 'Downtempo', |
184
|
|
|
Genre::GENRE_DUB => 'Dub', |
185
|
|
|
Genre::GENRE_EBM => 'EBM', |
186
|
|
|
Genre::GENRE_ECLECTIC => 'Eclectic', |
187
|
|
|
Genre::GENRE_ELECTRO => 'Electro', |
188
|
|
|
Genre::GENRE_ELECTROCLASH => 'Electroclash', |
189
|
|
|
Genre::GENRE_EMO => 'Emo', |
190
|
|
|
Genre::GENRE_EXPERIMENTAL => 'Experimental', |
191
|
|
|
Genre::GENRE_GARAGE => 'Garage', |
192
|
|
|
Genre::GENRE_GLOBAL => 'Global', |
193
|
|
|
Genre::GENRE_IDM => 'IDM', |
194
|
|
|
Genre::GENRE_ILLBIENT => 'Illbient', |
195
|
|
|
Genre::GENRE_INDUSTRO_GOTH => 'Industro-Goth', |
196
|
|
|
Genre::GENRE_JAM_BAND => 'Jam Band', |
197
|
|
|
Genre::GENRE_KRAUTROCK => 'Krautrock', |
198
|
|
|
Genre::GENRE_LEFTFIELD => 'Leftfield', |
199
|
|
|
Genre::GENRE_LOUNGE => 'Lounge', |
200
|
|
|
Genre::GENRE_MATH_ROCK => 'Math Rock', |
201
|
|
|
Genre::GENRE_NEW_ROMANTIC => 'New Romantic', |
202
|
|
|
Genre::GENRE_NU_BREAKZ => 'Nu-Breakz', |
203
|
|
|
Genre::GENRE_POST_PUNK => 'Post-Punk', |
204
|
|
|
Genre::GENRE_POST_ROCK => 'Post-Rock', |
205
|
|
|
Genre::GENRE_PSYTRANCE => 'Psytrance', |
206
|
|
|
Genre::GENRE_SHOEGAZE => 'Shoegaze', |
207
|
|
|
Genre::GENRE_SPACE_ROCK => 'Space Rock', |
208
|
|
|
Genre::GENRE_TROP_ROCK => 'Trop Rock', |
209
|
|
|
Genre::GENRE_WORLD_MUSIC => 'World Music', |
210
|
|
|
Genre::GENRE_NEOCLASSICAL => 'Neoclassical', |
211
|
|
|
Genre::GENRE_AUDIOBOOK => 'Audiobook', |
212
|
|
|
Genre::GENRE_AUDIO_THEATRE => 'Audio Theatre', |
213
|
|
|
Genre::GENRE_NEUE_DEUTSCHE_WELLE => 'Neue Deutsche Welle', |
214
|
|
|
Genre::GENRE_PODCAST => 'Podcast', |
215
|
|
|
Genre::GENRE_INDIE_ROCK => 'Indie Rock', |
216
|
|
|
Genre::GENRE_G_FUNK => 'G-Funk', |
217
|
|
|
Genre::GENRE_DUBSTEP => 'Dubstep', |
218
|
|
|
Genre::GENRE_GARAGE_ROCK => 'Garage Rock', |
219
|
|
|
Genre::GENRE_PSYBIENT => 'Psybient' |
220
|
|
|
]; |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @var int |
224
|
|
|
*/ |
225
|
|
|
protected $version; |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @var string |
229
|
|
|
*/ |
230
|
|
|
protected $title; |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @var string |
234
|
|
|
*/ |
235
|
|
|
protected $artist; |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @var string |
239
|
|
|
*/ |
240
|
|
|
protected $album; |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @var int |
244
|
|
|
*/ |
245
|
|
|
protected $year; |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @var string |
249
|
|
|
*/ |
250
|
|
|
protected $comment; |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @var int |
254
|
|
|
*/ |
255
|
|
|
protected $track; |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @var int |
259
|
|
|
*/ |
260
|
|
|
protected $genre; |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Create tag object. |
264
|
|
|
* |
265
|
|
|
* @param int $version The version (default is 1: v1.1). |
266
|
|
|
* |
267
|
|
|
* @throws InvalidArgumentException An exception is thrown on invalid version arguments. |
268
|
|
|
*/ |
269
|
|
View Code Duplication |
public function __construct($version = Version::VERSION_11) |
|
|
|
|
270
|
|
|
{ |
271
|
|
|
if (!in_array($version, Version::values())) { |
272
|
|
|
throw new InvalidArgumentException('Invalid version'); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
$this->version = $version; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Get version. |
280
|
|
|
* |
281
|
|
|
* @return int |
282
|
|
|
*/ |
283
|
|
|
public function getVersion() |
284
|
|
|
{ |
285
|
|
|
return $this->version; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Get title. |
290
|
|
|
* |
291
|
|
|
* @return string |
292
|
|
|
*/ |
293
|
|
|
public function getTitle() |
294
|
|
|
{ |
295
|
|
|
return $this->title; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Set title. |
300
|
|
|
* |
301
|
|
|
* @param string $title The title. |
302
|
|
|
* |
303
|
|
|
* @throws InvalidArgumentException An exception is thrown when the title exceeds 30 characters. |
304
|
|
|
* |
305
|
|
|
* @return $this |
306
|
|
|
*/ |
307
|
|
|
public function setTitle($title) |
308
|
|
|
{ |
309
|
|
|
if (strlen($title) > 30) { |
310
|
|
|
throw new InvalidArgumentException('Title argument exceeds maximum number of characters'); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
$this->title = $title; |
314
|
|
|
|
315
|
|
|
return $this; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Get artist |
320
|
|
|
* |
321
|
|
|
* @return string |
322
|
|
|
*/ |
323
|
|
|
public function getArtist() |
324
|
|
|
{ |
325
|
|
|
return $this->artist; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Set artist. |
330
|
|
|
* |
331
|
|
|
* @param string $artist The artist. |
332
|
|
|
* |
333
|
|
|
* @throws InvalidArgumentException An exception is thrown when the artist exceeds 30 characters. |
334
|
|
|
* |
335
|
|
|
* @return $this |
336
|
|
|
*/ |
337
|
|
|
public function setArtist($artist) |
338
|
|
|
{ |
339
|
|
|
if (strlen($artist) > 30) { |
340
|
|
|
throw new InvalidArgumentException('Artist argument exceeds maximum number of characters'); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$this->artist = $artist; |
344
|
|
|
|
345
|
|
|
return $this; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Get album |
350
|
|
|
* |
351
|
|
|
* @return string |
352
|
|
|
*/ |
353
|
|
|
public function getAlbum() |
354
|
|
|
{ |
355
|
|
|
return $this->album; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Set album. |
360
|
|
|
* |
361
|
|
|
* @param string $album The album. |
362
|
|
|
* |
363
|
|
|
* @throws InvalidArgumentException An exception is thrown when the album exceeds 30 characters. |
364
|
|
|
* |
365
|
|
|
* @return $this |
366
|
|
|
*/ |
367
|
|
|
public function setAlbum($album) |
368
|
|
|
{ |
369
|
|
|
if (strlen($album) > 30) { |
370
|
|
|
throw new InvalidArgumentException('Album argument exceeds maximum number of characters'); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$this->album = $album; |
374
|
|
|
|
375
|
|
|
return $this; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Get year. |
380
|
|
|
* |
381
|
|
|
* @return int |
382
|
|
|
*/ |
383
|
|
|
public function getYear() |
384
|
|
|
{ |
385
|
|
|
return $this->year; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Set year. |
390
|
|
|
* |
391
|
|
|
* @param int $year The year. |
392
|
|
|
* |
393
|
|
|
* @throws InvalidArgumentException An exception is thrown when the year does not have exactly 4 digits. |
394
|
|
|
* |
395
|
|
|
* @return $this |
396
|
|
|
*/ |
397
|
|
|
public function setYear($year) |
398
|
|
|
{ |
399
|
|
|
if (preg_match('/^\d{4}$/', $year) < 1) { |
400
|
|
|
throw new InvalidArgumentException('Year argument must have exactly 4 digits'); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
$this->year = $year; |
404
|
|
|
|
405
|
|
|
return $this; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Get comment. |
410
|
|
|
* |
411
|
|
|
* @return string |
412
|
|
|
*/ |
413
|
|
|
public function getComment() |
414
|
|
|
{ |
415
|
|
|
return $this->comment; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Set comment. |
420
|
|
|
* |
421
|
|
|
* @param string $comment The comment. |
422
|
|
|
* |
423
|
|
|
* @throws InvalidArgumentException An exception is thrown when the comment exceeds 28 characters (ID3 v1.1) or 30 |
424
|
|
|
* characters (ID3 v1.0). |
425
|
|
|
* |
426
|
|
|
* @return $this |
427
|
|
|
*/ |
428
|
|
|
public function setComment($comment) |
429
|
|
|
{ |
430
|
|
|
$max = Version::VERSION_11 === $this->version ? 28 : 30; |
431
|
|
|
if (strlen($comment) > $max) { |
432
|
|
|
throw new InvalidArgumentException('Comment argument exceeds maximum number of characters'); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
$this->comment = $comment; |
436
|
|
|
|
437
|
|
|
return $this; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Get track number. |
442
|
|
|
* |
443
|
|
|
* @return int |
444
|
|
|
*/ |
445
|
|
|
public function getTrack() |
446
|
|
|
{ |
447
|
|
|
return $this->track; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Set track number. |
452
|
|
|
* |
453
|
|
|
* @param int $track The track number. |
454
|
|
|
* |
455
|
|
|
* @throws BadMethodCallException An exception is thrown on ID3 v1.0 tags. |
456
|
|
|
* @throws InvalidArgumentException An exception is thrown when the year does not have exactly 2 digits. |
457
|
|
|
* |
458
|
|
|
* @return $this |
459
|
|
|
*/ |
460
|
|
|
public function setTrack($track) |
461
|
|
|
{ |
462
|
|
|
if (Version::VERSION_10 === $this->version) { |
463
|
|
|
throw new BadMethodCallException('Track is not supported in this version'); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
if (preg_match('/^\d{1,2}$/', $track) < 1) { |
467
|
|
|
throw new InvalidArgumentException('Track argument exceeds 2 digits'); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
$this->track = $track; |
471
|
|
|
|
472
|
|
|
return $this; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Get genre number. |
477
|
|
|
* |
478
|
|
|
* @return int |
479
|
|
|
*/ |
480
|
|
|
public function getGenre() |
481
|
|
|
{ |
482
|
|
|
return $this->genre; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Set genre number. |
487
|
|
|
* |
488
|
|
|
* @param int $genre The genre number. |
489
|
|
|
* |
490
|
|
|
* @throws InvalidArgumentException An exception is thrown on invalid genre arguments. |
491
|
|
|
* |
492
|
|
|
* @return $this |
493
|
|
|
*/ |
494
|
|
|
public function setGenre($genre) |
495
|
|
|
{ |
496
|
|
|
if (!in_array($genre, Genre::values())) { |
497
|
|
|
throw new InvalidArgumentException('Invalid genre'); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
$this->genre = $genre; |
501
|
|
|
|
502
|
|
|
return $this; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Get genre as string. |
507
|
|
|
* |
508
|
|
|
* @return string |
509
|
|
|
*/ |
510
|
|
|
public function getGenreAsString() |
511
|
|
|
{ |
512
|
|
|
return static::$genres[$this->genre]; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Set genre from string. |
517
|
|
|
* |
518
|
|
|
* @param string $genre The genre string. |
519
|
|
|
* |
520
|
|
|
* @throws InvalidArgumentException An exception is thrown on invalid genre arguments. |
521
|
|
|
* |
522
|
|
|
* @return $this |
523
|
|
|
*/ |
524
|
|
|
public function setGenreFromString($genre) |
525
|
|
|
{ |
526
|
|
|
return $this->setGenre(array_search($genre, static::$genres, true)); |
|
|
|
|
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.