Changeset 61
- Timestamp:
- 05/19/07 22:23:58 (2 years ago)
- Files:
-
- trunk/src/main/org/lastpod/LastPod.java (modified) (1 diff)
- trunk/src/main/org/lastpod/Scrobbler.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/org/lastpod/LastPod.java
r58 r61 139 139 List activeRecentPlayed = onlyActiveTrackItems(recentplayed); 140 140 List inactiveRecentPlayed = onlyInactiveTrackItems(recentplayed); 141 LastPod.scrobbler.handshake(activeRecentPlayed); 142 LastPod.scrobbler.submitTracks(activeRecentPlayed, LastPod.UI); 141 142 LastPod.scrobbler.setChunkProgress(LastPod.UI); 143 LastPod.scrobbler.setTracksToSubmit(activeRecentPlayed); 144 LastPod.scrobbler.handshake(); 145 LastPod.scrobbler.submitTracks(); 143 146 LastPod.scrobbler.addHistories(activeRecentPlayed, inactiveRecentPlayed); 144 147 trunk/src/main/org/lastpod/Scrobbler.java
r60 r61 78 78 79 79 /** 80 * Stores the chunks of tracks to be submitted. 81 */ 82 private List trackChunks; 83 84 /** 85 * Displays the submission progress as this class updates it. 86 */ 87 private ChunkProgress chunkProgress; 88 89 /** 80 90 * The number of seconds to pause between submissions. Only if the server 81 91 * asks to do so. … … 91 101 } 92 102 93 public void handshake(List recentPlayed) 103 /** 104 * Sets the object that displays submission progress. This object updates 105 * the progress as it is processing. 106 * @param chunkProgress The object that displays submission progress. 107 */ 108 public void setChunkProgress(ChunkProgress chunkProgress) { 109 this.chunkProgress = chunkProgress; 110 } 111 112 /** 113 * Sets the tracks that are submitted. 114 * @param recentPlayed A list of tracks to submit. 115 */ 116 public void setTracksToSubmit(final List recentPlayed) { 117 if (recentPlayed.size() == 0) { 118 throw new RuntimeException("No tracks to submit"); 119 } 120 121 /* Converts the recentPlayed List into a List of Chunk objects. Each 122 * chunk stores at most 10 tracks. Each chunk will be submitted to 123 * Last.fm individually, per their guidelines. 124 */ 125 trackChunks = ChunkUtil.createChunks(recentPlayed, MAX_TRACKS_PER_CHUNK); 126 127 /* Add 1 because the handshake will also be included in the progress. */ 128 chunkProgress.setNumberOfChunks(trackChunks.size() + 1); 129 } 130 131 public void handshake() 94 132 throws UnsupportedEncodingException, MalformedURLException, IOException, 95 133 FailedLoginException { 96 if ( recentPlayed.size() == 0) {134 if (trackChunks.size() == 0) { 97 135 throw new RuntimeException("No tracks to submit"); 98 136 } … … 171 209 challenge = lines[1]; 172 210 211 /* Displays some progress update once the handshake is completed. */ 212 chunkProgress.updateCurrentChunk(1); 213 173 214 logger.log(Level.INFO, "Handshake completed"); 174 215 } 175 216 176 public void submitTracks( final List recentPlayed, ChunkProgress chunkProgress)217 public void submitTracks() 177 218 throws UnsupportedEncodingException, NoSuchAlgorithmException, MalformedURLException, 178 219 IOException, FailedLoginException { 179 220 logger.log(Level.INFO, "Submitting tracks..."); 180 221 181 if ( recentPlayed.size() == 0) {222 if (trackChunks.size() == 0) { 182 223 throw new RuntimeException("No tracks to submit"); 183 224 } … … 189 230 String urlEncodedChallange = URLEncoder.encode(md5chal, "UTF-8"); 190 231 191 /* Converts the recentPlayed List into a List of Chunk objects. Each192 * chunk stores at most 10 tracks. Each chunk will be submitted to193 * Last.fm individually, per their guidelines.194 */195 List chunks = ChunkUtil.createChunks(recentPlayed, MAX_TRACKS_PER_CHUNK);196 197 chunkProgress.setNumberOfChunks(chunks.size());198 199 232 Chunk chunk = null; 200 233 201 for (int i = 0; i < chunks.size(); i++) {234 for (int i = 0; i < trackChunks.size(); i++) { 202 235 pauseIfRequired(); 203 236 204 chunk = (Chunk) chunks.get(i);237 chunk = (Chunk) trackChunks.get(i); 205 238 206 239 String queryString = "u=" + urlEncodedUsername + "&" + "s=" + urlEncodedChallange; … … 258 291 } 259 292 260 chunkProgress.updateCurrentChunk(i + 1); 293 /* Add 2 to progress. 1 because chunk progress starts at 1, whereas 294 * this for-loop is zero indexed. 1 because the handshake is also 295 * part of the progress. 296 */ 297 chunkProgress.updateCurrentChunk(i + 2); 261 298 } 262 299
