Source code: entagged/freedb/FreeDBReadResult.java
1 /*
2 * ******************************************************************** **
3 * Copyright notice **
4 * ** **
5 * (c) 2003 Entagged Developpement Team **
6 * http://www.sourceforge.net/projects/entagged **
7 * ** **
8 * All rights reserved **
9 * ** **
10 * This script is part of the Entagged project. The Entagged **
11 * project is free software; you can redistribute it and/or modify **
12 * it under the terms of the GNU General Public License as published by **
13 * the Free Software Foundation; either version 2 of the License, or **
14 * (at your option) any later version. **
15 * ** **
16 * The GNU General Public License can be found at **
17 * http://www.gnu.org/copyleft/gpl.html. **
18 * ** **
19 * This copyright notice MUST APPEAR in all copies of the file! **
20 * ********************************************************************
21 */
22 package entagged.freedb;
23 import entagged.common.*;
24 import entagged.formats.mp3.*;
25 import entagged.gui.*;
26
27 import java.util.*;
28
29
30 /**
31 * Represent a freedb server Read result and defines method to access the data
32 * collected $Id: FreeDBReadResult.java,v 1.3 2003/09/22 14:20:45 kikidonk Exp
33 * $
34 *
35 * @author Raphael Slinckx (KiKiDonK)
36 * @version v0.03
37 */
38 public class FreeDBReadResult {
39
40 /** Holds the ID3 Genre of this result */
41 private String DGENRE;
42
43 /** Holds the freedb Disc ID of this result */
44 private String DISCID;
45
46 /** Holds the Year of this result */
47 private String DYEAR;
48
49 /** Holds the Extended data of this result */
50 private String EXTD;
51
52 /** Holds an array of extended comments for each track of this result */
53 private String[] EXTT;
54
55 /** Holds the Play order of this result */
56 private String PLAYORDER;
57
58 /** Holds an array of track titles for each track of this result */
59 private String[] TITLE;
60
61 /** Holds the Album of this result */
62 private String album;
63
64 /** Holds the Artist of this result */
65 private String artist;
66
67 /** Contains the total number of tracks in this Read result */
68 private int totalTracks;
69
70
71 /**
72 * Creates a Read result object
73 *
74 * @param fields the array containing the fields needed to complete this read
75 * result
76 */
77 public FreeDBReadResult( Object[] fields ) {
78 DISCID = (String)fields[0];
79
80 String DTITLE = (String)fields[1];
81 StringTokenizer st = new StringTokenizer( DTITLE, "/" );
82 if ( st.countTokens() == 2 ) {
83 artist = st.nextToken();
84 album = st.nextToken();
85 }
86 else {
87 artist = "Error";
88 album = "Error";
89 }
90
91 DYEAR = (String)fields[2];
92 DGENRE = (String)fields[3];
93 EXTD = (String)fields[4];
94 PLAYORDER = (String)fields[5];
95
96 TITLE = (String[])fields[6];
97 EXTT = (String[])fields[7];
98
99 totalTracks = TITLE.length;
100 }
101
102
103 /**
104 * Gets the album attribute of the FreeDBReadResult object
105 *
106 * @return The album value
107 */
108 public String getAlbum() {
109 return album;
110 }
111
112
113 /**
114 * Gets the artist attribute of the FreeDBReadResult object
115 *
116 * @return The artist value
117 */
118 public String getArtist() {
119 return artist;
120 }
121
122
123 /**
124 * Gets the extendedCDData attribute of the FreeDBReadResult object
125 *
126 * @return The extendedCDData value
127 */
128 public String getExtendedCDData() {
129 return EXTD;
130 }
131
132
133 /**
134 * Gets the extendedTracksData attribute of the FreeDBReadResult object
135 *
136 * @return The extendedTracksData array
137 */
138 public String[] getExtendedTracksData() {
139 return EXTT;
140 }
141
142
143 /**
144 * Gets the given formatted TrackNumber
145 *
146 * @param i the given track number as an integer
147 * @return the given formatted track number as a string
148 */
149 public String getFormattedTrackNumber( int i ) {
150 return Utils.formatTrackNumber( new Integer( i ).intValue(), totalTracks, Entagged.guiPrefs.get( "tageditor.singletrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.totaltrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.trackpattern", "%1" ) );
151 }
152
153
154 /**
155 * Gets the genre attribute of the FreeDBReadResult object
156 *
157 * @return The genre value
158 */
159 public String getGenre() {
160 return DGENRE;
161 }
162
163
164 /**
165 * Gets the iD attribute of the FreeDBReadResult object
166 *
167 * @return The iD value
168 */
169 public String getID() {
170 return DISCID;
171 }
172
173
174 /**
175 * Gets the iD3v1Tag attribute of the FreeDBReadResult object
176 *
177 * @param i the index of the track
178 * @return The iD3v1Tag value
179 */
180 public ID3v1Tag getID3v1Tag( int i ) {
181 String v1Genre = Utils.translateGenre( DGENRE );
182 if ( v1Genre == null )
183 v1Genre = Utils.EMPTY_INDEX;
184 String[] fields = {TITLE[i], artist, album, DYEAR, EXTD, ( new Integer( i + 1 ) ).toString(), v1Genre};
185 return new ID3v1Tag( fields );
186 }
187
188
189 /**
190 * Gets the iD3v2Tag attribute of the FreeDBReadResult object
191 *
192 * @param i the index of the track
193 * @return The iD3v2Tag value
194 */
195 public ID3v2Tag getID3v2Tag( int i ) {
196 String[] fields = Utils.STANDARD_ID3_FIELDS;
197 String trackNumber = Utils.formatTrackNumber( new Integer( i + 1 ).intValue(), totalTracks, Entagged.guiPrefs.get( "tageditor.singletrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.totaltrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.trackpattern", "%1" ) );
198 //System.out.println( trackNumber );
199 String[] contents = {TITLE[i], artist, album, DYEAR, EXTD, trackNumber, DGENRE};
200
201 int length = 10;
202 length += fields.length * 10;
203 for ( int j = 0; j < fields.length; j++ )
204 length += contents[j].length() + 1;
205
206 return new ID3v2Tag( fields, contents );//Size to be COMPLETED
207 }
208
209
210 /**
211 * Gets the given track Number
212 *
213 * @param i the given track number as an integer
214 * @return the given track number as a string
215 */
216 public String getTrackNumber( int i ) {
217 return new Integer( i ).toString();
218 }
219
220
221 /**
222 * Gets the tracksTitle attribute of the FreeDBReadResult object
223 *
224 * @return The tracksTitle array
225 */
226 public String[] getTracksTitle() {
227 return TITLE;
228 }
229
230
231 /**
232 * Gets the year attribute of the FreeDBReadResult object
233 *
234 * @return The year value
235 */
236 public String getYear() {
237 return DYEAR;
238 }
239
240
241 /**
242 * Create a string representation of this result
243 *
244 * @return a string representation of this result
245 */
246 public String toString() {
247 String output = "---Free DB Read Result-----------------------\n";
248 output += "Artiste: " + artist + "\tAlbum: " + album + "\n";
249 output += "Disc ID: " + DISCID + "\tExt.DiscInfo: " + EXTD + "\n";
250 output += "Année: " + DYEAR + "\tGenre: " + DGENRE + "\n";
251 output += totalTracks + " Tracks total: \n";
252 for ( int i = 0; i < TITLE.length; i++ )
253 output += "\tTrack " + i + ": " + TITLE[i] + "\tExt.Trackinfo: " + EXTT[i] + "\n";
254 output += "----------------------------------------";
255 return output;
256 }
257 }
258