annotate src/scrobbler/scrobbler.c @ 2306:dd78327f5747

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