|
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\ID3v2; |
|
9
|
|
|
|
|
10
|
|
|
use GravityMedia\Metadata\Exception\InvalidArgumentException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* ID3v2 tag class. |
|
14
|
|
|
* |
|
15
|
|
|
* @package GravityMedia\Metadata\ID3v2 |
|
16
|
|
|
*/ |
|
17
|
|
|
class Tag |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var int |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $version; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var int |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $revision; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $padding; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var int |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $crc32; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var int[] |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $restrictions; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Frame[] |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $frames; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create ID3v2 tag object. |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $version The version (default is 3: v2.3) |
|
53
|
|
|
* @param int $revision The revision (default is 0) |
|
54
|
|
|
* |
|
55
|
|
|
* @throws InvalidArgumentException An exception is thrown on invalid version arguments |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct($version = Version::VERSION_23, $revision = 0) |
|
58
|
|
|
{ |
|
59
|
|
|
if (!in_array($version, Version::values(), true)) { |
|
60
|
|
|
throw new InvalidArgumentException('Invalid version.'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->version = $version; |
|
64
|
|
|
$this->revision = $revision; |
|
65
|
|
|
$this->padding = 0; |
|
66
|
|
|
$this->crc32 = 0; |
|
67
|
|
|
$this->restrictions = []; |
|
68
|
|
|
$this->frames = []; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get version. |
|
73
|
|
|
* |
|
74
|
|
|
* @return int |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getVersion() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->version; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get revision. |
|
83
|
|
|
* |
|
84
|
|
|
* @return int |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getRevision() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->revision; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get padding. |
|
93
|
|
|
* |
|
94
|
|
|
* @return int |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getPadding() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->padding; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Set padding. |
|
103
|
|
|
* |
|
104
|
|
|
* @param int $padding |
|
105
|
|
|
* |
|
106
|
|
|
* @return $this |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setPadding($padding) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->padding = $padding; |
|
111
|
|
|
|
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get CRC-32. |
|
117
|
|
|
* |
|
118
|
|
|
* @return int |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getCrc32() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->crc32; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set CRC-32. |
|
127
|
|
|
* |
|
128
|
|
|
* @param int $crc32 |
|
129
|
|
|
* |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setCrc32($crc32) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->crc32 = $crc32; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get restriction. |
|
141
|
|
|
* |
|
142
|
|
|
* @param int $restriction |
|
143
|
|
|
* |
|
144
|
|
|
* @return int |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getRestriction($restriction) |
|
147
|
|
|
{ |
|
148
|
|
|
if (isset($this->restrictions[$restriction])) { |
|
149
|
|
|
return $this->restrictions[$restriction]; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return -1; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set restrictions |
|
157
|
|
|
* |
|
158
|
|
|
* @param int[] $restrictions |
|
159
|
|
|
* |
|
160
|
|
|
* @return $this |
|
161
|
|
|
*/ |
|
162
|
|
|
public function setRestrictions(array $restrictions) |
|
163
|
|
|
{ |
|
164
|
|
|
$this->restrictions = $restrictions; |
|
165
|
|
|
|
|
166
|
|
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get frames |
|
171
|
|
|
* |
|
172
|
|
|
* @return Frame[] |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getFrames() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->frames; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Add frame |
|
181
|
|
|
* |
|
182
|
|
|
* @param Frame $frame |
|
183
|
|
|
* |
|
184
|
|
|
* @return $this |
|
185
|
|
|
*/ |
|
186
|
|
|
public function addFrame(Frame $frame) |
|
187
|
|
|
{ |
|
188
|
|
|
$this->frames[] = $frame; |
|
189
|
|
|
|
|
190
|
|
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|