13 |
13 |
#include <audacious/drct.h>
|
14 |
14 |
#include <audacious/debug.h>
|
15 |
15 |
#include <audacious/misc.h>
|
|
16 |
#include <audacious/playlist.h>
|
16 |
17 |
#include <audacious/plugin.h>
|
17 |
18 |
|
18 |
19 |
#define SCROBBLER_CLI_ID "aud"
|
... | ... | |
48 |
49 |
sc_curl_errbuf[CURL_ERROR_SIZE],
|
49 |
50 |
*sc_major_error;
|
50 |
51 |
|
|
52 |
static int sc_submit_np(Tuple *tuple, int len);
|
51 |
53 |
static void dump_queue();
|
52 |
54 |
|
53 |
55 |
/**** Queue stuff ****/
|
... | ... | |
63 |
65 |
int utctime, track, len;
|
64 |
66 |
int timeplayed;
|
65 |
67 |
int numtries;
|
|
68 |
bool_t is_http_source;
|
66 |
69 |
void *next;
|
67 |
70 |
} item_t;
|
68 |
71 |
|
... | ... | |
137 |
140 |
return newitem;
|
138 |
141 |
}
|
139 |
142 |
|
140 |
|
static item_t *create_item(Tuple *tuple, int len)
|
|
143 |
static item_t *create_item(Tuple *tuple, int len, bool_t is_http_source)
|
141 |
144 |
{
|
142 |
145 |
item_t *item;
|
143 |
146 |
gchar *album, *artist, *title;
|
... | ... | |
172 |
175 |
else
|
173 |
176 |
item->album = fmt_escape("");
|
174 |
177 |
|
|
178 |
item->is_http_source = is_http_source;
|
|
179 |
|
175 |
180 |
item->next = NULL;
|
176 |
181 |
|
177 |
182 |
return item;
|
... | ... | |
181 |
186 |
{
|
182 |
187 |
item_t *item;
|
183 |
188 |
|
184 |
|
if ((item = create_item (tuple, len)) == NULL)
|
|
189 |
if (!(item = create_item(tuple, len, FALSE)))
|
185 |
190 |
return NULL;
|
186 |
191 |
|
187 |
192 |
item->timeplayed = len;
|
... | ... | |
190 |
195 |
return q_additem(item);
|
191 |
196 |
}
|
192 |
197 |
|
193 |
|
static item_t *set_np(Tuple *tuple, int len)
|
|
198 |
static item_t *set_np(Tuple *tuple, int len, bool_t is_http_source)
|
194 |
199 |
{
|
195 |
200 |
if (np_item != NULL)
|
196 |
201 |
q_item_free (np_item);
|
197 |
202 |
|
198 |
|
if ((np_item = create_item (tuple, len)) != NULL)
|
|
203 |
if ((np_item = create_item(tuple, len, is_http_source)))
|
199 |
204 |
AUDDBG ("Tracking now-playing track: %s - %s\n", np_item->artist,
|
200 |
205 |
np_item->title);
|
201 |
206 |
|
... | ... | |
266 |
271 |
/* isn't there better way for that? --desowin */
|
267 |
272 |
gboolean sc_timeout(gpointer data)
|
268 |
273 |
{
|
269 |
|
if (np_item)
|
|
274 |
if (!np_item)
|
|
275 |
return TRUE;
|
|
276 |
|
|
277 |
if (aud_drct_get_playing() && !aud_drct_get_paused())
|
|
278 |
np_item->timeplayed++;
|
|
279 |
|
|
280 |
if (np_item->is_http_source)
|
270 |
281 |
{
|
271 |
|
if (aud_drct_get_playing() && !aud_drct_get_paused())
|
272 |
|
np_item->timeplayed+=1;
|
|
282 |
/* This might be a stream, so check if the track info has changed. */
|
|
283 |
int playlist = aud_playlist_get_playing();
|
|
284 |
int pos = aud_playlist_get_position(playlist);
|
|
285 |
Tuple *tuple = aud_playlist_entry_get_tuple(playlist, pos, FALSE);
|
|
286 |
|
|
287 |
if (!tuple)
|
|
288 |
return TRUE;
|
|
289 |
|
|
290 |
int len = tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000;
|
|
291 |
|
|
292 |
/* Make up a length when we submit streaming to now playing.
|
|
293 |
* We will change it before we actually scrobble the track. */
|
|
294 |
if (len < 1)
|
|
295 |
len = 240;
|
|
296 |
|
|
297 |
item_t *current_item = create_item(tuple, len, TRUE);
|
|
298 |
|
|
299 |
if (!current_item)
|
|
300 |
{
|
|
301 |
tuple_unref(tuple);
|
|
302 |
return TRUE;
|
|
303 |
}
|
|
304 |
|
|
305 |
if (strcmp(np_item->artist, current_item->artist)
|
|
306 |
|| strcmp(np_item->title, current_item->title)
|
|
307 |
|| strcmp (np_item->album, current_item->album)
|
|
308 |
|| np_item->track != current_item->track)
|
|
309 |
{
|
|
310 |
/* Now set the real length of the track. */
|
|
311 |
np_item->len = np_item->timeplayed;
|
273 |
312 |
|
|
313 |
AUDDBG ("Submitting\n");
|
|
314 |
|
|
315 |
q_additem(np_item);
|
|
316 |
np_item = current_item;
|
|
317 |
dump_queue();
|
|
318 |
|
|
319 |
sc_idle((GMutex*)data); // actually submit the queue
|
|
320 |
|
|
321 |
sc_submit_np(tuple, len);
|
|
322 |
}
|
|
323 |
else
|
|
324 |
{
|
|
325 |
q_item_free(current_item);
|
|
326 |
|
|
327 |
if (np_item->timeplayed > np_item->len)
|
|
328 |
{
|
|
329 |
/* Submit the track again to make sure it stays on now playing.
|
|
330 |
* This doubles the total length we have submitted. */
|
|
331 |
sc_submit_np(tuple, np_item->len);
|
|
332 |
np_item->len *= 2;
|
|
333 |
}
|
|
334 |
}
|
|
335 |
|
|
336 |
tuple_unref(tuple);
|
|
337 |
}
|
|
338 |
else
|
|
339 |
{
|
274 |
340 |
/*
|
275 |
341 |
* Check our now-playing track to see if it should go into the queue
|
276 |
342 |
*/
|
... | ... | |
288 |
354 |
return TRUE;
|
289 |
355 |
}
|
290 |
356 |
|
|
357 |
void sc_playback_end(void)
|
|
358 |
{
|
|
359 |
if (np_item && np_item->is_http_source)
|
|
360 |
{
|
|
361 |
/* Now set the real length of the track. */
|
|
362 |
np_item->len = np_item->timeplayed;
|
|
363 |
|
|
364 |
AUDDBG ("Submitting\n");
|
|
365 |
|
|
366 |
q_additem(np_item);
|
|
367 |
np_item = NULL;
|
|
368 |
dump_queue();
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
291 |
372 |
/* Error functions */
|
292 |
373 |
|
293 |
374 |
static void sc_throw_error(char *errortxt)
|
... | ... | |
778 |
859 |
return i;
|
779 |
860 |
}
|
780 |
861 |
|
781 |
|
static int sc_submit_np(Tuple *tuple)
|
|
862 |
static int sc_submit_np(Tuple *tuple, int len)
|
782 |
863 |
{
|
783 |
864 |
CURL *curl;
|
784 |
865 |
/* struct HttpPost *post = NULL , *last = NULL; */
|
... | ... | |
810 |
891 |
field_artist,
|
811 |
892 |
field_title,
|
812 |
893 |
field_album,
|
813 |
|
tuple_get_int(tuple, FIELD_LENGTH, NULL) / 1000,
|
|
894 |
len,
|
814 |
895 |
tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL));
|
815 |
896 |
curl_free(field_artist);
|
816 |
897 |
curl_free(field_title);
|
... | ... | |
1126 |
1207 |
AUDDBG("scrobbler starting up\n");
|
1127 |
1208 |
}
|
1128 |
1209 |
|
1129 |
|
void sc_addentry(GMutex *mutex, Tuple *tuple, int len)
|
|
1210 |
void sc_addentry(GMutex *mutex, Tuple *tuple, int len, bool_t is_http_source)
|
1130 |
1211 |
{
|
1131 |
1212 |
g_mutex_lock(mutex);
|
1132 |
1213 |
|
1133 |
|
sc_submit_np(tuple);
|
1134 |
|
set_np(tuple, len);
|
|
1214 |
sc_submit_np(tuple, len);
|
|
1215 |
set_np(tuple, len, is_http_source);
|
1135 |
1216 |
|
1136 |
1217 |
/*
|
1137 |
1218 |
* This will help make sure the queue will be saved on a nasty
|