annotate src/scrobbler/scrobbler.c @ 2317:447dce6f59f3

bump scrobbler implementation to 0.2
author Tomasz Mon <desowin@gmail.com>
date Tue, 15 Jan 2008 19:54:19 +0100
parents 8f3476f7a696
children 166397a7efe1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 #include <pthread.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 #include <limits.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 #include <stdlib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 #include <string.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 #include <stdarg.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 #include <curl/curl.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 #include <stdio.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 #include "fmt.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 #include "md5.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 #include "scrobbler.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 #include "config.h"
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
12 #include "settings.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 #include <glib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14
1982
0ea55fc6f220 scrobbler: vtable fixing
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
15 #include <audacious/plugin.h>
732
a3ca00f30af5 [svn] - path fixes
nenolod
parents: 401
diff changeset
16 #include <audacious/util.h>
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
17
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 #define SCROBBLER_HS_URL "http://post.audioscrobbler.com"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 #define SCROBBLER_CLI_ID "aud"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 #define SCROBBLER_HS_WAIT 1800
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 #define SCROBBLER_SB_WAIT 10
1026
ff0487e9d00d [svn] - first attempt at implementing AudioScrobbler 1.2 protocol
nenolod
parents: 990
diff changeset
22 #define SCROBBLER_VERSION "1.2"
2317
447dce6f59f3 bump scrobbler implementation to 0.2
Tomasz Mon <desowin@gmail.com>
parents: 2315
diff changeset
23 #define SCROBBLER_IMPLEMENTATION "0.2" /* This is the implementation, not the player version. */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 #define SCROBBLER_SB_MAXLEN 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25 #define CACHE_SIZE 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 /* Scrobblerbackend for xmms plugin, first draft */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 static int sc_hs_status,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30 sc_hs_timeout,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31 sc_hs_errors,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32 sc_sb_errors,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33 sc_bad_users,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34 sc_submit_interval,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35 sc_submit_timeout,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
36 sc_srv_res_size,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37 sc_giveup,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38 sc_major_error_present;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
40 static char *sc_submit_url, /* queue */
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
41 *sc_np_url, /* np */
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
42 *sc_session_id,
348
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
43 *sc_username = NULL,
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
44 *sc_password = NULL,
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45 *sc_challenge_hash,
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
46 sc_response_hash[65535],
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
47 *sc_srv_res,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
48 sc_curl_errbuf[CURL_ERROR_SIZE],
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49 *sc_major_error;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
50
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51 static void dump_queue();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
52
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
53 /**** Queue stuff ****/
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
54
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
55 #define I_ARTIST(i) i->artist
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
56 #define I_TITLE(i) i->title
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
57 #define I_TIME(i) i->utctime
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
58 #define I_LEN(i) i->len
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
59 #define I_ALBUM(i) i->album
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
60
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
61 typedef struct {
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
62 char *artist, *title, *album;
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
63 int utctime, track, len;
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
64 int timeplayed;
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
65 int numtries;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
66 void *next;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
67 } item_t;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
68
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
69 static item_t *q_queue = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
70 static item_t *q_queue_last = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
71 static int q_nitems;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
72
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
73 /* isn't there better way for that? --desowin */
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
74 gboolean sc_timeout(gpointer data) {
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
75 if (q_queue_last && audacious_drct_get_playing())
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
76 q_queue_last->timeplayed+=1;
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
77
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
78 return TRUE;
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
79 }
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
80
1172
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
81 gchar *
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
82 xmms_urldecode_plain(const gchar * encoded_path)
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
83 {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
84 const gchar *cur, *ext;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
85 gchar *path, *tmp;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
86 gint realchar;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
87
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
88 if (!encoded_path)
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
89 return NULL;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
90
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
91 cur = encoded_path;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
92 if (*cur == '/')
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
93 while (cur[1] == '/')
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
94 cur++;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
95
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
96 tmp = g_malloc0(strlen(cur) + 1);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
97
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
98 while ((ext = strchr(cur, '%')) != NULL) {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
99 strncat(tmp, cur, ext - cur);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
100 ext++;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
101 cur = ext + 2;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
102 if (!sscanf(ext, "%2x", &realchar)) {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
103 /*
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
104 * Assume it is a literal '%'. Several file
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
105 * managers send unencoded file: urls on on
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
106 * drag and drop.
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
107 */
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
108 realchar = '%';
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
109 cur -= 2;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
110 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
111 tmp[strlen(tmp)] = realchar;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
112 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
113
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
114 path = g_strconcat(tmp, cur, NULL);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
115 g_free(tmp);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
116 return path;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
117 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
118
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
119 static void q_item_free(item_t *item)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
120 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
121 if (item == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
122 return;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
123 curl_free(item->artist);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
124 curl_free(item->title);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
125 curl_free(item->album);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
126 free(item);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
127 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
128
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
129 static item_t *q_put(Tuple *tuple, int t, int len)
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
130 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
131 item_t *item;
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
132 const gchar *album;
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
133
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
134 item = malloc(sizeof(item_t));
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
135
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1693
diff changeset
136 item->artist = fmt_escape(aud_tuple_get_string(tuple, FIELD_ARTIST, NULL));
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1693
diff changeset
137 item->title = fmt_escape(aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
138 item->len = len;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
139 item->track = aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL);
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
140 if (t == -1) { /* now playing song */
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
141 item->timeplayed = 0;
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
142 item->utctime = time(NULL);
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
143 } else { /* item from queue */
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
144 item->timeplayed = len;
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
145 item->utctime = t;
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
146 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
147
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
148 album = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
149 if (album)
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
150 item->album = fmt_escape((char*) album);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
151 else
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
152 item->album = fmt_escape("");
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
153
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
154 q_nitems++;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
155
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
156 item->next = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
157
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
158 if(q_queue_last == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
159 q_queue = q_queue_last = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
160 else
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
161 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
162 q_queue_last->next = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
163 q_queue_last = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
164 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
165
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
166 return item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
167 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
168
990
238055a6cb8f [svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents: 786
diff changeset
169 #if 0
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
170 static item_t *q_peek(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
171 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
172 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
173 return NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
174 return q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
175 }
990
238055a6cb8f [svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents: 786
diff changeset
176 #endif
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
177
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
178 static item_t *q_peekall(int rewind)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
179 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
180 static item_t *citem = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
181 item_t *temp_item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
182
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
183 if (rewind) {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
184 citem = q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
185 return NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
186 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
187
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
188 temp_item = citem;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
189
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
190 if(citem != NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
191 citem = citem->next;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
192
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
193 return temp_item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
194 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
195
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
196 static int q_get(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
197 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
198 item_t *item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
199
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
200 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
201 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
202
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
203 item = q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
204
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
205 if(item == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
206 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
207
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
208 q_nitems--;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
209 q_queue = q_queue->next;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
210
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
211 q_item_free(item);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
212
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
213 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
214 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
215 q_queue_last = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
216 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
217 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
218
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
219 return -1;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
220 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
221
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
222 static void q_free(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
223 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
224 while (q_get());
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
225 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
226
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
227 static int q_len(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
228 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
229 return q_nitems;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
230 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
231
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
232 /* Error functions */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
233
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234 static void sc_throw_error(char *errortxt)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236 sc_major_error_present = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 if(sc_major_error == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
238 sc_major_error = strdup(errortxt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
239
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
240 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
241 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
242
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
243 int sc_catch_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
244 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
245 return sc_major_error_present;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
247
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
248 char *sc_fetch_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
249 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
250 return sc_major_error;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
251 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
252
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
253 void sc_clear_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 sc_major_error_present = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256 if(sc_major_error != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257 free(sc_major_error);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 sc_major_error = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
263 static size_t sc_store_res(void *ptr, size_t size,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
264 size_t nmemb,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 void *stream __attribute__((unused)))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267 int len = size * nmemb;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
269 sc_srv_res = realloc(sc_srv_res, sc_srv_res_size + len + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
270 memcpy(sc_srv_res + sc_srv_res_size,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 ptr, len);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
272 sc_srv_res_size += len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 return len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276 static void sc_free_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 if(sc_srv_res != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 free(sc_srv_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280 sc_srv_res = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
281 sc_srv_res_size = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 static int sc_parse_hs_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286 char *interval;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
287
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 if (!sc_srv_res_size) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289 pdebug("No reply from server", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
291 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 *(sc_srv_res + sc_srv_res_size) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
294 if (!strncmp(sc_srv_res, "OK\n", 3)) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
295 gchar *scratch = g_strdup(sc_srv_res);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
296 gchar **split = g_strsplit(scratch, "\n", 5);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
297
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
298 g_free(scratch);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
299
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
300 sc_session_id = g_strdup(split[1]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
301 sc_np_url = g_strdup(split[2]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
302 sc_submit_url = g_strdup(split[3]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
303
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
304 g_strfreev(split);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
305 return 0;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
306 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307 if (!strncmp(sc_srv_res, "FAILED ", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310 /* Throwing a major error, just in case */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311 /* sc_throw_error(fmt_vastr("%s", sc_srv_res));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312 sc_hs_errors++; */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313 pdebug(fmt_vastr("error: %s", sc_srv_res), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
315 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
316 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
317
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
318 if (!strncmp(sc_srv_res, "UPDATE ", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
319 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
320 if(!interval)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
321 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
322 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
323 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
324 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
325 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
326 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
327 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
328 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
329
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
330 sc_submit_url = strchr(strchr(sc_srv_res, '\n') + 1, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
331 *(sc_submit_url - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 sc_submit_url = strdup(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
333 sc_challenge_hash = strchr(sc_srv_res, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334 *(sc_challenge_hash - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
335 sc_challenge_hash = strdup(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
336
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
337 /* Throwing major error. Need to alert client to update. */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 sc_throw_error(fmt_vastr("Please update Audacious.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 "Update available at: http://audacious-media-player.org"));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340 pdebug(fmt_vastr("update client: %s", sc_srv_res + 7), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
341
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
342 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
343 * Russ isn't clear on whether we can submit with a not-updated
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
344 * client. Neither is RJ. I use what we did before.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
345 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 sc_giveup = -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
347 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
348 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
349 if (!strncmp(sc_srv_res, "UPTODATE\n", 9)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
350 sc_bad_users = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
351
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
352 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
353 if (!interval) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
356 * This is probably a bad thing, but Russ seems to
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
357 * think its OK to assume that an UPTODATE response
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358 * may not have an INTERVAL... We return -1 anyway.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
359 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
360 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
361 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
366 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
367
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368 sc_submit_url = strchr(strchr(sc_srv_res, '\n') + 1, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
369 *(sc_submit_url - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
370 sc_submit_url = strdup(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 sc_challenge_hash = strchr(sc_srv_res, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
372 *(sc_challenge_hash - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
373 sc_challenge_hash = strdup(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
374
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
375 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
376 }
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
377 if(!strncmp(sc_srv_res, "BADAUTH", 7)) {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
378 /* Throwing major error. */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
379 sc_throw_error("Incorrect username/password.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
380 "Please fix in configuration.");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
381 pdebug("incorrect username/password", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
382
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
383 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
384 if(!interval)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
386 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
387 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
390 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
391 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
392 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
393
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
394 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
395 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
396
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
397 pdebug(fmt_vastr("unknown server-reply '%s'", sc_srv_res), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
398 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
399 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
400
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
401 static unsigned char *md5_string(char *pass, int len)
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
402 {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
403 md5_state_t md5state;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
404 static unsigned char md5pword[16];
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
405
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
406 md5_init(&md5state);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
407 md5_append(&md5state, (unsigned const char *)pass, len);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
408 md5_finish(&md5state, md5pword);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
409
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
410 return md5pword;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
411 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
412
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
413 static void hexify(char *pass, int len)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
415 char *bp = sc_response_hash;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
416 char hexchars[] = "0123456789abcdef";
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
417 int i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
418
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
419 memset(sc_response_hash, 0, sizeof(sc_response_hash));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
420
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
421 for(i = 0; i < len; i++) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
423 *(bp++) = hexchars[pass[i] & 0x0f];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
425 *bp = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
426
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
427 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
428 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
429
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
430 static int sc_handshake(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
431 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
432 int status;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
433 char buf[65535];
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
434 CURL *curl;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
435 time_t ts = time(NULL);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
436 char *auth_tmp;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
437 char *auth;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
438
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
439 auth_tmp = g_strdup_printf("%s%ld", sc_password, ts);
1044
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 1032
diff changeset
440 auth = (char *)md5_string(auth_tmp, strlen(auth_tmp));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
441 g_free(auth_tmp);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
442 hexify(auth, strlen(auth));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
443 auth_tmp = g_strdup(sc_response_hash);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
444
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
445 g_snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s&t=%ld&a=%s",
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
446 SCROBBLER_HS_URL, SCROBBLER_VERSION,
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
447 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, time(NULL),
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
448 auth_tmp);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
449 g_free(auth_tmp);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
450
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
451 curl = curl_easy_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
452 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
453 curl_easy_setopt(curl, CURLOPT_URL, buf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
454 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
455 sc_store_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
456 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
457 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
458 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
401
192004e2a1b7 [svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents: 348
diff changeset
459 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
192004e2a1b7 [svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents: 348
diff changeset
460 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
461 status = curl_easy_perform(curl);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
462 curl_easy_cleanup(curl);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
463
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
464 sc_hs_timeout = time(NULL) + SCROBBLER_HS_WAIT;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
465
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
466 if (status) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
467 pdebug(sc_curl_errbuf, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
468 sc_hs_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
469 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
470 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
471 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
472
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
473 if (sc_parse_hs_res()) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
474 sc_hs_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
475 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
476 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
477 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
478
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
479 if (sc_challenge_hash != NULL) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
480 md5_state_t md5state;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
481 unsigned char md5pword[16];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
482
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
483 md5_init(&md5state);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
484 /*pdebug(fmt_vastr("Pass Hash: %s", sc_password), DEBUG);*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
485 md5_append(&md5state, (unsigned const char *)sc_password,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
486 strlen(sc_password));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
487 /*pdebug(fmt_vastr("Challenge Hash: %s", sc_challenge_hash), DEBUG);*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
488 md5_append(&md5state, (unsigned const char *)sc_challenge_hash,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
489 strlen(sc_challenge_hash));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
490 md5_finish(&md5state, md5pword);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
491 hexify((char*)md5pword, sizeof(md5pword));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
492 /*pdebug(fmt_vastr("Response Hash: %s", sc_response_hash), DEBUG);*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
493 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
494
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
495 sc_hs_errors = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
496 sc_hs_status = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
497
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
498 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
499
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
500 pdebug(fmt_vastr("submiturl: %s - interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
501 sc_submit_url, sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
502
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
503 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
504 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
505
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
506 static int sc_parse_sb_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
507 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
508 char *ch, *ch2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
509
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
510 if (!sc_srv_res_size) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
511 pdebug("No response from server", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
512 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
513 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
514 *(sc_srv_res + sc_srv_res_size) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
515
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
516 if (!strncmp(sc_srv_res, "OK", 2)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
517 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
518 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
519 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
520 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
521 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
522
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
523 pdebug(fmt_vastr("submission ok: %s", sc_srv_res), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
524
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
525 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
526 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
527
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
528 if (!strncmp(sc_srv_res, "BADAUTH", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
529 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
530 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
531 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
532 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
533 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
534
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
535 pdebug("incorrect username/password", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
536
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
537 sc_giveup = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
538
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
539 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
540 * We obviously aren't authenticated. The server might have
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
541 * lost our handshake status though, so let's try
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
542 * re-handshaking... This might not be proper.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
543 * (we don't give up)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
544 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
545 sc_hs_status = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
546
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
547 if(sc_challenge_hash != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
548 free(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
549 if(sc_submit_url != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
550 free(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
551
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
552 sc_challenge_hash = sc_submit_url = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
553 sc_bad_users++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
554
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
555 if(sc_bad_users > 2)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
556 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
557 pdebug("3 BADAUTH returns on submission. Halting "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
558 "submissions until login fixed.", DEBUG)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
559 sc_throw_error("Incorrect username/password.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
560 "Please fix in configuration.");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
561 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
562
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
563 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
564 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
565
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
566 if (!strncmp(sc_srv_res, "FAILED", 6)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
567 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
568 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
569 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
570 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
571 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
572
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
573 /* This could be important. (Such as FAILED - Get new plugin) */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
574 /*sc_throw_error(fmt_vastr("%s", sc_srv_res));*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
575
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
576 pdebug(sc_srv_res, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
577
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
578 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
579 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
580
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
581 if (!strncmp(sc_srv_res, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">", 50)) {
786
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
582 ch = strstr(sc_srv_res, "<TITLE>");
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
583 ch2 = strstr(sc_srv_res, "</TITLE>");
786
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
584 if (ch != NULL && ch2 != NULL) {
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
585 ch += strlen("<TITLE>");
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
586 *ch2 = '\0';
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
587
786
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
588 pdebug(fmt_vastr("HTTP Error (%d): '%s'",
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
589 atoi(ch), ch + 4), DEBUG);
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
590 // *ch2 = '<'; // needed? --yaz
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
591 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
592
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
593 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
594 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
595
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
596 pdebug(fmt_vastr("unknown server-reply %s", sc_srv_res), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
597
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
598 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
599 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
600
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
601 static gchar *sc_itemtag(char c, int n, char *str)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
602 {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
603 static char buf[SCROBBLER_SB_MAXLEN];
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
604 g_snprintf(buf, SCROBBLER_SB_MAXLEN, "&%c[%d]=%s", c, n, str);
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
605 return buf;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
606 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
607
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
608 #define cfa(f, l, n, v) \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
609 curl_formadd(f, l, CURLFORM_COPYNAME, n, \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
610 CURLFORM_PTRCONTENTS, v, CURLFORM_END)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
611
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
612 static int sc_generateentry(GString *submission)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
613 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
614 int i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
615 item_t *item;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
616
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
617 i = 0;
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
618
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
619 q_peekall(1);
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
620
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
621 while ((item = q_peekall(0)) && i < 10)
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
622 {
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
623 /*
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
624 * don't submit queued tracks which don't yet meet audioscrobbler
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
625 * requirements...
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
626 */
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
627 if ((item->timeplayed < (item->len / 2)) &&
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
628 (item->timeplayed < 240))
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
629 continue;
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
630
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
631 if (!item)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
632 return i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
633
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
634 g_string_append(submission,sc_itemtag('a',i,I_ARTIST(item)));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
635 g_string_append(submission,sc_itemtag('t',i,I_TITLE(item)));
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
636 gchar *tmp = g_strdup_printf("%d",I_LEN(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
637 g_string_append(submission,sc_itemtag('l',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
638 g_free(tmp);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
639 tmp = g_strdup_printf("%d",I_TIME(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
640 g_string_append(submission,sc_itemtag('i',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
641 g_free(tmp);
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
642 g_string_append(submission,sc_itemtag('m',i,""));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
643 g_string_append(submission,sc_itemtag('b',i,I_ALBUM(item)));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
644 g_string_append(submission,sc_itemtag('o',i,"P"));
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
645 tmp = g_strdup_printf("%d",item->track);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
646 g_string_append(submission,sc_itemtag('n',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
647 g_free(tmp);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
648 g_string_append(submission,sc_itemtag('r',i,""));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
649
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
650 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d b[%d]=%s",
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
651 i, I_ARTIST(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
652 i, I_TITLE(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
653 i, I_LEN(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
654 i, I_TIME(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
655 i, I_ALBUM(item)), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
656 #ifdef ALLOW_MULTIPLE
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
657 i++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
658 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
659 #endif
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
660
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
661 return i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
662 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
663
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
664 static int sc_submit_np(Tuple *tuple)
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
665 {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
666 CURL *curl;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
667 /* struct HttpPost *post = NULL , *last = NULL; */
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
668 int status;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
669 gchar *entry;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
670
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
671 curl = curl_easy_init();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
672 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
673 curl_easy_setopt(curl, CURLOPT_URL, sc_np_url);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
674 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
675 sc_store_res);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
676 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
677 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
678 /*cfa(&post, &last, "debug", "failed");*/
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
679
2283
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
680 char *field_artist = fmt_escape(aud_tuple_get_string(tuple, FIELD_ARTIST, NULL));
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
681 char *field_title = fmt_escape(aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
682 char *field_album = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL) ? fmt_escape(aud_tuple_get_string(tuple, FIELD_ALBUM, NULL)) : fmt_escape("");
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
683 entry = g_strdup_printf("s=%s&a=%s&t=%s&b=%s&l=%d&n=%d&m=", sc_session_id,
2283
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
684 field_artist,
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
685 field_title,
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
686 field_album,
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1693
diff changeset
687 aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000,
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1693
diff changeset
688 aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL));
2283
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
689 curl_free(field_artist);
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
690 curl_free(field_title);
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
691 curl_free(field_album);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
692
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
693 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *) entry);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
694 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
695 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
696 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
697 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
698 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
699
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
700 status = curl_easy_perform(curl);
1032
15e8890cb54d [svn] - fix memory-leak for protocol 1.2 code
nenolod
parents: 1031
diff changeset
701 curl_easy_cleanup(curl);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
702
1032
15e8890cb54d [svn] - fix memory-leak for protocol 1.2 code
nenolod
parents: 1031
diff changeset
703 g_free(entry);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
704
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
705 if (status) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
706 pdebug(sc_curl_errbuf, DEBUG);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
707 sc_sb_errors++;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
708 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
709 return -1;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
710 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
711
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
712 if (sc_parse_sb_res()) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
713 sc_sb_errors++;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
714 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
715 pdebug(fmt_vastr("Retrying in %d secs, %d elements in queue",
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
716 sc_submit_interval, q_len()), DEBUG);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
717 return -1;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
718 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
719 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
720 return 0;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
721 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
722
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
723 static int sc_submitentry(gchar *entry)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
724 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
725 CURL *curl;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
726 /* struct HttpPost *post = NULL , *last = NULL; */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
727 int status;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
728 GString *submission;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
729
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
730 curl = curl_easy_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
731 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
732 curl_easy_setopt(curl, CURLOPT_URL, sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
733 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
734 sc_store_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
735 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
736 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
737 /*cfa(&post, &last, "debug", "failed");*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
738
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
739 /*pdebug(fmt_vastr("Response Hash: %s", sc_response_hash), DEBUG);*/
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
740 submission = g_string_new("s=");
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
741 g_string_append(submission, (gchar *)sc_session_id);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
742 g_string_append(submission, entry);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
743
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
744 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *)submission->str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
745 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
746 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
401
192004e2a1b7 [svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents: 348
diff changeset
747 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
192004e2a1b7 [svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents: 348
diff changeset
748 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
749 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
750
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
751 status = curl_easy_perform(curl);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
752
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
753 curl_easy_cleanup(curl);
2283
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
754 g_string_free(submission, TRUE);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
755
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
756 if (status) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
757 pdebug(sc_curl_errbuf, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
758 sc_sb_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
759 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
760 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
761 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
762
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
763 if (sc_parse_sb_res()) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
764 sc_sb_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
765 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
766 pdebug(fmt_vastr("Retrying in %d secs, %d elements in queue",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
767 sc_submit_interval, q_len()), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
768 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
769 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
770 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
771 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
772 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
773
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
774 static void sc_handlequeue(GMutex *mutex)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
775 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
776 GString *submitentry;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
777 int nsubmit;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
778 int wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
779
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
780 if(sc_submit_timeout < time(NULL) && sc_bad_users < 3)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
781 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
782 submitentry = g_string_new("");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
783
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
784 g_mutex_lock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
785
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
786 nsubmit = sc_generateentry(submitentry);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
787
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
788 g_mutex_unlock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
789
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
790 if (nsubmit > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
791 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
792 pdebug(fmt_vastr("Number submitting: %d", nsubmit), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
793 pdebug(fmt_vastr("Submission: %s", submitentry->str), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
794
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
795 if(!sc_submitentry(submitentry->str))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
796 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
797 g_mutex_lock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
798
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
799 #ifdef ALLOW_MULTIPLE
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
800 q_free();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
801 #else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
802 q_get();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
803 #endif
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
804 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
805 * This should make sure that the queue doesn't
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
806 * get submitted multiple times on a nasty
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
807 * segfault...
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
808 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
809 dump_queue();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
810
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
811 g_mutex_unlock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
812
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
813 sc_sb_errors = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
814 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
815 if(sc_sb_errors)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
816 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
817 if(sc_sb_errors < 5)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
818 /* Retry after 1 min */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
819 wait = 60;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
820 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
821 wait = /* sc_submit_interval + */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
822 ( ((sc_sb_errors - 5) < 7) ?
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
823 (60 << (sc_sb_errors-5)) :
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
824 7200 );
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
825
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
826 sc_submit_timeout = time(NULL) + wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
827
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
828 pdebug(fmt_vastr("Error while submitting. "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
829 "Retrying after %d seconds.", wait),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
830 DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
831 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
832 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
833
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
834 g_string_free(submitentry, TRUE);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
835 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
836 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
837
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
838 static void read_cache(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
839 {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
840 FILE *fd;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
841 char buf[PATH_MAX];
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
842 int i=0;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
843 item_t *item;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
844 gchar* config_datadir;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
845
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
846 config_datadir = audacious_get_localdir();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
847 g_snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", config_datadir);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
848 g_free(config_datadir);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
849
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
850 if (!(fd = fopen(buf, "r")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
851 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
852 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
853 fclose(fd);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
854
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
855 gchar* cache;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
856 gchar** values;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
857 gchar** entry;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
858 g_file_get_contents(buf, &cache, NULL, NULL);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
859 values = g_strsplit(cache, "\n", 0);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
860
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
861 int x;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
862 for (x=0; values[x] && strlen(values[x]); x++) {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
863 entry = g_strsplit(values[x], "\t", 0);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
864 if (entry[0] && entry[1] && entry[2] && entry[3] && entry[4] && entry[6]) {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
865 char *artist, *title, *album;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
866 int t, len, track;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
867
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
868 artist = g_strdup(entry[0]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
869 album = g_strdup(entry[1]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
870 title = g_strdup(entry[2]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
871 track = atoi(entry[3]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
872 len = atoi(entry[4]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
873 t = atoi(entry[6]);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
874
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
875 if (!strncmp(entry[5], "L", 1)) {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
876 Tuple *tuple = aud_tuple_new();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
877 gchar* string_value;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
878 string_value = xmms_urldecode_plain(artist);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
879 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
880 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
881 string_value = xmms_urldecode_plain(title);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
882 aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
883 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
884 string_value = xmms_urldecode_plain(album);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
885 aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
886 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
887 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, track);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
888 item = q_put(tuple, t, len);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
889
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
890 aud_tuple_free(tuple);
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
891
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
892 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d b[%d]=%s",
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
893 i, I_ARTIST(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
894 i, I_TITLE(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
895 i, I_LEN(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
896 i, I_TIME(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
897 i, I_ALBUM(item)), DEBUG);
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
898 }
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
899
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
900 free(artist);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
901 free(title);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
902 free(album);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
903 g_free(entry);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
904 i++;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
905 }
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
906 }
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
907 g_free(values);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
908 g_free(cache);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
909 pdebug("Done loading cache.", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
910 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
911
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
912 static void dump_queue(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
913 {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
914 FILE *fd;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
915 item_t *item;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
916 char *home, buf[PATH_MAX];
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
917 gchar* config_datadir;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
918
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
919 /*pdebug("Entering dump_queue();", DEBUG);*/
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
920
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
921 if (!(home = getenv("HOME")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
922 {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
923 pdebug("No HOME directory found. Cannot dump queue.", DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
924 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
925 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
926
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
927 config_datadir = audacious_get_localdir();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
928 g_snprintf(buf, sizeof(buf), "%s/scrobblerqueue.txt", config_datadir);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
929 g_free(config_datadir);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
930
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
931 if (!(fd = fopen(buf, "w")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
932 {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
933 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
934 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
935 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
936
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
937 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
938
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
939 q_peekall(1);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
940
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
941 while ((item = q_peekall(0))) {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
942 fprintf(fd, "%s\t%s\t%s\t%d\t%d\t%s\t%d\n",
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
943 I_ARTIST(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
944 I_ALBUM(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
945 I_TITLE(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
946 item->track,
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
947 I_LEN(item),
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
948 ((item->timeplayed > item->len/2) || (item->timeplayed > 240)) ? "L" : "S",
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
949 I_TIME(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
950 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
951
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
952 fclose(fd);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
953 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
954
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
955 /* This was made public */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
956
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
957 void sc_cleaner(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
958 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
959 if(sc_submit_url != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
960 free(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
961 if(sc_username != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
962 free(sc_username);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
963 if(sc_password != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
964 free(sc_password);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
965 if(sc_challenge_hash != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
966 free(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
967 if(sc_srv_res != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
968 free(sc_srv_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
969 if(sc_major_error != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
970 free(sc_major_error);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
971 dump_queue();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
972 q_free();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
973 pdebug("scrobbler shutting down", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
974 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
975
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
976 static void sc_checkhandshake(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
977 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
978 int wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
979
348
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
980 if (!sc_username || !sc_password)
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
981 return;
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
982
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
983 if (sc_hs_status)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
984 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
985 if (sc_hs_timeout < time(NULL))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
986 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
987 sc_handshake();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
988
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
989 if(sc_hs_errors)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
990 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
991 if(sc_hs_errors < 5)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
992 /* Retry after 60 seconds */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
993 wait = 60;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
994 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
995 wait = /* sc_submit_interval + */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
996 ( ((sc_hs_errors - 5) < 7) ?
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
997 (60 << (sc_hs_errors-5)) :
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
998 7200 );
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
999 sc_hs_timeout = time(NULL) + wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1000 pdebug(fmt_vastr("Error while handshaking. Retrying "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1001 "after %d seconds.", wait), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1002 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1003 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1004 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1005
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1006 /**** Public *****/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1007
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1008 /* Called at session startup*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1009
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1010 void sc_init(char *uname, char *pwd)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1011 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1012 sc_hs_status = sc_hs_timeout = sc_hs_errors = sc_submit_timeout =
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1013 sc_srv_res_size = sc_giveup = sc_major_error_present =
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1014 sc_bad_users = sc_sb_errors = 0;
1031
3707a3efcc9c [svn] - protocol 1.2: use interval 1
nenolod
parents: 1030
diff changeset
1015 sc_submit_interval = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1016
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1017 sc_submit_url = sc_username = sc_password = sc_srv_res =
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1018 sc_challenge_hash = sc_major_error = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1019 sc_username = strdup(uname);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1020 sc_password = strdup(pwd);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1021 read_cache();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1022 pdebug("scrobbler starting up", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1023 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1024
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
1025 void sc_addentry(GMutex *mutex, Tuple *tuple, int len)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1026 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1027 g_mutex_lock(mutex);
1029
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1028
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1029 sc_submit_np(tuple);
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
1030 q_put(tuple, -1, len);
1029
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1031
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1032 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1033 * This will help make sure the queue will be saved on a nasty
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1034 * segfault...
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1035 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1036 dump_queue();
1029
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1037
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1038 g_mutex_unlock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1039 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1040
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1041 /* Call periodically from the plugin */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1042 int sc_idle(GMutex *mutex)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1043 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1044 sc_checkhandshake();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1045 if (sc_hs_status)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1046 sc_handlequeue(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1047
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1048 return sc_giveup;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1049 }