diff options
Diffstat (limited to 'songdbj/MpegInfo.java')
-rw-r--r-- | songdbj/MpegInfo.java | 367 |
1 files changed, 0 insertions, 367 deletions
diff --git a/songdbj/MpegInfo.java b/songdbj/MpegInfo.java deleted file mode 100644 index 6f57879883..0000000000 --- a/songdbj/MpegInfo.java +++ /dev/null | |||
@@ -1,367 +0,0 @@ | |||
1 | /* | ||
2 | * MpegInfo. | ||
3 | * | ||
4 | * JavaZOOM : jlgui@javazoom.net | ||
5 | * http://www.javazoom.net | ||
6 | * | ||
7 | *----------------------------------------------------------------------- | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Library General Public License as published | ||
10 | * by the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU Library General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Library General Public | ||
19 | * License along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | *---------------------------------------------------------------------- | ||
22 | */ | ||
23 | |||
24 | import java.io.File; | ||
25 | import java.io.IOException; | ||
26 | import java.io.InputStream; | ||
27 | import java.net.URL; | ||
28 | import java.util.Iterator; | ||
29 | import java.util.Map; | ||
30 | import java.util.Vector; | ||
31 | import java.io.FileInputStream; | ||
32 | import java.io.BufferedInputStream; | ||
33 | import javax.sound.sampled.AudioFileFormat; | ||
34 | import javax.sound.sampled.AudioSystem; | ||
35 | import javax.sound.sampled.UnsupportedAudioFileException; | ||
36 | |||
37 | import org.tritonus.share.sampled.file.TAudioFileFormat; | ||
38 | |||
39 | /** | ||
40 | * This class gives information (audio format and comments) about MPEG file or URL. | ||
41 | */ | ||
42 | public class MpegInfo implements TagInfo | ||
43 | { | ||
44 | protected int channels = -1; | ||
45 | protected String channelsMode = null; | ||
46 | protected String version = null; | ||
47 | protected int rate = 0; | ||
48 | protected String layer = null; | ||
49 | protected String emphasis = null; | ||
50 | protected int nominalbitrate = 0; | ||
51 | protected long total = 0; | ||
52 | protected String vendor = null; | ||
53 | protected String location = null; | ||
54 | protected long size = 0; | ||
55 | protected boolean copyright = false; | ||
56 | protected boolean crc = false; | ||
57 | protected boolean original = false; | ||
58 | protected boolean priv = false; | ||
59 | protected boolean vbr = false; | ||
60 | protected int track = -1; | ||
61 | protected int offset = 0; | ||
62 | protected String year = null; | ||
63 | protected String genre = null; | ||
64 | protected String title = null; | ||
65 | protected String artist = null; | ||
66 | protected String album = null; | ||
67 | protected Vector comments = null; | ||
68 | |||
69 | /** | ||
70 | * Constructor. | ||
71 | */ | ||
72 | public MpegInfo() | ||
73 | { | ||
74 | super(); | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Load and parse MPEG info from File. | ||
79 | * @param input | ||
80 | * @throws IOException | ||
81 | */ | ||
82 | public void load(File input) throws IOException, UnsupportedAudioFileException | ||
83 | { | ||
84 | size = input.length(); | ||
85 | location = input.getPath(); | ||
86 | loadInfo(input); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * Load and parse MPEG info from URL. | ||
91 | * @param input | ||
92 | * @throws IOException | ||
93 | * @throws UnsupportedAudioFileException | ||
94 | */ | ||
95 | public void load(URL input) throws IOException, UnsupportedAudioFileException | ||
96 | { | ||
97 | location = input.toString(); | ||
98 | loadInfo(input); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Load and parse MPEG info from InputStream. | ||
103 | * @param input | ||
104 | * @throws IOException | ||
105 | * @throws UnsupportedAudioFileException | ||
106 | */ | ||
107 | public void load(InputStream input) throws IOException, UnsupportedAudioFileException | ||
108 | { | ||
109 | loadInfo(input); | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * Load info from input stream. | ||
114 | * @param input | ||
115 | * @throws IOException | ||
116 | * @throws UnsupportedAudioFileException | ||
117 | */ | ||
118 | protected void loadInfo(InputStream input) throws IOException, UnsupportedAudioFileException | ||
119 | { | ||
120 | AudioFileFormat aff = AudioSystem.getAudioFileFormat(input); | ||
121 | loadInfo(aff); | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * Load MP3 info from file. | ||
126 | * @param file | ||
127 | * @throws IOException | ||
128 | * @throws UnsupportedAudioFileException | ||
129 | */ | ||
130 | protected void loadInfo(File file) throws IOException, UnsupportedAudioFileException | ||
131 | { | ||
132 | InputStream in = new BufferedInputStream(new FileInputStream(file)); | ||
133 | loadInfo(in); | ||
134 | in.close(); | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * Load info from AudioFileFormat. | ||
139 | * @param aff | ||
140 | */ | ||
141 | protected void loadInfo(AudioFileFormat aff) throws UnsupportedAudioFileException | ||
142 | { | ||
143 | String type = aff.getType().toString(); | ||
144 | if (!type.equalsIgnoreCase("mp3")) throw new UnsupportedAudioFileException("Not MP3 audio format"); | ||
145 | if (aff instanceof TAudioFileFormat) | ||
146 | { | ||
147 | Map props = ((TAudioFileFormat) aff).properties(); | ||
148 | if (props.containsKey("mp3.channels")) channels = ((Integer)props.get("mp3.channels")).intValue(); | ||
149 | if (props.containsKey("mp3.frequency.hz")) rate = ((Integer)props.get("mp3.frequency.hz")).intValue(); | ||
150 | if (props.containsKey("mp3.bitrate.nominal.bps")) nominalbitrate = ((Integer)props.get("mp3.bitrate.nominal.bps")).intValue(); | ||
151 | if (props.containsKey("mp3.version.layer")) layer = "Layer "+(String)props.get("mp3.version.layer"); | ||
152 | if (props.containsKey("mp3.version.mpeg")) | ||
153 | { | ||
154 | version = (String)props.get("mp3.version.mpeg"); | ||
155 | if (version.equals("1")) version = "MPEG1"; | ||
156 | else if (version.equals("2")) version = "MPEG2-LSF"; | ||
157 | else if (version.equals("2.5")) version = "MPEG2.5-LSF"; | ||
158 | } | ||
159 | if (props.containsKey("mp3.mode")) | ||
160 | { | ||
161 | int mode = ((Integer)props.get("mp3.mode")).intValue(); | ||
162 | if (mode==0) channelsMode = "Stereo"; | ||
163 | else if (mode==1) channelsMode = "Joint Stereo"; | ||
164 | else if (mode==2) channelsMode = "Dual Channel"; | ||
165 | else if (mode==3) channelsMode = "Single Channel"; | ||
166 | } | ||
167 | if (props.containsKey("mp3.crc")) crc = ((Boolean)props.get("mp3.crc")).booleanValue(); | ||
168 | if (props.containsKey("mp3.vbr")) vbr = ((Boolean)props.get("mp3.vbr")).booleanValue(); | ||
169 | if (props.containsKey("mp3.copyright")) copyright = ((Boolean)props.get("mp3.copyright")).booleanValue(); | ||
170 | if (props.containsKey("mp3.original")) original = ((Boolean)props.get("mp3.original")).booleanValue(); | ||
171 | emphasis="none"; | ||
172 | |||
173 | if (props.containsKey("title")) title = (String)props.get("title"); | ||
174 | if (props.containsKey("author")) artist = (String)props.get("author"); | ||
175 | if (props.containsKey("album")) album = (String)props.get("album"); | ||
176 | if (props.containsKey("date")) year = (String)props.get("date"); | ||
177 | if (props.containsKey("duration")) total = (long) Math.round((((Long)props.get("duration")).longValue())/1000000); | ||
178 | if (props.containsKey("mp3.id3tag.genre")) genre = (String)props.get("mp3.id3tag.genre"); | ||
179 | |||
180 | if (props.containsKey("mp3.header.pos")) { | ||
181 | offset = ((Integer)props.get("mp3.header.pos")).intValue(); | ||
182 | } | ||
183 | else | ||
184 | offset = 0; | ||
185 | if (props.containsKey("mp3.id3tag.track")) | ||
186 | { | ||
187 | try | ||
188 | { | ||
189 | track = Integer.parseInt((String)props.get("mp3.id3tag.track")); | ||
190 | } | ||
191 | catch (NumberFormatException e1) | ||
192 | { | ||
193 | // Not a number | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Load MP3 info from URL. | ||
201 | * @param input | ||
202 | * @throws IOException | ||
203 | * @throws UnsupportedAudioFileException | ||
204 | */ | ||
205 | protected void loadInfo(URL input) throws IOException, UnsupportedAudioFileException | ||
206 | { | ||
207 | AudioFileFormat aff = AudioSystem.getAudioFileFormat(input); | ||
208 | loadInfo(aff); | ||
209 | loadShoutastInfo(aff); | ||
210 | } | ||
211 | |||
212 | /** | ||
213 | * Load Shoutcast info from AudioFileFormat. | ||
214 | * @param aff | ||
215 | * @throws IOException | ||
216 | * @throws UnsupportedAudioFileException | ||
217 | */ | ||
218 | protected void loadShoutastInfo(AudioFileFormat aff) throws IOException, UnsupportedAudioFileException | ||
219 | { | ||
220 | String type = aff.getType().toString(); | ||
221 | if (!type.equalsIgnoreCase("mp3")) throw new UnsupportedAudioFileException("Not MP3 audio format"); | ||
222 | if (aff instanceof TAudioFileFormat) | ||
223 | { | ||
224 | Map props = ((TAudioFileFormat) aff).properties(); | ||
225 | // Try shoutcast meta data (if any). | ||
226 | Iterator it = props.keySet().iterator(); | ||
227 | comments = new Vector(); | ||
228 | while (it.hasNext()) | ||
229 | { | ||
230 | String key = (String) it.next(); | ||
231 | if (key.startsWith("mp3.shoutcast.metadata.")) | ||
232 | { | ||
233 | String value = (String) props.get(key); | ||
234 | key = key.substring(23,key.length()); | ||
235 | if (key.equalsIgnoreCase("icy-name")) | ||
236 | { | ||
237 | title = value; | ||
238 | } | ||
239 | else if (key.equalsIgnoreCase("icy-genre")) | ||
240 | { | ||
241 | genre = value; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | comments.add(key+"="+value); | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | public boolean getVBR() | ||
253 | { | ||
254 | return vbr; | ||
255 | } | ||
256 | |||
257 | public int getChannels() | ||
258 | { | ||
259 | return channels; | ||
260 | } | ||
261 | |||
262 | public String getVersion() | ||
263 | { | ||
264 | return version; | ||
265 | } | ||
266 | |||
267 | public String getEmphasis() | ||
268 | { | ||
269 | return emphasis; | ||
270 | } | ||
271 | |||
272 | public boolean getCopyright() | ||
273 | { | ||
274 | return copyright; | ||
275 | } | ||
276 | |||
277 | public boolean getCRC() | ||
278 | { | ||
279 | return crc; | ||
280 | } | ||
281 | |||
282 | public boolean getOriginal() | ||
283 | { | ||
284 | return original; | ||
285 | } | ||
286 | |||
287 | public String getLayer() | ||
288 | { | ||
289 | return layer; | ||
290 | } | ||
291 | |||
292 | public long getSize() | ||
293 | { | ||
294 | return size; | ||
295 | } | ||
296 | |||
297 | public String getLocation() | ||
298 | { | ||
299 | return location; | ||
300 | } | ||
301 | |||
302 | /*-- TagInfo Implementation --*/ | ||
303 | |||
304 | public int getSamplingRate() | ||
305 | { | ||
306 | return rate; | ||
307 | } | ||
308 | |||
309 | public int getBitRate() | ||
310 | { | ||
311 | return nominalbitrate; | ||
312 | } | ||
313 | |||
314 | public long getPlayTime() | ||
315 | { | ||
316 | return total; | ||
317 | } | ||
318 | |||
319 | public String getTitle() | ||
320 | { | ||
321 | return title; | ||
322 | } | ||
323 | |||
324 | public String getArtist() | ||
325 | { | ||
326 | return artist; | ||
327 | } | ||
328 | |||
329 | public String getAlbum() | ||
330 | { | ||
331 | return album; | ||
332 | } | ||
333 | |||
334 | public int getTrack() | ||
335 | { | ||
336 | return track; | ||
337 | } | ||
338 | |||
339 | public String getGenre() | ||
340 | { | ||
341 | return genre; | ||
342 | } | ||
343 | |||
344 | public Vector getComment() | ||
345 | { | ||
346 | return comments; | ||
347 | } | ||
348 | |||
349 | public String getYear() | ||
350 | { | ||
351 | return year; | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Get channels mode. | ||
356 | * @return | ||
357 | */ | ||
358 | public String getChannelsMode() | ||
359 | { | ||
360 | return channelsMode; | ||
361 | } | ||
362 | |||
363 | public int getFirstFrameOffset() { | ||
364 | return offset; | ||
365 | } | ||
366 | |||
367 | } \ No newline at end of file | ||