annotate src/scrobbler/scrobbler.c @ 3150:062f42c3737e

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