# HG changeset patch # User William Pitcock # Date 1241198928 18000 # Node ID 5a11abf0075c4b4153bb5e914f19d32e52d9cf27 # Parent 9978be206b93f6e983cf7866bdf2788a55b79bb6 scrobbler: add support for custom audioscrobbler servers. (closes #23) diff -r 9978be206b93 -r 5a11abf0075c src/scrobbler/configure.c --- a/src/scrobbler/configure.c Thu Apr 30 18:23:44 2009 -0400 +++ b/src/scrobbler/configure.c Fri May 01 12:28:48 2009 -0500 @@ -19,7 +19,9 @@ #include "configure.h" #include "plugin.h" -GtkWidget *entry1, *entry2, *ge_entry1, *ge_entry2, *cfgdlg; +#define LASTFM_HS_URL "http://post.audioscrobbler.com" + +GtkWidget *entry1, *entry2, *entry3, *ge_entry1, *ge_entry2, *cfgdlg; static GdkColor disabled_color; guint apply_timeout = 0; /* ID of timeout to save new config */ gboolean running = TRUE; /* if plugin threads are running */ @@ -49,6 +51,7 @@ mcs_handle_t *cfgfile; const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1)); + const char *url = gtk_entry_get_text(GTK_ENTRY(entry3)); const char *ge_uid = gtk_entry_get_text(GTK_ENTRY(ge_entry1)); if ((cfgfile = aud_cfg_db_open())) { @@ -68,6 +71,11 @@ aud_cfg_db_set_string(cfgfile, "audioscrobbler", "username", ""); aud_cfg_db_set_string(cfgfile, "audioscrobbler", "password", ""); } + + if (url != NULL && url[0] != '\0' && strlen(url)) + aud_cfg_db_set_string(cfgfile, "audioscrobbler", "sc_url", (char *)url); + else if (!url || url[0] == '\0') + aud_cfg_db_set_string(cfgfile, "audioscrobbler", "sc_url", LASTFM_HS_URL); if (ge_uid != NULL && ge_uid[0] != '\0' && strlen(ge_uid) && ge_pwd != NULL && ge_pwd[0] != '\0' && strlen(ge_pwd)) @@ -154,6 +162,7 @@ GtkWidget *label3; GtkWidget *label1; GtkWidget *label2; + GtkWidget *label4; GtkWidget *himage1; GtkWidget *align1; GtkWidget *notebook1; @@ -197,6 +206,14 @@ gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5); + label4 = gtk_label_new (_("Scrobbler URL:")); + gtk_widget_show (label4); + gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_label_set_justify (GTK_LABEL (label4), GTK_JUSTIFY_RIGHT); + gtk_misc_set_alignment (GTK_MISC (label4), 1, 0.5); + entry1 = gtk_entry_new (); gtk_widget_show (entry1); gtk_table_attach_defaults (GTK_TABLE (table1), entry1, 1, 2, 2, 3); @@ -216,6 +233,10 @@ NULL); gtk_widget_show (entry2); gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4); + + entry3 = gtk_entry_new (); + gtk_widget_show (entry3); + gtk_table_attach_defaults (GTK_TABLE (table1), entry3, 1, 2, 4, 5); label1 = gtk_label_new (_("Last.FM")); gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); @@ -282,6 +303,7 @@ if ((db = aud_cfg_db_open())) { gchar *username = NULL; + gchar *sc_url = NULL; // last fm aud_cfg_db_get_string(db, "audioscrobbler", "username", &username); @@ -290,6 +312,14 @@ g_free(username); username = NULL; } + + aud_cfg_db_get_string(db, "audioscrobbler", "sc_url", &sc_url); + if (sc_url) { + gtk_entry_set_text(GTK_ENTRY(entry3), sc_url); + g_free(sc_url); + sc_url = NULL; + } + // gerpok aud_cfg_db_get_string(db, "audioscrobbler", "ge_username", &username); @@ -303,6 +333,7 @@ } g_signal_connect(entry1, "changed", G_CALLBACK(entry_changed), NULL); + g_signal_connect(entry3, "changed", G_CALLBACK(entry_changed), NULL); g_signal_connect(ge_entry1, "changed", G_CALLBACK(entry_changed), NULL); return vbox2; diff -r 9978be206b93 -r 5a11abf0075c src/scrobbler/plugin.c --- a/src/scrobbler/plugin.c Thu Apr 30 18:23:44 2009 -0400 +++ b/src/scrobbler/plugin.c Fri May 01 12:28:48 2009 -0500 @@ -99,7 +99,7 @@ } void start(void) { - char *username = NULL, *password = NULL; + char *username = NULL, *password = NULL, *sc_url = NULL; char *ge_username = NULL, *ge_password = NULL; mcs_handle_t *cfgfile; sc_going = 1; @@ -111,6 +111,8 @@ &username); aud_cfg_db_get_string(cfgfile, "audioscrobbler", "password", &password); + aud_cfg_db_get_string(cfgfile, "audioscrobbler", "sc_url", + &sc_url); aud_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_username", &ge_username); aud_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_password", @@ -126,10 +128,11 @@ } else { - sc_init(username, password); + sc_init(username, password, sc_url); g_free(username); g_free(password); + g_free(sc_url); } if ((!ge_username || !ge_password) || (!*ge_username || !*ge_password)) diff -r 9978be206b93 -r 5a11abf0075c src/scrobbler/scrobbler.c --- a/src/scrobbler/scrobbler.c Thu Apr 30 18:23:44 2009 -0400 +++ b/src/scrobbler/scrobbler.c Fri May 01 12:28:48 2009 -0500 @@ -14,7 +14,6 @@ #include #include -#define SCROBBLER_HS_URL "http://post.audioscrobbler.com" #define SCROBBLER_CLI_ID "aud" #define SCROBBLER_HS_WAIT 1800 #define SCROBBLER_SB_WAIT 10 @@ -38,6 +37,7 @@ static char *sc_submit_url, /* queue */ *sc_np_url, /* np */ + *sc_hs_url, /* handshake url */ *sc_session_id, *sc_username = NULL, *sc_password = NULL, @@ -483,7 +483,7 @@ auth_tmp = g_strdup(sc_response_hash); g_snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s&t=%ld&a=%s", - SCROBBLER_HS_URL, SCROBBLER_VERSION, + sc_hs_url, SCROBBLER_VERSION, SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, ts, auth_tmp); g_free(auth_tmp); @@ -1072,7 +1072,7 @@ /* Called at session startup*/ -void sc_init(char *uname, char *pwd) +void sc_init(char *uname, char *pwd, char *url) { sc_hs_status = sc_hs_timeout = sc_hs_errors = sc_submit_timeout = sc_srv_res_size = sc_giveup = sc_major_error_present = @@ -1083,6 +1083,7 @@ sc_challenge_hash = sc_major_error = NULL; sc_username = strdup(uname); sc_password = strdup(pwd); + sc_hs_url = strdup(url); read_cache(); pdebug("scrobbler starting up", DEBUG); } diff -r 9978be206b93 -r 5a11abf0075c src/scrobbler/scrobbler.h --- a/src/scrobbler/scrobbler.h Thu Apr 30 18:23:44 2009 -0400 +++ b/src/scrobbler/scrobbler.h Fri May 01 12:28:48 2009 -0500 @@ -8,7 +8,7 @@ gboolean sc_timeout(gpointer data); int sc_idle(GMutex *); -void sc_init(char *, char *); +void sc_init(char *, char *, char *); void sc_addentry(GMutex *, Tuple *, int); void sc_cleaner(void); int sc_catch_error(void);