comparison src/scrobbler/scrobbler.c @ 1687:d158ce84fda7

Modified for Tuplez/plugin API changes.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2007 09:29:26 +0300
parents db616ccdd40c
children 62e89e392227
comparison
equal deleted inserted replaced
1600:49fe2225d236 1687:d158ce84fda7
129 item_t *item; 129 item_t *item;
130 const gchar *album; 130 const gchar *album;
131 131
132 item = malloc(sizeof(item_t)); 132 item = malloc(sizeof(item_t));
133 133
134 item->artist = fmt_escape(tuple_get_string(tuple, "artist")); 134 item->artist = fmt_escape(tuple_get_string(tuple, FIELD_ARTIST, NULL));
135 item->title = fmt_escape(tuple_get_string(tuple, "title")); 135 item->title = fmt_escape(tuple_get_string(tuple, FIELD_TITLE, NULL));
136 snprintf(item->utctime, sizeof(item->utctime), "%ld", time(NULL)); 136 g_snprintf(item->utctime, sizeof(item->utctime), "%ld", time(NULL));
137 snprintf(item->len, sizeof(item->len), "%d", len); 137 g_snprintf(item->len, sizeof(item->len), "%d", len);
138 snprintf(item->track, sizeof(item->track), "%d", tuple_get_int(tuple, "track-number")); 138 g_snprintf(item->track, sizeof(item->track), "%d",
139 tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL));
139 140
140 #ifdef NOTYET 141 #ifdef NOTYET
141 if(tuple->mb == NULL) 142 if(tuple->mb == NULL)
142 #endif 143 #endif
143 item->mb = fmt_escape(""); 144 item->mb = fmt_escape("");
144 #ifdef NOTYET 145 #ifdef NOTYET
145 else 146 else
146 item->mb = fmt_escape((char*)tuple->mb); 147 item->mb = fmt_escape((char*)tuple->mb);
147 #endif 148 #endif
148 149
149 if((album = tuple_get_string(tuple, "album"))) 150 if((album = tuple_get_string(tuple, FIELD_ALBUM, NULL)))
150 item->album = fmt_escape(""); 151 item->album = fmt_escape("");
151 else 152 else
152 item->album = fmt_escape((char*) album); 153 item->album = fmt_escape((char*) album);
153 154
154 q_nitems++; 155 q_nitems++;
440 auth = (char *)md5_string(auth_tmp, strlen(auth_tmp)); 441 auth = (char *)md5_string(auth_tmp, strlen(auth_tmp));
441 g_free(auth_tmp); 442 g_free(auth_tmp);
442 hexify(auth, strlen(auth)); 443 hexify(auth, strlen(auth));
443 auth_tmp = g_strdup(sc_response_hash); 444 auth_tmp = g_strdup(sc_response_hash);
444 445
445 snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s&t=%ld&a=%s", 446 g_snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s&t=%ld&a=%s",
446 SCROBBLER_HS_URL, SCROBBLER_VERSION, 447 SCROBBLER_HS_URL, SCROBBLER_VERSION,
447 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, time(NULL), 448 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, time(NULL),
448 auth_tmp); 449 auth_tmp);
449 g_free(auth_tmp); 450 g_free(auth_tmp);
450 451
598 return -1; 599 return -1;
599 } 600 }
600 601
601 static gchar *sc_itemtag(char c, int n, char *str) 602 static gchar *sc_itemtag(char c, int n, char *str)
602 { 603 {
603 static char buf[SCROBBLER_SB_MAXLEN]; 604 static char buf[SCROBBLER_SB_MAXLEN];
604 snprintf(buf, SCROBBLER_SB_MAXLEN, "&%c[%d]=%s", c, n, str); 605 g_snprintf(buf, SCROBBLER_SB_MAXLEN, "&%c[%d]=%s", c, n, str);
605 return buf; 606 return buf;
606 } 607 }
607 608
608 #define cfa(f, l, n, v) \ 609 #define cfa(f, l, n, v) \
609 curl_formadd(f, l, CURLFORM_COPYNAME, n, \ 610 curl_formadd(f, l, CURLFORM_COPYNAME, n, \
610 CURLFORM_PTRCONTENTS, v, CURLFORM_END) 611 CURLFORM_PTRCONTENTS, v, CURLFORM_END)
671 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); 672 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
672 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 673 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
673 /*cfa(&post, &last, "debug", "failed");*/ 674 /*cfa(&post, &last, "debug", "failed");*/
674 675
675 entry = g_strdup_printf("s=%s&a=%s&t=%s&b=%s&l=%d&n=%d&m=", sc_session_id, 676 entry = g_strdup_printf("s=%s&a=%s&t=%s&b=%s&l=%d&n=%d&m=", sc_session_id,
676 tuple_get_string(tuple, "artist"), 677 tuple_get_string(tuple, FIELD_ARTIST, NULL),
677 tuple_get_string(tuple, "title"), 678 tuple_get_string(tuple, FIELD_TITLE, NULL),
678 tuple_get_string(tuple, "album") ? tuple_get_string(tuple, "album") : "", 679 tuple_get_string(tuple, FIELD_ALBUM, NULL) ? tuple_get_string(tuple, FIELD_ALBUM, NULL) : "",
679 tuple_get_int(tuple, "length") / 1000, tuple_get_int(tuple, "track-number")); 680 tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000,
681 tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL));
680 682
681 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *) entry); 683 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *) entry);
682 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf)); 684 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
683 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf); 685 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
684 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); 686 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
829 int cachesize, written, i = 0; 831 int cachesize, written, i = 0;
830 item_t *item; 832 item_t *item;
831 833
832 cachesize = written = 0; 834 cachesize = written = 0;
833 835
834 snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", audacious_get_localdir()); 836 g_snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", audacious_get_localdir());
835 837
836 if (!(fd = fopen(buf, "r"))) 838 if (!(fd = fopen(buf, "r")))
837 return; 839 return;
838 pdebug(fmt_vastr("Opening %s", buf), DEBUG); 840 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
839 while(!feof(fd)) 841 while(!feof(fd))
881 ptr1 = ptr2 + 1; 883 ptr1 = ptr2 + 1;
882 884
883 { 885 {
884 Tuple *tuple = tuple_new(); 886 Tuple *tuple = tuple_new();
885 887
886 tuple_associate_string(tuple, "artist", xmms_urldecode_plain(artist)); 888 tuple_associate_string(tuple, FIELD_ARTIST, NULL, xmms_urldecode_plain(artist));
887 tuple_associate_string(tuple, "title", xmms_urldecode_plain(title)); 889 tuple_associate_string(tuple, FIELD_TITLE, NULL, xmms_urldecode_plain(title));
888 tuple_associate_string(tuple, "album", xmms_urldecode_plain(album)); 890 tuple_associate_string(tuple, FIELD_ALBUM, NULL, xmms_urldecode_plain(album));
889 891
890 item = q_put(tuple, atoi(len)); 892 item = q_put(tuple, atoi(len));
891 893
892 tuple_free(tuple); 894 tuple_free(tuple);
893 } 895 }
924 { 926 {
925 pdebug("No HOME directory found. Cannot dump queue.", DEBUG); 927 pdebug("No HOME directory found. Cannot dump queue.", DEBUG);
926 return; 928 return;
927 } 929 }
928 930
929 snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", audacious_get_localdir()); 931 g_snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", audacious_get_localdir());
930 932
931 if (!(fd = fopen(buf, "w"))) 933 if (!(fd = fopen(buf, "w")))
932 { 934 {
933 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG); 935 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG);
934 return; 936 return;