Mercurial > audlegacy-plugins
comparison src/scrobbler/plugin.c @ 2306:dd78327f5747
keep track of how long song is played
| author | Tomasz Mon <desowin@gmail.com> |
|---|---|
| date | Sun, 13 Jan 2008 17:33:47 +0100 |
| parents | b8da6a0b0da2 |
| children | 3f684f1b1840 |
comparison
equal
deleted
inserted
replaced
| 2305:738914331374 | 2306:dd78327f5747 |
|---|---|
| 51 static GThread *pt_scrobbler; | 51 static GThread *pt_scrobbler; |
| 52 static GThread *pt_handshake; | 52 static GThread *pt_handshake; |
| 53 | 53 |
| 54 static GMutex *hs_mutex, *xs_mutex; | 54 static GMutex *hs_mutex, *xs_mutex; |
| 55 static GCond *hs_cond, *xs_cond; | 55 static GCond *hs_cond, *xs_cond; |
| 56 guint track_timeout; | |
| 56 | 57 |
| 57 static GeneralPlugin scrobbler_gp = | 58 static GeneralPlugin scrobbler_gp = |
| 58 { | 59 { |
| 59 .description = "Scrobbler Plugin", | 60 .description = "Scrobbler Plugin", |
| 60 .init = init, | 61 .init = init, |
| 87 } | 88 } |
| 88 | 89 |
| 89 /* wake up the scrobbler thread to submit or queue */ | 90 /* wake up the scrobbler thread to submit or queue */ |
| 90 submit = TRUE; | 91 submit = TRUE; |
| 91 g_cond_signal(xs_cond); | 92 g_cond_signal(xs_cond); |
| 93 } | |
| 94 | |
| 95 static void aud_hook_playback_end(gpointer aud_hook_data, gpointer user_data) | |
| 96 { | |
| 97 if (track_timeout) { | |
| 98 g_source_remove(track_timeout); | |
| 99 track_timeout = 0; | |
| 100 } | |
| 92 } | 101 } |
| 93 | 102 |
| 94 static void init(void) | 103 static void init(void) |
| 95 { | 104 { |
| 96 char *username = NULL, *password = NULL; | 105 char *username = NULL, *password = NULL; |
| 164 ge_going = 0; | 173 ge_going = 0; |
| 165 return; | 174 return; |
| 166 } | 175 } |
| 167 | 176 |
| 168 aud_hook_associate("playback begin", aud_hook_playback_begin, NULL); | 177 aud_hook_associate("playback begin", aud_hook_playback_begin, NULL); |
| 178 aud_hook_associate("playback end", aud_hook_playback_end, NULL); | |
| 169 | 179 |
| 170 pdebug("plugin started", DEBUG); | 180 pdebug("plugin started", DEBUG); |
| 171 } | 181 } |
| 172 | 182 |
| 173 static void cleanup(void) | 183 static void cleanup(void) |
| 203 | 213 |
| 204 sc_cleaner(); | 214 sc_cleaner(); |
| 205 gerpok_sc_cleaner(); | 215 gerpok_sc_cleaner(); |
| 206 | 216 |
| 207 aud_hook_dissociate("playback begin", aud_hook_playback_begin); | 217 aud_hook_dissociate("playback begin", aud_hook_playback_begin); |
| 218 aud_hook_dissociate("playback end", aud_hook_playback_end); | |
| 208 } | 219 } |
| 209 | 220 |
| 210 static void *xs_thread(void *data __attribute__((unused))) | 221 static void *xs_thread(void *data __attribute__((unused))) |
| 211 { | 222 { |
| 212 int run = 1; | 223 int run = 1; |
| 251 aud_tuple_get_string(tuple, FIELD_ARTIST, NULL), | 262 aud_tuple_get_string(tuple, FIELD_ARTIST, NULL), |
| 252 aud_tuple_get_string(tuple, FIELD_TITLE, NULL)), DEBUG); | 263 aud_tuple_get_string(tuple, FIELD_TITLE, NULL)), DEBUG); |
| 253 | 264 |
| 254 sc_addentry(m_scrobbler, tuple, aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000); | 265 sc_addentry(m_scrobbler, tuple, aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000); |
| 255 gerpok_sc_addentry(m_scrobbler, tuple, aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000); | 266 gerpok_sc_addentry(m_scrobbler, tuple, aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000); |
| 267 if (!track_timeout) | |
| 268 track_timeout = g_timeout_add_seconds(1, sc_timeout, NULL); | |
| 256 } | 269 } |
| 257 else | 270 else |
| 258 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG); | 271 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG); |
| 259 | 272 |
| 260 submit = FALSE; | 273 submit = FALSE; |
