diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
commit | 9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch) | |
tree | 4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/net/shredzone/ifish/ltr/LTR.java | |
parent | dfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff) | |
download | rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.tar.gz rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.zip |
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/net/shredzone/ifish/ltr/LTR.java')
-rw-r--r-- | songdbj/net/shredzone/ifish/ltr/LTR.java | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/songdbj/net/shredzone/ifish/ltr/LTR.java b/songdbj/net/shredzone/ifish/ltr/LTR.java new file mode 100644 index 0000000000..8a38676583 --- /dev/null +++ b/songdbj/net/shredzone/ifish/ltr/LTR.java | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | * iFish -- An iRiver iHP jukebox database creation tool | ||
3 | * | ||
4 | * Copyright (c) 2004 Richard "Shred" Körber | ||
5 | * http://www.shredzone.net/go/ifish | ||
6 | * | ||
7 | *----------------------------------------------------------------------- | ||
8 | * ***** BEGIN LICENSE BLOCK ***** | ||
9 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
10 | * | ||
11 | * The contents of this file are subject to the Mozilla Public License Version | ||
12 | * 1.1 (the "License"); you may not use this file except in compliance with | ||
13 | * the License. You may obtain a copy of the License at | ||
14 | * http://www.mozilla.org/MPL/ | ||
15 | * | ||
16 | * Software distributed under the License is distributed on an "AS IS" basis, | ||
17 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
18 | * for the specific language governing rights and limitations under the | ||
19 | * License. | ||
20 | * | ||
21 | * The Original Code is IFISH. | ||
22 | * | ||
23 | * The Initial Developer of the Original Code is | ||
24 | * Richard "Shred" Körber. | ||
25 | * Portions created by the Initial Developer are Copyright (C) 2004 | ||
26 | * the Initial Developer. All Rights Reserved. | ||
27 | * | ||
28 | * Contributor(s): | ||
29 | * | ||
30 | * Alternatively, the contents of this file may be used under the terms of | ||
31 | * either the GNU General Public License Version 2 or later (the "GPL"), or | ||
32 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
33 | * in which case the provisions of the GPL or the LGPL are applicable instead | ||
34 | * of those above. If you wish to allow use of your version of this file only | ||
35 | * under the terms of either the GPL or the LGPL, and not to allow others to | ||
36 | * use your version of this file under the terms of the MPL, indicate your | ||
37 | * decision by deleting the provisions above and replace them with the notice | ||
38 | * and other provisions required by the GPL or the LGPL. If you do not delete | ||
39 | * the provisions above, a recipient may use your version of this file under | ||
40 | * the terms of any one of the MPL, the GPL or the LGPL. | ||
41 | * | ||
42 | * ***** END LICENSE BLOCK ***** | ||
43 | */ | ||
44 | |||
45 | package net.shredzone.ifish.ltr; | ||
46 | |||
47 | import java.io.*; | ||
48 | |||
49 | /** | ||
50 | * The Base Class for the Lightweight Tag Reader. LTR was made to read | ||
51 | * the basic tag information of MP3 (IDv1, IDv2), Ogg Vorbis and ASF/WMA | ||
52 | * files. It is lightweight because it is optimized for speed, and is | ||
53 | * only able to read the tag information, but unable to edit them. | ||
54 | * | ||
55 | * @author Richard Körber <dev@shredzone.de> | ||
56 | * @version $Id$ | ||
57 | */ | ||
58 | public abstract class LTR { | ||
59 | protected RandomAccessFile in; // The file to be checked | ||
60 | |||
61 | /** | ||
62 | * Create a new LTR object. It is connected to the file to be decoded, | ||
63 | * by a RandomAccessFile. The cursor position will be changed during | ||
64 | * recognizing and decoding. | ||
65 | * | ||
66 | * @param in RandomAccessFile to be used | ||
67 | * @throws FormatDecodeException Description of the Exception | ||
68 | */ | ||
69 | public LTR( RandomAccessFile in ) | ||
70 | throws FormatDecodeException { | ||
71 | this.in = in; | ||
72 | try { | ||
73 | in.seek( 0 ); // To the beginning of file | ||
74 | } catch( IOException e ) { | ||
75 | throw new FormatDecodeException( "couldn't seek: " + e.toString() ); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Create an LTR object for a file. If the file given, was not | ||
81 | * recognized or did not contain any tags, null will be returned. | ||
82 | * | ||
83 | * @param file File to open | ||
84 | * @return LTR to this file, or null | ||
85 | * @exception IOException Description of the Exception | ||
86 | */ | ||
87 | public static LTR create( File file ) { | ||
88 | RandomAccessFile in = null; | ||
89 | LTR result = null; | ||
90 | |||
91 | try { | ||
92 | in = new RandomAccessFile( file, "r" ); | ||
93 | |||
94 | try { | ||
95 | result = new TagOggVorbis( in ); | ||
96 | return result; | ||
97 | } catch( FormatDecodeException e ) {} | ||
98 | |||
99 | try { | ||
100 | result = new TagMp3v2( in ); | ||
101 | return result; | ||
102 | } catch( FormatDecodeException e ) {} | ||
103 | |||
104 | try { | ||
105 | result = new TagMp3v200( in ); | ||
106 | return result; | ||
107 | } catch( FormatDecodeException e ) {} | ||
108 | |||
109 | try { | ||
110 | result = new TagAsf( in, file ); | ||
111 | return result; | ||
112 | }catch( FormatDecodeException e ) {} | ||
113 | |||
114 | try { | ||
115 | // Always check ID3v1 *after* ID3v2, because a lot of ID3v2 | ||
116 | // files also contain ID3v1 tags with limited content. | ||
117 | result = new TagMp3v1( in ); | ||
118 | return result; | ||
119 | } catch( FormatDecodeException e ) {} | ||
120 | }catch(IOException e) { | ||
121 | return null; | ||
122 | } finally { | ||
123 | try { | ||
124 | if( in!=null ) in.close(); | ||
125 | } catch(IOException e) { | ||
126 | System.out.println("Failed to close file."); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return null; | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Get the type of this file. This is usually the compression format | ||
135 | * itself (e.g. "OGG" or "MP3"). If there are different taggings for | ||
136 | * this format, the used tag format is appended after a slash (e.g. | ||
137 | * "MP3/id3v2"). | ||
138 | * | ||
139 | * @return The type | ||
140 | */ | ||
141 | public abstract String getType(); | ||
142 | |||
143 | /** | ||
144 | * Get the artist. | ||
145 | * | ||
146 | * @return The artist (never null) | ||
147 | */ | ||
148 | public abstract String getArtist(); | ||
149 | |||
150 | /** | ||
151 | * Get the album. | ||
152 | * | ||
153 | * @return The album (never null) | ||
154 | */ | ||
155 | public abstract String getAlbum(); | ||
156 | |||
157 | /** | ||
158 | * Get the title. | ||
159 | * | ||
160 | * @return The title (never null) | ||
161 | */ | ||
162 | public abstract String getTitle(); | ||
163 | |||
164 | /** | ||
165 | * Get the genre. | ||
166 | * | ||
167 | * @return The genre (never null) | ||
168 | */ | ||
169 | public abstract String getGenre(); | ||
170 | |||
171 | /** | ||
172 | * Get the year. | ||
173 | * | ||
174 | * @return The year (never null) | ||
175 | */ | ||
176 | public abstract String getYear(); | ||
177 | |||
178 | /** | ||
179 | * Get the comment. | ||
180 | * | ||
181 | * @return The comment (never null) | ||
182 | */ | ||
183 | public abstract String getComment(); | ||
184 | |||
185 | /** | ||
186 | * Get the track. | ||
187 | * | ||
188 | * @return The track (never null) | ||
189 | */ | ||
190 | public abstract String getTrack(); | ||
191 | |||
192 | /** | ||
193 | * Read a String of a certain length from the file. It will always use | ||
194 | * "ISO-8859-1" encoding! | ||
195 | * | ||
196 | * @param length Maximum number of bytes to read | ||
197 | * @return String that was read | ||
198 | * @throws IOException If EOF was already reached | ||
199 | */ | ||
200 | protected String readStringLen( int length ) | ||
201 | throws IOException { | ||
202 | return readStringLen( length, "ISO-8859-1" ); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * Read a String of a certain length from the file. The length will | ||
207 | * not be exceeded. No null termination is required. Anyhow an | ||
208 | * IOException will be thrown if the EOF was reached before invocation. | ||
209 | * | ||
210 | * @param length Maximum number of bytes to read | ||
211 | * @param charset Charset to be used | ||
212 | * @return String that was read | ||
213 | * @throws IOException If EOF was already reached | ||
214 | */ | ||
215 | protected String readStringLen( int length, String charset ) | ||
216 | throws IOException { | ||
217 | byte[] buf = new byte[length]; | ||
218 | int readlength = in.read( buf ); | ||
219 | if( readlength < 0 ) { | ||
220 | throw new IOException( "Unexpected EOF" ); | ||
221 | } | ||
222 | return new String( buf, 0, readlength, charset ); | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * Return a string representation of the LTR content. | ||
227 | * | ||
228 | * @return String representation | ||
229 | */ | ||
230 | public String toString() { | ||
231 | StringBuffer buff = new StringBuffer(); | ||
232 | buff.append( getType() ); | ||
233 | buff.append( "[ART='" ); | ||
234 | buff.append( getArtist() ); | ||
235 | buff.append( "' ALB='" ); | ||
236 | buff.append( getAlbum() ); | ||
237 | buff.append( "' TIT='" ); | ||
238 | buff.append( getTitle() ); | ||
239 | buff.append( "' TRK='" ); | ||
240 | buff.append( getTrack() ); | ||
241 | buff.append( "' GEN='" ); | ||
242 | buff.append( getGenre() ); | ||
243 | buff.append( "' YR='" ); | ||
244 | buff.append( getYear() ); | ||
245 | buff.append( "' CMT='" ); | ||
246 | buff.append( getComment() ); | ||
247 | buff.append( "']" ); | ||
248 | return buff.toString(); | ||
249 | } | ||
250 | |||
251 | } | ||