diff options
Diffstat (limited to 'apps/scrobbler.c')
-rw-r--r-- | apps/scrobbler.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 07ba016a51..01c704afab 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -139,7 +139,7 @@ static bool scrobbler_flush_callback(void) | |||
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | 141 | ||
142 | static void add_to_cache(void) | 142 | static void add_to_cache(unsigned long play_length) |
143 | { | 143 | { |
144 | if ( cache_pos >= SCROBBLER_MAX_CACHE ) | 144 | if ( cache_pos >= SCROBBLER_MAX_CACHE ) |
145 | write_cache(); | 145 | write_cache(); |
@@ -149,8 +149,7 @@ static void add_to_cache(void) | |||
149 | 149 | ||
150 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); | 150 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); |
151 | 151 | ||
152 | if ( audio_prev_elapsed() > | 152 | if ( play_length > (scrobbler_entry.length/2) ) |
153 | (scrobbler_entry.length/2) ) | ||
154 | rating = 'L'; /* Listened */ | 153 | rating = 'L'; /* Listened */ |
155 | 154 | ||
156 | if (scrobbler_entry.tracknum > 0) | 155 | if (scrobbler_entry.tracknum > 0) |
@@ -193,7 +192,7 @@ void scrobbler_change_event(struct mp3entry *id) | |||
193 | { | 192 | { |
194 | /* add entry using the previous scrobbler_entry and timestamp */ | 193 | /* add entry using the previous scrobbler_entry and timestamp */ |
195 | if (pending) | 194 | if (pending) |
196 | add_to_cache(); | 195 | add_to_cache(audio_prev_elapsed()); |
197 | 196 | ||
198 | /* check if track was resumed > %50 played | 197 | /* check if track was resumed > %50 played |
199 | check for blank artist or track name */ | 198 | check for blank artist or track name */ |
@@ -219,7 +218,7 @@ void scrobbler_change_event(struct mp3entry *id) | |||
219 | int scrobbler_init(void) | 218 | int scrobbler_init(void) |
220 | { | 219 | { |
221 | logf("SCROBBLER: init %d", global_settings.audioscrobbler); | 220 | logf("SCROBBLER: init %d", global_settings.audioscrobbler); |
222 | 221 | ||
223 | if(!global_settings.audioscrobbler) | 222 | if(!global_settings.audioscrobbler) |
224 | return -1; | 223 | return -1; |
225 | 224 | ||
@@ -239,8 +238,8 @@ void scrobbler_flush_cache(void) | |||
239 | { | 238 | { |
240 | /* Add any pending entries to the cache */ | 239 | /* Add any pending entries to the cache */ |
241 | if(pending) | 240 | if(pending) |
242 | add_to_cache(); | 241 | add_to_cache(audio_prev_elapsed()); |
243 | 242 | ||
244 | /* Write the cache to disk if needed */ | 243 | /* Write the cache to disk if needed */ |
245 | if (cache_pos) | 244 | if (cache_pos) |
246 | write_cache(); | 245 | write_cache(); |
@@ -257,7 +256,7 @@ void scrobbler_shutdown(void) | |||
257 | #endif | 256 | #endif |
258 | 257 | ||
259 | scrobbler_flush_cache(); | 258 | scrobbler_flush_cache(); |
260 | 259 | ||
261 | if (scrobbler_initialised) | 260 | if (scrobbler_initialised) |
262 | { | 261 | { |
263 | audio_set_track_changed_event(NULL); | 262 | audio_set_track_changed_event(NULL); |
@@ -265,6 +264,21 @@ void scrobbler_shutdown(void) | |||
265 | } | 264 | } |
266 | } | 265 | } |
267 | 266 | ||
267 | void scrobbler_poweroff(void) | ||
268 | { | ||
269 | if (scrobbler_initialised && pending) | ||
270 | { | ||
271 | if ( audio_status() ) | ||
272 | add_to_cache(audio_current_track()->elapsed); | ||
273 | else | ||
274 | add_to_cache(audio_prev_elapsed()); | ||
275 | |||
276 | /* scrobbler_shutdown is called later, the cache will be written | ||
277 | * make sure the final track isn't added twice when that happens */ | ||
278 | pending = false; | ||
279 | } | ||
280 | } | ||
281 | |||
268 | bool scrobbler_is_enabled(void) | 282 | bool scrobbler_is_enabled(void) |
269 | { | 283 | { |
270 | return scrobbler_initialised; | 284 | return scrobbler_initialised; |