| 1 |
/* |
|---|
| 2 |
* LastPod is an application used to publish one's iPod play counts to Last.fm. |
|---|
| 3 |
* Copyright (C) 2007 Chris Tilden |
|---|
| 4 |
* |
|---|
| 5 |
* This program is free software; you can redistribute it and/or |
|---|
| 6 |
* modify it under the terms of the GNU General Public License |
|---|
| 7 |
* as published by the Free Software Foundation; either version 2 |
|---|
| 8 |
* of the License, or (at your option) any later version. |
|---|
| 9 |
* |
|---|
| 10 |
* This program is distributed in the hope that it will be useful, |
|---|
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 |
* GNU General Public License for more details. |
|---|
| 14 |
* |
|---|
| 15 |
* You should have received a copy of the GNU General Public License |
|---|
| 16 |
* along with this program; if not, write to the Free Software |
|---|
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 18 |
*/ |
|---|
| 19 |
package org.lastpod; |
|---|
| 20 |
|
|---|
| 21 |
import java.util.Date; |
|---|
| 22 |
|
|---|
| 23 |
/** |
|---|
| 24 |
* @author muti |
|---|
| 25 |
* @version $Id$ |
|---|
| 26 |
*/ |
|---|
| 27 |
public class TrackItem implements Comparable { |
|---|
| 28 |
private long trackid; |
|---|
| 29 |
private Boolean active; |
|---|
| 30 |
private long length; //in seconds |
|---|
| 31 |
private String artist; |
|---|
| 32 |
private String album; |
|---|
| 33 |
private String track; |
|---|
| 34 |
private long playcount; |
|---|
| 35 |
private long lastplayed; |
|---|
| 36 |
private boolean parseVariousArtists; |
|---|
| 37 |
|
|---|
| 38 |
/** |
|---|
| 39 |
* Default constructor |
|---|
| 40 |
*/ |
|---|
| 41 |
public TrackItem() { |
|---|
| 42 |
this.trackid = 0; |
|---|
| 43 |
this.active = new Boolean(true); |
|---|
| 44 |
this.length = 0; |
|---|
| 45 |
this.artist = ""; |
|---|
| 46 |
this.album = ""; |
|---|
| 47 |
this.track = ""; |
|---|
| 48 |
this.playcount = 0; |
|---|
| 49 |
this.lastplayed = 0; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
/** |
|---|
| 53 |
* If <code>true</code>; sets this track to be submitted, otherwise do not |
|---|
| 54 |
* submit. |
|---|
| 55 |
* @return Returns <code>true</code> if this track should be submitted. |
|---|
| 56 |
*/ |
|---|
| 57 |
public Boolean isActive() { |
|---|
| 58 |
return active; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
/** |
|---|
| 62 |
* If <code>true</code>; sets this track to be submitted, otherwise do not |
|---|
| 63 |
* submit. |
|---|
| 64 |
* @param active <code>true</code> if this track should be submitted. |
|---|
| 65 |
*/ |
|---|
| 66 |
public void setActive(Boolean active) { |
|---|
| 67 |
this.active = active; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
/** |
|---|
| 71 |
* @return Returns the album. |
|---|
| 72 |
*/ |
|---|
| 73 |
public String getAlbum() { |
|---|
| 74 |
return album; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
/** |
|---|
| 78 |
* @param album The album to set. |
|---|
| 79 |
*/ |
|---|
| 80 |
public void setAlbum(String album) { |
|---|
| 81 |
this.album = album; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
/** |
|---|
| 85 |
* Gets the artist of this track. |
|---|
| 86 |
* @return Returns the artist. |
|---|
| 87 |
*/ |
|---|
| 88 |
public String getArtist() { |
|---|
| 89 |
/* If required parse the track String to obtain the proper artist. */ |
|---|
| 90 |
if (isVariousArtistAlbum(parseVariousArtists)) { |
|---|
| 91 |
return track.split("-")[0].trim(); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
return artist; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
/** |
|---|
| 98 |
* Returns <code>true</code> if this track belongs to a "Various Artist" |
|---|
| 99 |
* album. |
|---|
| 100 |
* @param parseVariousArtists <code>true</code> Will cause the track to be |
|---|
| 101 |
* checked to see if it is a "Various Artist" track. If so, the artist |
|---|
| 102 |
* information will be parsed from the track title. |
|---|
| 103 |
* @return <code>true</code> if this is a "Various Artist" album. |
|---|
| 104 |
*/ |
|---|
| 105 |
public boolean isVariousArtistAlbum(boolean parseVariousArtists) { |
|---|
| 106 |
/* Returns false if "Various Artist" tracks should not be parsed. */ |
|---|
| 107 |
if (!parseVariousArtists) { |
|---|
| 108 |
return false; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
/* In addition to other checks, this makes sure the track is not null, |
|---|
| 112 |
* because track will need to be parsed. */ |
|---|
| 113 |
return (track != null) && (artist != null) |
|---|
| 114 |
&& artist.trim().toLowerCase().equals("various artists"); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
/** |
|---|
| 118 |
* @param artist The artist to set. |
|---|
| 119 |
*/ |
|---|
| 120 |
public void setArtist(String artist) { |
|---|
| 121 |
this.artist = artist; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
/** |
|---|
| 125 |
* @return Returns the lastplayed. |
|---|
| 126 |
*/ |
|---|
| 127 |
public long getLastplayed() { |
|---|
| 128 |
return lastplayed; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
/** |
|---|
| 132 |
* @param lastplayed UNIX timestamp, in seconds. |
|---|
| 133 |
*/ |
|---|
| 134 |
public void setLastplayed(long lastplayed) { |
|---|
| 135 |
this.lastplayed = lastplayed; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
/** |
|---|
| 139 |
* @return Returns the length. |
|---|
| 140 |
*/ |
|---|
| 141 |
public long getLength() { |
|---|
| 142 |
return length; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
/** |
|---|
| 146 |
* @param length The length to set. |
|---|
| 147 |
*/ |
|---|
| 148 |
public void setLength(long length) { |
|---|
| 149 |
this.length = length; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
/** |
|---|
| 153 |
* @return Returns the playcount. |
|---|
| 154 |
*/ |
|---|
| 155 |
public long getPlaycount() { |
|---|
| 156 |
return playcount; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
/** |
|---|
| 160 |
* @param playcount The playcount to set. |
|---|
| 161 |
*/ |
|---|
| 162 |
public void setPlaycount(long playcount) { |
|---|
| 163 |
this.playcount = playcount; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
/** |
|---|
| 167 |
* Gets the track name of the track. |
|---|
| 168 |
* @return Returns the track. |
|---|
| 169 |
*/ |
|---|
| 170 |
public String getTrack() { |
|---|
| 171 |
/* If required parse the track String to obtain the proper track. */ |
|---|
| 172 |
if (isVariousArtistAlbum(parseVariousArtists)) { |
|---|
| 173 |
return track.split("-")[1].trim(); |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
return track; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
/** |
|---|
| 180 |
* @param track The track to set. |
|---|
| 181 |
*/ |
|---|
| 182 |
public void setTrack(String track) { |
|---|
| 183 |
this.track = track; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
/** |
|---|
| 187 |
* @return Returns the trackid. |
|---|
| 188 |
*/ |
|---|
| 189 |
public long getTrackid() { |
|---|
| 190 |
return trackid; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
/** |
|---|
| 194 |
* @param trackid The trackid to set. |
|---|
| 195 |
*/ |
|---|
| 196 |
public void setTrackid(long trackid) { |
|---|
| 197 |
this.trackid = trackid; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
/** |
|---|
| 201 |
* Returns <code>true</code> if the track should be parsed for "Various |
|---|
| 202 |
* Artists". |
|---|
| 203 |
* @return Returns <code>true</code> if the track should be parsed for |
|---|
| 204 |
* "Various Artists". |
|---|
| 205 |
*/ |
|---|
| 206 |
public boolean isParseVariousArtists() { |
|---|
| 207 |
return parseVariousArtists; |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
/** |
|---|
| 211 |
* Set this to <code>true</code> if the track should be parsed for "Various |
|---|
| 212 |
* Artists". |
|---|
| 213 |
* @param parseVariousArtists <code>true</code> Will cause the track to be |
|---|
| 214 |
* checked to see if it is a "Various Artist" track. If so, the artist |
|---|
| 215 |
* information will be parsed from the track title. |
|---|
| 216 |
*/ |
|---|
| 217 |
public void setParseVariousArtists(boolean parseVariousArtists) { |
|---|
| 218 |
this.parseVariousArtists = parseVariousArtists; |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
public int compareTo(Object trackItem) { |
|---|
| 222 |
TrackItem temptrack = (TrackItem) trackItem; |
|---|
| 223 |
|
|---|
| 224 |
if (this.lastplayed < temptrack.getLastplayed()) { |
|---|
| 225 |
return -1; |
|---|
| 226 |
} else if (this.lastplayed > temptrack.getLastplayed()) { |
|---|
| 227 |
return 1; |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
return 0; |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
public String toString() { |
|---|
| 234 |
String tempstring; |
|---|
| 235 |
|
|---|
| 236 |
tempstring = "Track ID: " + trackid + "\n"; |
|---|
| 237 |
tempstring += ("Length: " + length + "\n"); |
|---|
| 238 |
tempstring += ("Artist: " + getArtist() + "\n"); |
|---|
| 239 |
tempstring += ("Album: " + album + "\n"); |
|---|
| 240 |
tempstring += ("Track: " + getTrack() + "\n"); |
|---|
| 241 |
tempstring += ("Play Count: " + playcount + "\n"); |
|---|
| 242 |
tempstring += ("Last Played: " + new Date(lastplayed * 1000) + "\n"); |
|---|
| 243 |
|
|---|
| 244 |
return tempstring; |
|---|
| 245 |
} |
|---|
| 246 |
} |
|---|