|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Navarr; |
|
4
|
|
|
|
|
5
|
|
|
use getID3; |
|
6
|
|
|
use getid3_lib; |
|
7
|
|
|
|
|
8
|
|
|
class mp3Data |
|
9
|
|
|
{ |
|
10
|
|
|
protected $getid3; |
|
11
|
|
|
protected $analyzed = false; |
|
12
|
|
|
public $info; |
|
13
|
|
|
protected $error; |
|
14
|
|
|
|
|
15
|
13 |
|
public function __construct($filename = null) |
|
16
|
|
|
{ |
|
17
|
13 |
|
$this->getid3 = new getID3(); |
|
18
|
13 |
|
$this->getid3->encoding = 'UTF-8'; |
|
19
|
13 |
|
$this->error = []; |
|
20
|
13 |
|
if ($filename !== null) { |
|
21
|
13 |
|
$this->analyze($filename); |
|
22
|
13 |
|
} |
|
23
|
13 |
|
} |
|
24
|
|
|
|
|
25
|
13 |
|
public function analyze($filename) |
|
26
|
|
|
{ |
|
27
|
13 |
|
if (!file_exists($filename)) { |
|
28
|
1 |
|
throw new \RuntimeException('File does not exist'); |
|
29
|
|
|
} |
|
30
|
13 |
|
if ($this->getid3->Analyze($filename)) { |
|
31
|
13 |
|
getid3_lib::CopyTagsToComments($this->getid3->info); |
|
32
|
13 |
|
} |
|
33
|
13 |
|
$this->analyzed = true; |
|
34
|
13 |
|
$this->info = $this->getid3->info['comments']; |
|
35
|
|
|
|
|
36
|
13 |
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getArt($id = 0) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->throwErrorIfNotAnalyzed(); |
|
42
|
|
|
|
|
43
|
|
|
if (!isset($this->getid3->info['id3v2']['APIC'][$id]['data'])) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
$img = imagecreatefromstring($this->getid3->info['id3v2']['APIC'][$id]['data']); |
|
47
|
|
|
|
|
48
|
|
|
return $img; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function getArts() |
|
52
|
|
|
{ |
|
53
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
54
|
1 |
|
if (!isset($this->getid3->info['id3v2']['APIC'])) { |
|
55
|
|
|
return []; |
|
56
|
|
|
} |
|
57
|
1 |
|
$ra = []; |
|
58
|
1 |
|
foreach ($this->getid3->info['id3v2']['APIC'] as $v) { |
|
59
|
1 |
|
$ra[] = imagecreatefromstring($v['data']); |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
return $ra; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
public function getInfo() |
|
66
|
|
|
{ |
|
67
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
68
|
|
|
|
|
69
|
1 |
|
return $this->info; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
public function getRawInfo() |
|
73
|
|
|
{ |
|
74
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
75
|
|
|
|
|
76
|
1 |
|
return $this->getid3->info; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
2 |
|
public function getName($id = 0) |
|
80
|
|
|
{ |
|
81
|
2 |
|
$this->throwErrorIfNotAnalyzed(); |
|
82
|
|
|
|
|
83
|
1 |
|
return $this->info['title'][$id]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function getNames() |
|
87
|
|
|
{ |
|
88
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
89
|
|
|
|
|
90
|
1 |
|
return $this->info['title']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
public function getArtist($id = 0) |
|
94
|
|
|
{ |
|
95
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
96
|
|
|
|
|
97
|
1 |
|
return $this->info['artist'][$id]; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
1 |
|
public function getArtists() |
|
101
|
|
|
{ |
|
102
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
103
|
|
|
|
|
104
|
1 |
|
return $this->info['artist']; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
public function getAlbum($id = 0) |
|
108
|
|
|
{ |
|
109
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
110
|
|
|
|
|
111
|
1 |
|
return $this->info['album'][$id]; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
1 |
|
public function getAlbums() |
|
115
|
|
|
{ |
|
116
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
117
|
|
|
|
|
118
|
1 |
|
return $this->info['album']; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function getYear($id = 0) |
|
122
|
|
|
{ |
|
123
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
124
|
|
|
|
|
125
|
1 |
|
return $this->info['year'][$id]; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
1 |
|
public function getYears() |
|
129
|
|
|
{ |
|
130
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
131
|
|
|
|
|
132
|
1 |
|
return $this->info['year']; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
public function getGenre($id = 0) |
|
136
|
|
|
{ |
|
137
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
138
|
|
|
|
|
139
|
1 |
|
return $this->info['genre'][$id]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
1 |
|
public function getGenres() |
|
143
|
|
|
{ |
|
144
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
145
|
|
|
|
|
146
|
1 |
|
return $this->info['genre']; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
1 |
|
public function getTrack($id = 0) |
|
150
|
|
|
{ |
|
151
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
152
|
|
|
|
|
153
|
1 |
|
$info = explode('/', $this->info['track_number'][$id]); |
|
154
|
|
|
|
|
155
|
1 |
|
return $info[0]; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
1 |
|
public function getTotalTracks($id = 0) |
|
159
|
|
|
{ |
|
160
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
161
|
|
|
|
|
162
|
1 |
|
$info = explode('/', $this->info['track_number'][$id]); |
|
163
|
1 |
|
$return = isset($info[1]) ? $info[1] : null; |
|
164
|
|
|
|
|
165
|
1 |
|
return $return; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
1 |
|
public function getTracks() |
|
169
|
|
|
{ |
|
170
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
171
|
|
|
|
|
172
|
1 |
|
return $this->info['track_number']; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
1 |
|
public function getComment($id = 0) |
|
176
|
|
|
{ |
|
177
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
178
|
|
|
|
|
179
|
1 |
|
return $this->info['comment'][$id]; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
1 |
|
public function getComments() |
|
183
|
|
|
{ |
|
184
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
185
|
|
|
|
|
186
|
1 |
|
return $this->info['comment']; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function getLyric($id = 0) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->throwErrorIfNotAnalyzed(); |
|
192
|
|
|
|
|
193
|
|
|
return $this->info['unsynchronised_lyric'][$id]; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function getLyrics() |
|
197
|
|
|
{ |
|
198
|
|
|
$this->throwErrorIfNotAnalyzed(); |
|
199
|
|
|
|
|
200
|
|
|
return $this->info['unsynchronised_lyric']; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
1 |
|
public function getBand($id = 0) |
|
204
|
|
|
{ |
|
205
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
206
|
|
|
|
|
207
|
1 |
|
return $this->info['band'][$id]; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
1 |
|
public function getBands() |
|
211
|
|
|
{ |
|
212
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
213
|
|
|
|
|
214
|
1 |
|
return $this->info['band']; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function getPublisher($id = 0) |
|
218
|
|
|
{ |
|
219
|
|
|
$this->throwErrorIfNotAnalyzed(); |
|
220
|
|
|
|
|
221
|
|
|
return $this->info['publisher'][$id]; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function getPublishers() |
|
225
|
|
|
{ |
|
226
|
|
|
$this->throwErrorIfNotAnalyzed(); |
|
227
|
|
|
|
|
228
|
|
|
return $this->info['publisher']; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
1 |
|
public function getComposer($id = 0) |
|
232
|
|
|
{ |
|
233
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
234
|
|
|
|
|
235
|
1 |
|
return $this->info['composer'][$id]; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
1 |
|
public function getComposers() |
|
239
|
|
|
{ |
|
240
|
1 |
|
$this->throwErrorIfNotAnalyzed(); |
|
241
|
|
|
|
|
242
|
1 |
|
return $this->info['composer']; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
12 |
|
private function throwErrorIfNotAnalyzed() |
|
246
|
|
|
{ |
|
247
|
12 |
|
if ($this->analyzed) { |
|
248
|
11 |
|
return; |
|
249
|
|
|
} |
|
250
|
1 |
|
throw new \RuntimeException('File must be analyzed before attempting to read from it.'); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|