annotate src/scrobbler/plugin.c @ 554:7deaaa08706a trunk

[svn] - include a valid length
author nenolod
date Sat, 27 Jan 2007 06:48:17 -0800
parents 269841b8fb31
children 45c9130027d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
1 #include "settings.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 #include "config.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 #include <glib.h>
527
d124034ebea3 [svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents: 402
diff changeset
5 #include <audacious/i18n.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 #include <gdk/gdkkeysyms.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 #include <gtk/gtk.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 #include <audacious/plugin.h>
402
1d50eb0b5a0a [svn] - chase prefswin -> ui_preferences in audacious core
nenolod
parents: 364
diff changeset
11 #include <audacious/ui_preferences.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 #include <audacious/playlist.h>
4
0ad4849f6219 [svn] - the first pass missed some libaudacious references, this fixes them
nenolod
parents: 0
diff changeset
13 #include <audacious/configdb.h>
0ad4849f6219 [svn] - the first pass missed some libaudacious references, this fixes them
nenolod
parents: 0
diff changeset
14 #include <audacious/beepctrl.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 #include <unistd.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 #include <stdio.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 #include <stdlib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 #include <string.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 #include <ctype.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 #include <wchar.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
22 #include <sys/time.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 #include "scrobbler.h"
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
25 #include "gerpok.h"
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
26 #include "hatena.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 #include "gtkstuff.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28 #include "config.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 #include "fmt.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30 #include "configure.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32 #define XS_CS xmms_scrobbler.xmms_session
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
33 #define XS_SLEEP 1
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
34 #define HS_SLEEP 10
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
36 typedef struct submit_t
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37 {
553
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
38 int dosubmit, pos_c, len, gerpok;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39 } submit_t;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
40
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
41 static void init(void);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
42 static void cleanup(void);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
43 static void *xs_thread(void *);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
44 static void *hs_thread(void *);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
45 static int sc_going, ge_going, ha_going;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46 static GtkWidget *cfgdlg;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
47
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
48 static GMutex *m_scrobbler;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49 static GThread *pt_scrobbler;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
50 static GThread *pt_handshake;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
52 static GMutex *hs_mutex, *xs_mutex;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
53 static GCond *hs_cond, *xs_cond;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
54
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
55 static GeneralPlugin xmms_scrobbler =
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 NULL,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58 NULL,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 -1,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 NULL,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61 init,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62 about_show,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
63 NULL,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
64 cleanup
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
65 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
66
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
67 static void init(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
68 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
69 char *username = NULL, *password = NULL;
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
70 char *ge_username = NULL, *ge_password = NULL;
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
71 char *ha_username = NULL, *ha_password = NULL;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
72 ConfigDb *cfgfile;
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
73 sc_going = 1;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
74 ge_going = 1;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
75 ha_going = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
76 GError **moo = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77 cfgdlg = create_cfgdlg();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
79 prefswin_page_new(cfgdlg, "Scrobbler", DATA_DIR "/images/audioscrobbler.png");
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
81 if ((cfgfile = bmp_cfg_db_open()) != NULL) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "username",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83 &username);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "password",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 &password);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
86 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_username",
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
87 &ge_username);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
88 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ge_password",
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
89 &ge_password);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
90 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ha_username",
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
91 &ha_username);
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
92 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "ha_password",
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
93 &ha_password);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94 bmp_cfg_db_close(cfgfile);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
96
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
97 if ((!username || !password) || (!*username || !*password))
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
98 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
99 pdebug("username/password not found - not starting last.fm support",
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 DEBUG);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
101 sc_going = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
103 else
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
104 {
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
105 sc_init(username, password);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
106
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
107 g_free(username);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
108 g_free(password);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
109 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
110
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
111 if ((!ge_username || !ge_password) || (!*ge_username || !*ge_password))
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
112 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
113 pdebug("username/password not found - not starting Gerpok support",
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
114 DEBUG);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
115 ge_going = 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
116 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
117 else
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
118 {
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
119 gerpok_sc_init(ge_username, ge_password);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
120
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
121 g_free(ge_username);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
122 g_free(ge_password);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
123 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
124
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
125 if ((!ha_username || !ha_password) || (!*ha_username || !*ha_password))
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
126 {
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
127 pdebug("username/password not found - not starting Hatena support",
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
128 DEBUG);
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
129 ha_going = 0;
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
130 }
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
131 else
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
132 {
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
133 hatena_sc_init(ha_username, ha_password);
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
134
364
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
135 g_free(ha_username);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
136 g_free(ha_password);
50347c06ec68 [svn] - make scrobbler behave better
nenolod
parents: 363
diff changeset
137 }
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
138
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
139 m_scrobbler = g_mutex_new();
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
140 hs_mutex = g_mutex_new();
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
141 xs_mutex = g_mutex_new();
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
142 hs_cond = g_cond_new();
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
143 xs_cond = g_cond_new();
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
144
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
145 if ((pt_scrobbler = g_thread_create(xs_thread, NULL, TRUE, moo)) == NULL)
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
146 {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
147 pdebug(fmt_vastr("Error creating scrobbler thread: %s", moo), DEBUG);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
148 sc_going = 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
149 ge_going = 0;
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
150 ha_going = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
151 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
152 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
153
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
154 if ((pt_handshake = g_thread_create(hs_thread, NULL, TRUE, moo)) == NULL)
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
155 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
156 pdebug(fmt_vastr("Error creating handshake thread: %s", moo), DEBUG);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
157 sc_going = 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
158 ge_going = 0;
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
159 ha_going = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
160 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
161 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
162
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
163 pdebug("plugin started", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
164 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
165
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
166 static void cleanup(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
167 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
168 g_free (xmms_scrobbler.description);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
169 xmms_scrobbler.description = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
170
108
0eb1e99b7748 [svn] - move prefswin_page_destroy(cfgdlg) to before the plugin logs out of last.fm;
nenolod
parents: 12
diff changeset
171 prefswin_page_destroy(cfgdlg);
0eb1e99b7748 [svn] - move prefswin_page_destroy(cfgdlg) to before the plugin logs out of last.fm;
nenolod
parents: 12
diff changeset
172
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
173 if (!sc_going && !ge_going && ! ha_going)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
174 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
175 pdebug("about to lock mutex", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
176 g_mutex_lock(m_scrobbler);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
177 pdebug("locked mutex", DEBUG);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
178 sc_going = 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
179 ge_going = 0;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
180 ha_going = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
181 g_mutex_unlock(m_scrobbler);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
182 pdebug("joining threads", DEBUG);
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
183
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
184 /* wake up waiting threads */
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
185 pdebug("send signal to xs and hs", DEBUG);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
186 g_cond_signal(xs_cond);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
187 g_cond_signal(hs_cond);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
188
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
189 pdebug("wait xs", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
190 g_thread_join(pt_scrobbler);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
191
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
192 pdebug("wait hs", DEBUG);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
193 g_thread_join(pt_handshake);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
194
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
195 g_cond_free(hs_cond);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
196 g_cond_free(xs_cond);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
197 g_mutex_free(hs_mutex);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
198 g_mutex_free(xs_mutex);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
199 g_mutex_free(m_scrobbler);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
200
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
201 sc_cleaner();
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
202 gerpok_sc_cleaner();
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
203 hatena_sc_cleaner();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
204 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
205
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
206 static char ishttp(const char *a)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
207 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
208 char *tmp, *bp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
209 int status = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
210
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
211 if (!a || !*a)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
212 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
213
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
214 tmp = strdup(a);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
215 for (bp = tmp; *bp; bp++)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
216 *bp = toupper((int) *bp);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
217 if (strstr(tmp, "HTTP://"))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
218 status = -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219 free(tmp);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
220 return status;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
221 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
222
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
223 /* Following code thanks to nosuke
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
224 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
225 * It should probably be cleaned up
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
226 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
227 static submit_t get_song_status(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
228 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
229 static int pos_c, playlistlen_c, playtime_c, time_c,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
230 pos_p = 0, playlistlen_p = 0, playtime_p = 0,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
231 playtime_i = 0, time_i = 0,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
232 playtime_ofs = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
233 static char *file_c = NULL, *file_p = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 static enum playstatus {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236 ps_stop, ps_play, ps_pause
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 } ps_c, ps_p = ps_stop;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
238
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
239 static int submitted = 0, changed, seeked, repeat,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
240 filechanged, rewind, len = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
241
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
242 static enum state {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
243 start, stop, pause, restart, playing, pausing, stopping
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
244 } playstate;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
245
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 submit_t dosubmit;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
247
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
248 struct timeval timetmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
249
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
250 /* clear dosubmit */
553
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
251 dosubmit.dosubmit = dosubmit.pos_c = dosubmit.len = dosubmit.gerpok = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
252
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
253 /* current music number */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254 pos_c = xmms_remote_get_playlist_pos(XS_CS);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 /* current file name */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256 file_c = xmms_remote_get_playlist_file(XS_CS, pos_c);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257 /* total number */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 playlistlen_c = xmms_remote_get_playlist_length(XS_CS);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259 /* current playtime */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260 playtime_c = xmms_remote_get_output_time(XS_CS);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 /* total length */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262 len = xmms_remote_get_playlist_time(XS_CS, pos_c);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
263
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
264 /* current time (ms) */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 gettimeofday(&timetmp, NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 time_c = timetmp.tv_sec * 1000 + timetmp.tv_usec / 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268 /* current status */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
269 if( xmms_remote_is_paused(XS_CS) ) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
270 ps_c = ps_pause;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 }else if( xmms_remote_is_playing(XS_CS) ) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
272 ps_c = ps_play;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 }else{
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274 ps_c = ps_stop;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 /* repeat setting */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 repeat = xmms_remote_is_repeat(XS_CS);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280 if( ps_p == ps_stop && ps_c == ps_stop ) playstate = stopping;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
281 else if( ps_p == ps_stop && ps_c == ps_play ) playstate = start;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 /* else if( ps_p == ps_stop && ps_c == ps_pause ) ; */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283 else if( ps_p == ps_play && ps_c == ps_play ) playstate = playing;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 else if( ps_p == ps_play && ps_c == ps_stop ) playstate = stop;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 else if( ps_p == ps_play && ps_c == ps_pause ) playstate = pause;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286 else if( ps_p == ps_pause && ps_c == ps_pause ) playstate = pausing;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
287 else if( ps_p == ps_pause && ps_c == ps_play ) playstate = restart;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 else if( ps_p == ps_pause && ps_c == ps_stop ) playstate = stop;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289 else playstate = stopping;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
291 /* filename has changed */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 if( !(file_p == NULL && file_c == NULL) &&
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293 ((file_p == NULL && file_c != NULL) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
294 (file_p != NULL && file_c == NULL) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
295 (file_p != NULL && file_c != NULL && strcmp(file_c, file_p))) ){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
296 filechanged = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
297 pdebug("*** filechange ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
298 }else{
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
299 filechanged = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
300 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
301 if( file_c == NULL ){ len = 0; }
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 /* whole rewind has occurred (maybe) */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
304 if( len != 0 && len - (playtime_p - playtime_c) < 3000 ){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
305 rewind = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
306 pdebug("*** rewind ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307 }else{
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308 rewind = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312 changed = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313 seeked = 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 switch( playstate ){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
316 case start:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
317 pdebug("*** START ***", SUB_DEBUG);
553
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
318 dosubmit.gerpok = 1;
554
7deaaa08706a [svn] - include a valid length
nenolod
parents: 553
diff changeset
319 dosubmit.len = len;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
320 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
321 case stop:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
322 pdebug("*** STOP ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
323 len = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
324 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
325 case pause:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
326 pdebug("*** PAUSE ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
327 playtime_ofs += playtime_c - playtime_i; /* save playtime */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
328 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
329 case restart:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
330 pdebug("*** RESTART ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
331 playtime_i = playtime_c; /* restore playtime */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
333 case playing:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334 if( (playtime_c < playtime_p) || /* back */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
335 ( (playtime_c - playtime_i) - (time_c - time_i) > 3000 )
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
336 /* forward */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
337 ) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 seeked = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
341 if( filechanged || /* filename has changed */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
342 ( !filechanged && /* filename has not changed... */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
343 /* (( rewind && (repeat && (!advance ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
344 (pos_c == 0 && playlistlen_c == 1 )))) || */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
345 /* looping with only one file */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 (( pos_c == 0 && playlistlen_c == 1 && repeat
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
347 && rewind ) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
348 /* looping? */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
349 ( pos_p == pos_c && rewind ) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
350
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
351 ( pos_p != pos_c && seeked ) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
352 /* skip from current music to next music,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
353 which has the same filename as previous one */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 ( pos_p < pos_c && playtime_c < playtime_p ) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355 /* current song has removed from playlist
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
356 but the next (following) song has the same
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
357 filename */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358 ( playlistlen_p > playlistlen_c
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
359 && playtime_c < playtime_p )))){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
360 pdebug("*** CHANGE ***",SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
361 pdebug(fmt_vastr(" filechanged = %d",filechanged),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362 pdebug(fmt_vastr(" pos_c = %d",pos_c),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363 pdebug(fmt_vastr(" pos_p = %d",pos_p),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 pdebug(fmt_vastr(" rewind = %d", rewind),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365 pdebug(fmt_vastr(" seeked = %d", seeked),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
366 pdebug(fmt_vastr(" playtime_c = %d", playtime_c),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
367 pdebug(fmt_vastr(" playtime_p = %d", playtime_p),SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368 pdebug(fmt_vastr(" playlistlen_c = %d", playlistlen_p),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
369 SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
370 pdebug(fmt_vastr(" playlistlen_p = %d", playlistlen_p),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
372 changed = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
373 seeked = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
374
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
375 if (file_p != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
376 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
377 g_free(file_p);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
378 file_p = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
379 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
380 }else if( seeked ) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
381 seeked = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
382 pdebug("*** SEEK ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
383 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
384
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
386 case pausing:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
387 if(playtime_c != playtime_p){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 pdebug("*** SEEK ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389 seeked = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
390 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
391 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
392 case stopping:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
393 len = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
394 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
395 default:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
396 pdebug("*** unknown state tranfer!!! ***", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
397 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
398 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
399
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
400
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
401 if( playstate == start || changed || (seeked && !submitted) ){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
402 /* reset counter */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
403 pdebug(" <<< reset counter >>>", SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
404
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
405 submitted = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
406 playtime_ofs = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
407 playtime_i = playtime_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
408 time_i = time_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
409
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
410 }else{
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
411 /* check playtime for submitting */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
412 if( !submitted ){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
413 if( len > 30 * 1000 &&
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 /* len < 30 *60 * 1000 && // crazy rule!!! */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
415 (
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
416 (playtime_ofs + playtime_c - playtime_i > len / 2) ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
417 (playtime_ofs + playtime_c - playtime_i > 240 * 1000)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
418 /* (playtime_c - playtime_i > 10 * 1000)// for debug */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
419 )){
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
420 pdebug("*** submitting requirements are satisfied.",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
421 SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422 pdebug(fmt_vastr(" len = %d, playtime = %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
423 len / 1000, (playtime_c - playtime_i)/1000 ),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 SUB_DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
425 submitted = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
426 dosubmit.dosubmit = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
427 dosubmit.pos_c = pos_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
428 dosubmit.len = len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
429 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
430 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
431 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
432
553
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
433 if (playstate != start)
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
434 dosubmit.gerpok = 0;
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
435
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
436 g_free(file_p);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
437
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
438 /* keep current value for next iteration */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
439 ps_p = ps_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
440 file_p = file_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
441 playtime_p = playtime_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
442 pos_p = pos_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
443 playlistlen_p = playlistlen_c;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
444
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
445 return dosubmit;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
446 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
447
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
448 static void *xs_thread(void *data __attribute__((unused)))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
449 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
450 int run = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
451 submit_t dosubmit;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
452 GTimeVal sleeptime;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
453
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
454 while (run) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
455 /* Error catching */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
456 if(sc_catch_error())
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
457 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
458 errorbox_show(sc_fetch_error());
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
459 sc_clear_error();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
460 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
461
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
462 if(gerpok_sc_catch_error())
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
463 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
464 errorbox_show(gerpok_sc_fetch_error());
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
465 gerpok_sc_clear_error();
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
466 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
467
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
468 if(hatena_sc_catch_error())
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
469 {
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
470 errorbox_show(hatena_sc_fetch_error());
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
471 hatena_sc_clear_error();
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
472 }
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
473
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
474 /* Check for ability to submit */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
475 dosubmit = get_song_status();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
476
553
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
477 if(dosubmit.gerpok) {
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
478 TitleInput *tuple;
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
479
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
480 pdebug("Submitting song.", DEBUG);
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
481
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
482 tuple = playlist_get_tuple(playlist_get_active(), dosubmit.pos_c);
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
483
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
484 if (ishttp(tuple->file_name))
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
485 continue;
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
486
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
487 if(tuple->performer != NULL && tuple->track_name != NULL)
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
488 {
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
489 pdebug(fmt_vastr(
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
490 "submitting artist: %s, title: %s",
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
491 tuple->performer, tuple->track_name), DEBUG);
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
492 gerpok_sc_addentry(m_scrobbler, tuple,
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
493 dosubmit.len/1000);
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
494 }
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
495 else
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
496 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG);
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
497 }
269841b8fb31 [svn] - submit gerpok tracks on immediate playback begin
nenolod
parents: 527
diff changeset
498
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
499 if(dosubmit.dosubmit) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
500 TitleInput *tuple;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
501
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
502 pdebug("Submitting song.", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
503
363
958855dae693 [svn] - fix other plugins dependant on the playlist framework
nenolod
parents: 353
diff changeset
504 tuple = playlist_get_tuple(playlist_get_active(), dosubmit.pos_c);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
505
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
506 if (ishttp(tuple->file_name))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
507 continue;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
508
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
509 if(tuple->performer != NULL && tuple->track_name != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
510 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
511 pdebug(fmt_vastr(
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
512 "submitting artist: %s, title: %s",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
513 tuple->performer, tuple->track_name), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
514 sc_addentry(m_scrobbler, tuple,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
515 dosubmit.len/1000);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
516 hatena_sc_addentry(m_scrobbler, tuple,
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
517 dosubmit.len/1000);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
518 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
519 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
520 pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
521 }
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
522 g_get_current_time(&sleeptime);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
523 sleeptime.tv_sec += XS_SLEEP;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
524
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
525 g_mutex_lock(m_scrobbler);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
526 run = (sc_going != 0 || ge_going != 0 || ha_going != 0);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
527 g_mutex_unlock(m_scrobbler);
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
528
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
529 g_mutex_lock(xs_mutex);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
530 g_cond_timed_wait(xs_cond, xs_mutex, &sleeptime);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
531 g_mutex_unlock(xs_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
532 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
533 pdebug("scrobbler thread: exiting", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
534 g_thread_exit(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
535
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
536 return NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
537 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
538
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
539 static void *hs_thread(void *data __attribute__((unused)))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
540 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
541 int run = 1;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
542 GTimeVal sleeptime;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
543
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
544 while(run)
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 if(sc_idle(m_scrobbler))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
547 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
548 pdebug("Giving up due to fatal error", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
549 g_mutex_lock(m_scrobbler);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
550 sc_going = 0;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
551 g_mutex_unlock(m_scrobbler);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
552 }
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
553
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
554 if(gerpok_sc_idle(m_scrobbler))
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
555 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
556 pdebug("Giving up due to fatal error", DEBUG);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
557 g_mutex_lock(m_scrobbler);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
558 ge_going = 0;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
559 g_mutex_unlock(m_scrobbler);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
560 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 108
diff changeset
561
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
562 if(hatena_sc_idle(m_scrobbler))
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
563 {
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
564 pdebug("Giving up due to fatal error", DEBUG);
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
565 g_mutex_lock(m_scrobbler);
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
566 ha_going = 0;
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
567 g_mutex_unlock(m_scrobbler);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
568 }
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
569
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
570 g_mutex_lock(m_scrobbler);
350
b4f1ad07fcd9 [svn] - add support for hatena (experimental)
nenolod
parents: 346
diff changeset
571 run = (sc_going != 0 || ge_going != 0 || ha_going != 0);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
572 g_mutex_unlock(m_scrobbler);
353
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
573
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
574 if(run) {
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
575 g_get_current_time(&sleeptime);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
576 sleeptime.tv_sec += HS_SLEEP;
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
577
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
578 g_mutex_lock(hs_mutex);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
579 g_cond_timed_wait(hs_cond, hs_mutex, &sleeptime);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
580 g_mutex_unlock(hs_mutex);
1bd205b6e83d [svn] - replace g_usleep() with g_cond_timed_wait()
yaz
parents: 350
diff changeset
581 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
582 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
583 pdebug("handshake thread: exiting", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
584 g_thread_exit(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
585
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
586 return NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
587 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
588
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
589 GeneralPlugin *get_gplugin_info(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
590 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
591 xmms_scrobbler.description = g_strdup_printf(_("Scrobbler Plugin"));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
592 return &xmms_scrobbler;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
593 }