root/trunk/src/main/org/lastpod/TrackItem.java

Revision 79, 7.2 kB (checked in by chris, 3 years ago)

r7798@flan: chris | 2007-06-16 00:35:49 -0700
Completes trac ticket #16:
Multi-play track submissions


So iSproggler will submit the multi-plays for tracks, and I wondered
how that was possible.


It detects the number of plays for a track, and simply submits it some
n times with a small time offset to not trigger spam protection. Not
ideal, but since the iPod db only stores last play and number of
plays, the best solution currently possible I'd think without
seriously hacking the db, and thus the iPod software.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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      * Constructs a new TrackItem based off the given one.
54      * @param trackItem  The TrackItem to effectively clone.
55      */
56     public TrackItem(TrackItem trackItem) {
57         super();
58         this.setTrackid(trackItem.getTrackid());
59         this.setActive(trackItem.isActive());
60         this.setLength(trackItem.getLength());
61         this.setArtist(trackItem.getArtist());
62         this.setAlbum(trackItem.getAlbum());
63         this.setTrack(trackItem.getTrack());
64         this.setPlaycount(trackItem.getPlaycount());
65         this.setLastplayed(trackItem.getLastplayed());
66         this.setParseVariousArtists(trackItem.isParseVariousArtists());
67     }
68
69     /**
70      * If <code>true</code>; sets this track to be submitted, otherwise do not
71      * submit.
72      * @return Returns <code>true</code> if this track should be submitted.
73      */
74     public Boolean isActive() {
75         return active;
76     }
77
78     /**
79      * If <code>true</code>; sets this track to be submitted, otherwise do not
80      * submit.
81      * @param active  <code>true</code> if this track should be submitted.
82      */
83     public void setActive(Boolean active) {
84         this.active = active;
85     }
86
87     /**
88      * @return Returns the album.
89      */
90     public String getAlbum() {
91         return album;
92     }
93
94     /**
95      * @param album The album to set.
96      */
97     public void setAlbum(String album) {
98         this.album = album;
99     }
100
101     /**
102      * Gets the artist of this track.
103      * @return Returns the artist.
104      */
105     public String getArtist() {
106         /* If required parse the track String to obtain the proper artist. */
107         if (isVariousArtistAlbum(parseVariousArtists)) {
108             return track.split("-")[0].trim();
109         }
110
111         return artist;
112     }
113
114     /**
115      * Returns <code>true</code> if this track belongs to a "Various Artist"
116      * album.
117      * @param parseVariousArtists  <code>true</code> Will cause the track to be
118      * checked to see if it is a "Various Artist" track.  If so, the artist
119      * information will be parsed from the track title.
120      * @return  <code>true</code> if this is a "Various Artist" album.
121      */
122     public boolean isVariousArtistAlbum(boolean parseVariousArtists) {
123         /* Returns false if "Various Artist" tracks should not be parsed. */
124         if (!parseVariousArtists) {
125             return false;
126         }
127
128         /* In addition to other checks, this makes sure the track is not null,
129          * because track will need to be parsed. */
130         return (track != null) && (artist != null)
131         && artist.trim().toLowerCase().equals("various artists");
132     }
133
134     /**
135      * @param artist The artist to set.
136      */
137     public void setArtist(String artist) {
138         this.artist = artist;
139     }
140
141     /**
142      * @return Returns the lastplayed.
143      */
144     public long getLastplayed() {
145         return lastplayed;
146     }
147
148     /**
149      * @param lastplayed UNIX timestamp, in seconds.
150      */
151     public void setLastplayed(long lastplayed) {
152         this.lastplayed = lastplayed;
153     }
154
155     /**
156      * @return Returns the length.
157      */
158     public long getLength() {
159         return length;
160     }
161
162     /**
163      * @param length The length to set.
164      */
165     public void setLength(long length) {
166         this.length = length;
167     }
168
169     /**
170      * @return Returns the playcount.
171      */
172     public long getPlaycount() {
173         return playcount;
174     }
175
176     /**
177      * @param playcount The playcount to set.
178      */
179     public void setPlaycount(long playcount) {
180         this.playcount = playcount;
181     }
182
183     /**
184      * Gets the track name of the track.
185      * @return Returns the track.
186      */
187     public String getTrack() {
188         /* If required parse the track String to obtain the proper track. */
189         if (isVariousArtistAlbum(parseVariousArtists)) {
190             return track.split("-")[1].trim();
191         }
192
193         return track;
194     }
195
196     /**
197      * @param track The track to set.
198      */
199     public void setTrack(String track) {
200         this.track = track;
201     }
202
203     /**
204      * @return Returns the trackid.
205      */
206     public long getTrackid() {
207         return trackid;
208     }
209
210     /**
211      * @param trackid The trackid to set.
212      */
213     public void setTrackid(long trackid) {
214         this.trackid = trackid;
215     }
216
217     /**
218      * Returns <code>true</code> if the track should be parsed for "Various
219      * Artists".
220      * @return  Returns <code>true</code> if the track should be parsed for
221      * "Various Artists".
222      */
223     public boolean isParseVariousArtists() {
224         return parseVariousArtists;
225     }
226
227     /**
228      * Set this to <code>true</code> if the track should be parsed for "Various
229      * Artists".
230      * @param parseVariousArtists  <code>true</code> Will cause the track to be
231      * checked to see if it is a "Various Artist" track.  If so, the artist
232      * information will be parsed from the track title.
233      */
234     public void setParseVariousArtists(boolean parseVariousArtists) {
235         this.parseVariousArtists = parseVariousArtists;
236     }
237
238     public int compareTo(Object trackItem) {
239         TrackItem temptrack = (TrackItem) trackItem;
240
241         if (this.lastplayed < temptrack.getLastplayed()) {
242             return -1;
243         } else if (this.lastplayed > temptrack.getLastplayed()) {
244             return 1;
245         }
246
247         return 0;
248     }
249
250     public String toString() {
251         String tempstring;
252
253         tempstring = "Track ID: " + trackid + "\n";
254         tempstring += ("Length: " + length + "\n");
255         tempstring += ("Artist: " + getArtist() + "\n");
256         tempstring += ("Album: " + album + "\n");
257         tempstring += ("Track: " + getTrack() + "\n");
258         tempstring += ("Play Count: " + playcount + "\n");
259         tempstring += ("Last Played: " + new Date(lastplayed * 1000) + "\n");
260
261         return tempstring;
262     }
263 }
Note: See TracBrowser for help on using the browser.