annotate src/scrobbler/scrobbler.c @ 2904:ff9b4776b938

now scrobbler uses proxy settings; whole scrobbler plugin needs to be re-written using neon
author Andrew O. Shadoura <bugzilla@tut.by>
date Wed, 13 Aug 2008 16:15:29 +0300
parents 19fb7d7dcf4e
children 9ec994a3bb59
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
1982
0ea55fc6f220 scrobbler: vtable fixing
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
14 #include <audacious/plugin.h>
2599
19fb7d7dcf4e Use the md5 routines in libaudutil.
Matti Hamalainen <ccr@tnsp.org>
parents: 2576
diff changeset
15 #include <audacious/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_HS_URL "http://post.audioscrobbler.com"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 #define SCROBBLER_CLI_ID "aud"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 #define SCROBBLER_HS_WAIT 1800
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 #define SCROBBLER_SB_WAIT 10
1026
ff0487e9d00d [svn] - first attempt at implementing AudioScrobbler 1.2 protocol
nenolod
parents: 990
diff changeset
21 #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
22 #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
23 #define SCROBBLER_SB_MAXLEN 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 #define CACHE_SIZE 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 /* Scrobblerbackend for xmms plugin, first draft */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 sc_giveup,
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
37 sc_major_error_present;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
39 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
40 *sc_np_url, /* np */
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);
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
482 hexify(auth, strlen(auth));
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",
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
486 SCROBBLER_HS_URL, SCROBBLER_VERSION,
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
487 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, time(NULL),
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
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
607 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
608 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
609 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
610 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
611 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
612 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
613
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
614 /* 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
615 /*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
616
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
617 pdebug(sc_srv_res, DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
618
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
619 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
620 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
621
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
622 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
623 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
624 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
625 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
626 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
627 *ch2 = '\0';
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
628
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
629 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
630 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
631 // *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
632 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
633
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
634 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
635 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
636
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
637 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
638
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
639 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
640 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
641
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
642 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
643 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
644 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
645 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
646 return buf;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
647 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
648
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
649 #define cfa(f, l, n, v) \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
650 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
651 CURLFORM_PTRCONTENTS, v, CURLFORM_END)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
652
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
653 static int sc_generateentry(GString *submission)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
654 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
655 int i;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
656 item_t *item;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
657
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
658 i = 0;
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
659
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
660 q_peekall(1);
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
661
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
662 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
663 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
664 /*
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
665 * 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
666 * 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
667 */
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 if (!item)
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
670 return i;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
671
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
672 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
673 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
674 gchar *tmp = g_strdup_printf("%d",I_LEN(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
675 g_string_append(submission,sc_itemtag('l',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
676 g_free(tmp);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
677 tmp = g_strdup_printf("%d",I_TIME(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
678 g_string_append(submission,sc_itemtag('i',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
679 g_free(tmp);
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
680 g_string_append(submission,sc_itemtag('m',i,""));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
681 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
682 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
683 tmp = g_strdup_printf("%d",item->track);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
684 g_string_append(submission,sc_itemtag('n',i,tmp));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
685 g_free(tmp);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
686 g_string_append(submission,sc_itemtag('r',i,""));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
687
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
688 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
689 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
690 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
691 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
692 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
693 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
694 i++;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
695 }
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 return i;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
698 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
699
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
700 static int sc_submit_np(Tuple *tuple)
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
701 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
702 CURL *curl;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
703 /* 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
704 int status;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
705 gchar *entry;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
706
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
707 curl = curl_easy_init();
2904
ff9b4776b938 now scrobbler uses proxy settings;
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2599
diff changeset
708 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
709 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
710 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
711 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
712 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
713 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
714 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
715 /*cfa(&post, &last, "debug", "failed");*/
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
716
2283
689bdfacb10c Fixes memory leaks in scrobbler plugin when submitting songs. (Bugzilla #83)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2267
diff changeset
717 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
718 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
719 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
720 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
721 field_artist,
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
722 field_title,
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
723 field_album,
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
724 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
725 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
726 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
727 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
728 curl_free(field_album);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
729
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
730 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
731 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
732 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
733 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
734 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
735 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
736
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
737 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
738 curl_easy_cleanup(curl);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
739
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
740 g_free(entry);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
741
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
742 if (status) {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
743 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
744 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
745 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
746 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
747 }
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 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
750 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
751 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
752 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
753 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
754 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
755 }
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
756 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
757 return 0;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
758 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
759
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
760 static int sc_submitentry(gchar *entry)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
761 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
762 CURL *curl;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
763 /* 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
764 int status;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
765 GString *submission;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
766
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
767 curl = curl_easy_init();
2904
ff9b4776b938 now scrobbler uses proxy settings;
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2599
diff changeset
768 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
769 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
770 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
771 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
772 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
773 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
774 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
775 /*cfa(&post, &last, "debug", "failed");*/
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
776
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
777 /*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
778 submission = g_string_new("s=");
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
779 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
780 g_string_append(submission, entry);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
781
2441
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_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
783 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
784 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
785 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
786 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
787 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
788
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
789 status = curl_easy_perform(curl);
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_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
792 g_string_free(submission, TRUE);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
793
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
794 if (status) {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
795 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
796 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
797 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
798 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
799 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
800
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
801 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
802 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
803 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
804 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
805 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
806 return -1;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
807 }
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
808 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
809 return 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
810 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
811
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
812 static void sc_handlequeue(GMutex *mutex)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
813 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
814 GString *submitentry;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
815 int nsubmit;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
816 int wait;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
817 int i;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
818
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
819 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
820 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
821 submitentry = g_string_new("");
0
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 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
824
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
825 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
826
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
827 g_mutex_unlock(mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
828
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
829 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
830 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
831 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
832 pdebug(fmt_vastr("Submission: %s", submitentry->str), DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
833
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
834 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
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_lock(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 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
839 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
840 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
841 q_get();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
842 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
843
2441
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 * 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
846 * 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
847 * segfault...
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
848 */
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
849 dump_queue();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
850
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
851 g_mutex_unlock(mutex);
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 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
854 }
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
855 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
856 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
857 /* Dump queue */
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
858 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
859 dump_queue();
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 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
863 /* 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
864 wait = 60;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
865 else
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
866 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
867 ( ((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
868 (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
869 7200 );
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
870
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
871 sc_submit_timeout = time(NULL) + wait;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
872
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
873 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
874 "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
875 DEBUG);
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
876 }
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
877 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
878
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
879 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
880 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
881 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
882
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
883 static void read_cache(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
884 {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
885 FILE *fd;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
886 char buf[PATH_MAX];
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
887 int i=0;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
888 item_t *item;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
889 gchar* config_datadir;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
890
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
891 config_datadir = audacious_get_localdir();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
892 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
893 g_free(config_datadir);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
894
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
895 if (!(fd = fopen(buf, "r")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
896 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
897 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
898 fclose(fd);
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 gchar* cache;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
901 gchar** values;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
902 gchar** entry;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
903 g_file_get_contents(buf, &cache, NULL, NULL);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
904 values = g_strsplit(cache, "\n", 0);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
905
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
906 int x;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
907 for (x=0; values[x] && strlen(values[x]); x++) {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
908 entry = g_strsplit(values[x], "\t", 0);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
909 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
910 char *artist, *title, *album;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
911 int t, len, track;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
912
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
913 artist = g_strdup(entry[0]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
914 album = g_strdup(entry[1]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
915 title = g_strdup(entry[2]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
916 track = atoi(entry[3]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
917 len = atoi(entry[4]);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
918 t = atoi(entry[6]);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
919
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
920 /*
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
921 * 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
922 * 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
923 */
2306
dd78327f5747 keep track of how long song is played
Tomasz Mon <desowin@gmail.com>
parents: 2302
diff changeset
924 if (!strncmp(entry[5], "L", 1)) {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
925 Tuple *tuple = aud_tuple_new();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
926 gchar* string_value;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
927 string_value = xmms_urldecode_plain(artist);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
928 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
929 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
930 string_value = xmms_urldecode_plain(title);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
931 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
932 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
933 string_value = xmms_urldecode_plain(album);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
934 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
935 g_free(string_value);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
936 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
937 item = q_put(tuple, t, len);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
938
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
939 aud_tuple_free(tuple);
2315
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
940
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
941 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
942 i, I_ARTIST(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
943 i, I_TITLE(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
944 i, I_LEN(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
945 i, I_TIME(item),
8f3476f7a696 prevent segfault
Tomasz Mon <desowin@gmail.com>
parents: 2314
diff changeset
946 i, I_ALBUM(item)), DEBUG);
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
947 }
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
948
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
949 free(artist);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
950 free(title);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
951 free(album);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
952 i++;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
953 }
2442
1286f65395d7 string arrays should be freed with g_strfreev()
Tomasz Mon <desowin@gmail.com>
parents: 2441
diff changeset
954 g_strfreev(entry);
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
955 }
2442
1286f65395d7 string arrays should be freed with g_strfreev()
Tomasz Mon <desowin@gmail.com>
parents: 2441
diff changeset
956 g_strfreev(values);
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
957 g_free(cache);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
958 pdebug("Done loading cache.", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
959 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
960
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
961 static void dump_queue(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
962 {
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
963 FILE *fd;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
964 item_t *item;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
965 char *home, buf[PATH_MAX];
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
966 gchar* config_datadir;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
967
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
968 /*pdebug("Entering dump_queue();", DEBUG);*/
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
969
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
970 if (!(home = getenv("HOME")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
971 {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
972 pdebug("No HOME directory found. Cannot dump queue.", DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
973 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
974 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
975
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
976 config_datadir = audacious_get_localdir();
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
977 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
978 g_free(config_datadir);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
979
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
980 if (!(fd = fopen(buf, "w")))
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
981 {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
982 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG);
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
983 return;
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
984 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
985
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
986 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
987
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
988 q_peekall(1);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
989
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
990 /*
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
991 * 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
992 * 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
993 * 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
994 * 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
995 * 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
996 */
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
997 while ((item = q_peekall(0))) {
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
998 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
999 I_ARTIST(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1000 I_ALBUM(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1001 I_TITLE(item),
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1002 item->track,
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1003 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
1004 "L",
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1005 I_TIME(item));
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1006 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1007
2302
f074702a0df3 revise scrobblerqueue.txt a bit
Tomasz Mon <desowin@gmail.com>
parents: 2283
diff changeset
1008 fclose(fd);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1009 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1010
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1011 /* This was made public */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1012
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1013 void sc_cleaner(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1014 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 dump_queue();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1028 q_free();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1029 pdebug("scrobbler shutting down", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1030 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1031
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1032 static void sc_checkhandshake(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1033 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1034 int wait;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1035
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1036 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
1037 return;
348
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
1038
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1039 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
1040 return;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1041 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
1042 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1043 sc_handshake();
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_hs_errors)
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1046 {
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1047 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
1048 /* 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
1049 wait = 60;
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1050 else
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1051 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
1052 ( ((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
1053 (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
1054 7200 );
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1055 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
1056 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
1057 "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
1058 }
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1059 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1060 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1061
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1062 /**** Public *****/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1063
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1064 /* Called at session startup*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1065
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1066 void sc_init(char *uname, char *pwd)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1067 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1068 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
1069 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
1070 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
1071 sc_submit_interval = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1072
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1073 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
1074 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
1075 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
1076 sc_password = strdup(pwd);
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1077 read_cache();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1078 pdebug("scrobbler starting up", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1079 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1080
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
1081 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
1082 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1083 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
1084
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1085 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
1086 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
1087
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1088 /*
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1089 * 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
1090 * segfault...
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1091 */
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1092 dump_queue();
1029
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1093
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1094 g_mutex_unlock(mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1095 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1096
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1097 /* Call periodically from the plugin */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1098 int sc_idle(GMutex *mutex)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1099 {
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1100 sc_checkhandshake();
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1101 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
1102 sc_handlequeue(mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1103
2441
166397a7efe1 Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents: 2317
diff changeset
1104 return sc_giveup;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1105 }