Project

General

Profile

0001-Added-very-basic-support-for-scrobbling-of-data-obta.patch

Michael Jacobs, May 08, 2012 20:25

View differences:

src/scrobbler/plugin.c
54 54
	gint playlist = aud_playlist_get_playing();
55 55
	gint pos = aud_playlist_get_position(playlist);
56 56

  
57
	if (aud_playlist_entry_get_length (playlist, pos, FALSE) < 30)
58
	{
59
		AUDDBG(" *** not submitting due to entry->length < 30");
60
		return;
61
	}
62

  
63 57
	gchar * filename = aud_playlist_entry_get_filename (playlist, pos);
64
	if (ishttp (filename))
58
	gboolean is_http_source = ishttp (filename);
59
	str_unref (filename);
60

  
61
	if (aud_playlist_entry_get_length (playlist, pos, FALSE) < 30
62
		&& !is_http_source)
65 63
	{
66
		AUDDBG(" *** not submitting due to HTTP source");
67
		str_unref (filename);
64
		AUDDBG(" *** not submitting due to entry->length < 30");
68 65
		return;
69 66
	}
70
	str_unref (filename);
71 67

  
72 68
	sc_idle(m_scrobbler);
73 69

  
......
77 73
	if (! submit_tuple)
78 74
		return;
79 75

  
80
	sc_addentry(m_scrobbler, submit_tuple, tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) / 1000);
76
	if (is_http_source)
77
	{
78
		if (tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) <= 0)
79
			tuple_set_int(submit_tuple, FIELD_LENGTH, NULL, 240000);
80
	}
81

  
82
	sc_addentry(m_scrobbler, submit_tuple, tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) / 1000, is_http_source);
81 83

  
82 84
	if (!track_timeout)
83
		track_timeout = g_timeout_add_seconds(1, sc_timeout, NULL);
85
		track_timeout = g_timeout_add_seconds(1, sc_timeout, (gpointer)m_scrobbler);
84 86
}
85 87

  
86 88
static void aud_hook_playback_end(gpointer aud_hook_data, gpointer user_data)
87 89
{
90
	sc_playback_end(m_scrobbler);
91

  
88 92
	sc_idle(m_scrobbler);
89 93

  
90 94
	if (track_timeout)
src/scrobbler/scrobbler.c
14 14
#include <audacious/debug.h>
15 15
#include <audacious/misc.h>
16 16
#include <audacious/plugin.h>
17
#include <audacious/playlist.h>
17 18

  
18 19
#define SCROBBLER_CLI_ID "aud"
19 20
#define SCROBBLER_HS_WAIT 1800
......
63 64
    int utctime, track, len;
64 65
    int timeplayed;
65 66
    int numtries;
67
    gboolean is_http_source;
66 68
    void *next;
67 69
} item_t;
68 70

  
......
172 174
    else
173 175
        item->album = fmt_escape("");
174 176

  
177
    item->is_http_source = FALSE;
178

  
175 179
    item->next = NULL;
176 180

  
177 181
    return item;
......
190 194
    return q_additem(item);
191 195
}
192 196

  
193
static item_t *set_np(Tuple *tuple, int len)
197
static item_t *set_np(Tuple *tuple, int len, gboolean is_http_source)
194 198
{
195 199
    if (np_item != NULL)
196 200
        q_item_free (np_item);
197 201

  
198 202
    if ((np_item = create_item (tuple, len)) != NULL)
203
    {
199 204
        AUDDBG ("Tracking now-playing track: %s - %s\n", np_item->artist,
200 205
         np_item->title);
206
        np_item->is_http_source = is_http_source;
207
    }
201 208

  
202 209
    return np_item;
203 210
}
......
262 269
    while (q_get());
263 270
}
264 271

  
272
static int sc_submit_np(Tuple * tuple);
265 273

  
266 274
/* isn't there better way for that? --desowin */
267 275
gboolean sc_timeout(gpointer data)
......
271 279
        if (aud_drct_get_playing() && !aud_drct_get_paused())
272 280
            np_item->timeplayed+=1;
273 281

  
274
        /*
275
         * Check our now-playing track to see if it should go into the queue
276
         */
277
        if (((np_item->timeplayed >= (np_item->len / 2)) ||
278
            (np_item->timeplayed >= 240)))
279
        {
280
            AUDDBG("submitting!!!\n");
281

  
282
            q_additem(np_item);
283
            np_item = NULL;
284
            dump_queue();
285
        }
282
        if (!np_item->is_http_source)
283
	{
284
		/*
285
		 * Check our now-playing track to see if it should go into the queue
286
		 */
287
		if (((np_item->timeplayed >= (np_item->len / 2)) ||
288
		    (np_item->timeplayed >= 240)))
289
		{
290
		    AUDDBG("submitting!!!\n");
291

  
292
		    q_additem(np_item);
293
		    np_item = NULL;
294
		    dump_queue();
295
		}
296
	}
297
	else
298
	{
299
		/*
300
		 * It is possibly a stream. So check if the track info has changed.
301
		 * This is for sure not the most efficient way to do this.
302
		 * But it is straight forward for now...
303
		 */
304
	
305
		gint playlist = aud_playlist_get_playing();
306
		gint pos = aud_playlist_get_position(playlist);
307

  
308
		Tuple *submit_tuple = aud_playlist_entry_get_tuple (playlist, pos, FALSE);
309
		if (! submit_tuple)
310
			return TRUE;
311
		
312
		item_t* current_item = create_item(submit_tuple, tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) / 1000);
313
		if (! current_item)
314
			return TRUE;
315

  
316
		AUDDBG("np: %s\ncurrent: %s\n", np_item->title, current_item->title);
317

  
318
		if ( strcmp(np_item->artist, current_item->artist)
319
			|| strcmp(np_item->title, current_item->title)
320
			|| strcmp(np_item->album, current_item->album)
321
			|| np_item->track != current_item->track )
322
		{
323
			AUDDBG("submitting!!!\n");
324

  
325
			current_item->is_http_source = TRUE;
326

  
327
			if (tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) <= 0)
328
			{
329
				tuple_set_int(submit_tuple, FIELD_LENGTH, NULL, 240000);
330
				current_item->len = 240;
331
			}
332

  
333
			np_item->len = np_item->timeplayed;
334

  
335
			q_additem(np_item);
336
			np_item = current_item;
337
			dump_queue();
338

  
339
			sc_idle((GMutex*)data);
340

  
341
			sc_submit_np(submit_tuple);
342
		}
343
		else
344
		{
345
			q_item_free(current_item);
346

  
347
			AUDDBG("mue_test: timeplayed: %d, len: %d\n", np_item->timeplayed, np_item->len);
348

  
349
			if (np_item->timeplayed > np_item->len)
350
			{
351
				AUDDBG("mue_test: entered!\n");
352

  
353
				/* Make sure that the track stays on now playing. */
354
				tuple_set_int(submit_tuple, FIELD_LENGTH, NULL, np_item->len * 1000);
355
				sc_submit_np(submit_tuple);
356
				np_item->len *= 2;
357
			}			
358
		}
359

  
360
		tuple_unref (submit_tuple);
361
	}
286 362
    }
287 363

  
288 364
    return TRUE;
289 365
}
290 366

  
367
void sc_playback_end(GMutex *mutex)
368
{
369
	if (np_item && np_item->is_http_source)
370
	{
371
		AUDDBG("submitting!!!\n");
372

  
373
		np_item->len = np_item->timeplayed;
374

  
375
                q_additem(np_item);
376
                np_item = NULL;
377
                dump_queue();
378
	}
379
}
380

  
291 381
/* Error functions */
292 382

  
293 383
static void sc_throw_error(char *errortxt)
......
1126 1216
    AUDDBG("scrobbler starting up\n");
1127 1217
}
1128 1218

  
1129
void sc_addentry(GMutex *mutex, Tuple *tuple, int len)
1219
void sc_addentry(GMutex *mutex, Tuple *tuple, int len, gboolean is_http_source)
1130 1220
{
1131 1221
    g_mutex_lock(mutex);
1132 1222

  
1223
    AUDDBG("length: %d, %d\n", tuple_get_int(tuple, FIELD_LENGTH, NULL), len);
1224

  
1133 1225
    sc_submit_np(tuple);
1134
    set_np(tuple, len);
1226
    set_np(tuple, len, is_http_source);
1135 1227

  
1136 1228
    /*
1137 1229
     * This will help make sure the queue will be saved on a nasty
src/scrobbler/scrobbler.h
11 11

  
12 12
int sc_idle(GMutex *);
13 13
void sc_init(char *, char *, char *);
14
void sc_addentry(GMutex *, Tuple *, int);
14
void sc_addentry(GMutex *, Tuple *, int, gboolean);
15 15
void sc_cleaner(void);
16 16
int sc_catch_error(void);
17 17
char *sc_fetch_error(void);
18 18
void sc_clear_error(void);
19
void sc_playback_end(GMutex *);
19 20
#endif
20
-