Mercurial > audlegacy-plugins
comparison src/scrobbler/plugin.c @ 990:238055a6cb8f trunk
[svn] - remove support for hatena music as hatena ceased their musical profile service.
| author | yaz |
|---|---|
| date | Tue, 01 May 2007 07:03:49 -0700 |
| parents | eb5fe37b785d |
| children | 69cf6184edef |
comparison
equal
deleted
inserted
replaced
| 989:84bef123b22e | 990:238055a6cb8f |
|---|---|
| 22 #include <wchar.h> | 22 #include <wchar.h> |
| 23 #include <sys/time.h> | 23 #include <sys/time.h> |
| 24 | 24 |
| 25 #include "scrobbler.h" | 25 #include "scrobbler.h" |
| 26 #include "gerpok.h" | 26 #include "gerpok.h" |
| 27 #include "hatena.h" | |
| 28 #include "gtkstuff.h" | 27 #include "gtkstuff.h" |
| 29 #include "config.h" | 28 #include "config.h" |
| 30 #include "fmt.h" | 29 #include "fmt.h" |
| 31 #include "configure.h" | 30 #include "configure.h" |
| 32 | 31 |
| 41 | 40 |
| 42 static void init(void); | 41 static void init(void); |
| 43 static void cleanup(void); | 42 static void cleanup(void); |
| 44 static void *xs_thread(void *); | 43 static void *xs_thread(void *); |
| 45 static void *hs_thread(void *); | 44 static void *hs_thread(void *); |
| 46 static int sc_going, ge_going, ha_going; | 45 static int sc_going, ge_going; |
| 47 static GtkWidget *cfgdlg; | 46 static GtkWidget *cfgdlg; |
| 48 | 47 |
| 49 static GMutex *m_scrobbler; | 48 static GMutex *m_scrobbler; |
| 50 static GThread *pt_scrobbler; | 49 static GThread *pt_scrobbler; |
| 51 static GThread *pt_handshake; | 50 static GThread *pt_handshake; |
| 67 | 66 |
| 68 static void init(void) | 67 static void init(void) |
| 69 { | 68 { |
| 70 char *username = NULL, *password = NULL; | 69 char *username = NULL, *password = NULL; |
| 71 char *ge_username = NULL, *ge_password = NULL; | 70 char *ge_username = NULL, *ge_password = NULL; |
| 72 char *ha_username = NULL, *ha_password = NULL; | |
| 73 ConfigDb *cfgfile; | 71 ConfigDb *cfgfile; |
| 74 sc_going = 1; | 72 sc_going = 1; |
| 75 ge_going = 1; | 73 ge_going = 1; |
| 76 ha_going = 1; | |
| 77 GError **moo = NULL; | 74 GError **moo = NULL; |
| 78 cfgdlg = create_cfgdlg(); | 75 cfgdlg = create_cfgdlg(); |
| 79 | 76 |
| 80 prefswin_page_new(cfgdlg, "Scrobbler", DATA_DIR "/images/audioscrobbler.png"); | 77 prefswin_page_new(cfgdlg, "Scrobbler", DATA_DIR "/images/audioscrobbler.png"); |
| 81 | 78 |
| 86 &password); | 83 &password); |
| 87 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_username", | 84 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_username", |
| 88 &ge_username); | 85 &ge_username); |
| 89 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_password", | 86 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_password", |
| 90 &ge_password); | 87 &ge_password); |
| 91 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ha_username", | |
| 92 &ha_username); | |
| 93 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ha_password", | |
| 94 &ha_password); | |
| 95 bmp_cfg_db_close(cfgfile); | 88 bmp_cfg_db_close(cfgfile); |
| 96 } | 89 } |
| 97 | 90 |
| 98 if ((!username || !password) || (!*username || !*password)) | 91 if ((!username || !password) || (!*username || !*password)) |
| 99 { | 92 { |
| 119 { | 112 { |
| 120 gerpok_sc_init(ge_username, ge_password); | 113 gerpok_sc_init(ge_username, ge_password); |
| 121 | 114 |
| 122 g_free(ge_username); | 115 g_free(ge_username); |
| 123 g_free(ge_password); | 116 g_free(ge_password); |
| 124 } | |
| 125 | |
| 126 if ((!ha_username || !ha_password) || (!*ha_username || !*ha_password)) | |
| 127 { | |
| 128 pdebug("username/password not found - not starting Hatena support", | |
| 129 DEBUG); | |
| 130 ha_going = 0; | |
| 131 } | |
| 132 else | |
| 133 { | |
| 134 hatena_sc_init(ha_username, ha_password); | |
| 135 | |
| 136 g_free(ha_username); | |
| 137 g_free(ha_password); | |
| 138 } | 117 } |
| 139 | 118 |
| 140 m_scrobbler = g_mutex_new(); | 119 m_scrobbler = g_mutex_new(); |
| 141 hs_mutex = g_mutex_new(); | 120 hs_mutex = g_mutex_new(); |
| 142 xs_mutex = g_mutex_new(); | 121 xs_mutex = g_mutex_new(); |
| 146 if ((pt_scrobbler = g_thread_create(xs_thread, NULL, TRUE, moo)) == NULL) | 125 if ((pt_scrobbler = g_thread_create(xs_thread, NULL, TRUE, moo)) == NULL) |
| 147 { | 126 { |
| 148 pdebug(fmt_vastr("Error creating scrobbler thread: %s", moo), DEBUG); | 127 pdebug(fmt_vastr("Error creating scrobbler thread: %s", moo), DEBUG); |
| 149 sc_going = 0; | 128 sc_going = 0; |
| 150 ge_going = 0; | 129 ge_going = 0; |
| 151 ha_going = 0; | |
| 152 return; | 130 return; |
| 153 } | 131 } |
| 154 | 132 |
| 155 if ((pt_handshake = g_thread_create(hs_thread, NULL, TRUE, moo)) == NULL) | 133 if ((pt_handshake = g_thread_create(hs_thread, NULL, TRUE, moo)) == NULL) |
| 156 { | 134 { |
| 157 pdebug(fmt_vastr("Error creating handshake thread: %s", moo), DEBUG); | 135 pdebug(fmt_vastr("Error creating handshake thread: %s", moo), DEBUG); |
| 158 sc_going = 0; | 136 sc_going = 0; |
| 159 ge_going = 0; | 137 ge_going = 0; |
| 160 ha_going = 0; | |
| 161 return; | 138 return; |
| 162 } | 139 } |
| 163 | 140 |
| 164 pdebug("plugin started", DEBUG); | 141 pdebug("plugin started", DEBUG); |
| 165 } | 142 } |
| 169 g_free (xmms_scrobbler.description); | 146 g_free (xmms_scrobbler.description); |
| 170 xmms_scrobbler.description = NULL; | 147 xmms_scrobbler.description = NULL; |
| 171 | 148 |
| 172 prefswin_page_destroy(cfgdlg); | 149 prefswin_page_destroy(cfgdlg); |
| 173 | 150 |
| 174 if (!sc_going && !ge_going && ! ha_going) | 151 if (!sc_going && !ge_going) |
| 175 return; | 152 return; |
| 176 pdebug("about to lock mutex", DEBUG); | 153 pdebug("about to lock mutex", DEBUG); |
| 177 g_mutex_lock(m_scrobbler); | 154 g_mutex_lock(m_scrobbler); |
| 178 pdebug("locked mutex", DEBUG); | 155 pdebug("locked mutex", DEBUG); |
| 179 sc_going = 0; | 156 sc_going = 0; |
| 180 ge_going = 0; | 157 ge_going = 0; |
| 181 ha_going = 0; | |
| 182 g_mutex_unlock(m_scrobbler); | 158 g_mutex_unlock(m_scrobbler); |
| 183 pdebug("joining threads", DEBUG); | 159 pdebug("joining threads", DEBUG); |
| 184 | 160 |
| 185 /* wake up waiting threads */ | 161 /* wake up waiting threads */ |
| 186 pdebug("send signal to xs and hs", DEBUG); | 162 pdebug("send signal to xs and hs", DEBUG); |
| 199 g_mutex_free(xs_mutex); | 175 g_mutex_free(xs_mutex); |
| 200 g_mutex_free(m_scrobbler); | 176 g_mutex_free(m_scrobbler); |
| 201 | 177 |
| 202 sc_cleaner(); | 178 sc_cleaner(); |
| 203 gerpok_sc_cleaner(); | 179 gerpok_sc_cleaner(); |
| 204 hatena_sc_cleaner(); | |
| 205 } | 180 } |
| 206 | 181 |
| 207 static gboolean ishttp(const char *a) | 182 static gboolean ishttp(const char *a) |
| 208 { | 183 { |
| 209 g_return_val_if_fail(a != NULL, FALSE); | 184 g_return_val_if_fail(a != NULL, FALSE); |
| 457 { | 432 { |
| 458 errorbox_show(gerpok_sc_fetch_error()); | 433 errorbox_show(gerpok_sc_fetch_error()); |
| 459 gerpok_sc_clear_error(); | 434 gerpok_sc_clear_error(); |
| 460 } | 435 } |
| 461 | 436 |
| 462 if(hatena_sc_catch_error()) | |
| 463 { | |
| 464 errorbox_show(hatena_sc_fetch_error()); | |
| 465 hatena_sc_clear_error(); | |
| 466 } | |
| 467 | |
| 468 /* Check for ability to submit */ | 437 /* Check for ability to submit */ |
| 469 dosubmit = get_song_status(); | 438 dosubmit = get_song_status(); |
| 470 | 439 |
| 471 if(dosubmit.gerpok) { | 440 if(dosubmit.gerpok) { |
| 472 TitleInput *tuple; | 441 TitleInput *tuple; |
| 511 pdebug(fmt_vastr( | 480 pdebug(fmt_vastr( |
| 512 "submitting artist: %s, title: %s", | 481 "submitting artist: %s, title: %s", |
| 513 tuple->performer, tuple->track_name), DEBUG); | 482 tuple->performer, tuple->track_name), DEBUG); |
| 514 sc_addentry(m_scrobbler, tuple, | 483 sc_addentry(m_scrobbler, tuple, |
| 515 dosubmit.len/1000); | 484 dosubmit.len/1000); |
| 516 hatena_sc_addentry(m_scrobbler, tuple, | |
| 517 dosubmit.len/1000); | |
| 518 } | 485 } |
| 519 else | 486 else |
| 520 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG); | 487 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG); |
| 521 } | 488 } |
| 522 g_get_current_time(&sleeptime); | 489 g_get_current_time(&sleeptime); |
| 523 sleeptime.tv_sec += XS_SLEEP; | 490 sleeptime.tv_sec += XS_SLEEP; |
| 524 | 491 |
| 525 g_mutex_lock(m_scrobbler); | 492 g_mutex_lock(m_scrobbler); |
| 526 run = (sc_going != 0 || ge_going != 0 || ha_going != 0); | 493 run = (sc_going != 0 || ge_going != 0); |
| 527 g_mutex_unlock(m_scrobbler); | 494 g_mutex_unlock(m_scrobbler); |
| 528 | 495 |
| 529 g_mutex_lock(xs_mutex); | 496 g_mutex_lock(xs_mutex); |
| 530 g_cond_timed_wait(xs_cond, xs_mutex, &sleeptime); | 497 g_cond_timed_wait(xs_cond, xs_mutex, &sleeptime); |
| 531 g_mutex_unlock(xs_mutex); | 498 g_mutex_unlock(xs_mutex); |
| 557 g_mutex_lock(m_scrobbler); | 524 g_mutex_lock(m_scrobbler); |
| 558 ge_going = 0; | 525 ge_going = 0; |
| 559 g_mutex_unlock(m_scrobbler); | 526 g_mutex_unlock(m_scrobbler); |
| 560 } | 527 } |
| 561 | 528 |
| 562 if(hatena_sc_idle(m_scrobbler)) | |
| 563 { | |
| 564 pdebug("Giving up due to fatal error", DEBUG); | |
| 565 g_mutex_lock(m_scrobbler); | |
| 566 ha_going = 0; | |
| 567 g_mutex_unlock(m_scrobbler); | |
| 568 } | |
| 569 | |
| 570 g_mutex_lock(m_scrobbler); | 529 g_mutex_lock(m_scrobbler); |
| 571 run = (sc_going != 0 || ge_going != 0 || ha_going != 0); | 530 run = (sc_going != 0 || ge_going != 0); |
| 572 g_mutex_unlock(m_scrobbler); | 531 g_mutex_unlock(m_scrobbler); |
| 573 | 532 |
| 574 if(run) { | 533 if(run) { |
| 575 g_get_current_time(&sleeptime); | 534 g_get_current_time(&sleeptime); |
| 576 sleeptime.tv_sec += HS_SLEEP; | 535 sleeptime.tv_sec += HS_SLEEP; |
