changeset 1443:f4d8082668c1

scrobbler: tuple API update
author William Pitcock <nenolod@atheme-project.org>
date Fri, 10 Aug 2007 10:03:10 -0500
parents 95b8abed24c7
children 3b1651d37b58
files src/scrobbler/fmt.c src/scrobbler/fmt.h src/scrobbler/gerpok.c src/scrobbler/gerpok.h src/scrobbler/plugin.c src/scrobbler/scrobbler.c src/scrobbler/scrobbler.h
diffstat 7 files changed, 39 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/scrobbler/fmt.c	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/fmt.c	Fri Aug 10 10:03:10 2007 -0500
@@ -7,7 +7,7 @@
 #include "fmt.h"
 #include <curl/curl.h>
 
-char *fmt_escape(char *str)
+char *fmt_escape(const char *str)
 {
 	return curl_escape(str, 0);
 }
--- a/src/scrobbler/fmt.h	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/fmt.h	Fri Aug 10 10:03:10 2007 -0500
@@ -4,7 +4,7 @@
 
 #include <time.h>
 
-char *fmt_escape(char *);
+char *fmt_escape(const char *);
 char *fmt_unescape(char *);
 char *fmt_timestr(time_t, int);
 char *fmt_vastr(char *, ...);
--- a/src/scrobbler/gerpok.c	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/gerpok.c	Fri Aug 10 10:03:10 2007 -0500
@@ -13,7 +13,7 @@
 #include "config.h"
 #include <glib.h>
 
-#include <audacious/titlestring.h>
+#include <audacious/tuple.h>
 #include <audacious/util.h>
 
 #define SCROBBLER_HS_URL "http://post.gerpok.com"
@@ -85,14 +85,15 @@
 	free(item);
 }
 
-static void q_put(TitleInput *tuple, int len)
+static void q_put(Tuple *tuple, int len)
 {
 	item_t *item;
+	const gchar *album;
 
 	item = malloc(sizeof(item_t));
 
-	item->artist = fmt_escape(tuple->performer);
-	item->title = fmt_escape(tuple->track_name);
+	item->artist = fmt_escape(tuple_get_string(tuple, "artist"));
+	item->title = fmt_escape(tuple_get_string(tuple, "title"));
 	item->utctime = fmt_escape(fmt_timestr(time(NULL), 1));
 	snprintf(item->len, sizeof(item->len), "%d", len);
 
@@ -105,10 +106,10 @@
 		item->mb = fmt_escape((char*)tuple->mb);
 #endif
 
-	if(tuple->album_name == NULL)
+	if((album = tuple_get_string(tuple, "album")))
 		item->album = fmt_escape("");
 	else
-		item->album = fmt_escape((char*)tuple->album_name);
+		item->album = fmt_escape((char*) album);
 
 	q_nitems++;
 
@@ -926,7 +927,7 @@
 	pdebug("scrobbler starting up", DEBUG);
 }
 
-void gerpok_sc_addentry(GMutex *mutex, TitleInput *tuple, int len)
+void gerpok_sc_addentry(GMutex *mutex, Tuple *tuple, int len)
 {
 	g_mutex_lock(mutex);
 	q_put(tuple, len);
--- a/src/scrobbler/gerpok.h	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/gerpok.h	Fri Aug 10 10:03:10 2007 -0500
@@ -1,11 +1,11 @@
 #ifndef G_NET_H
 #define G_NET_H 1
 
-#include "audacious/titlestring.h"
+#include <audacious/tuple.h>
 
 int gerpok_sc_idle(GMutex *);
 void gerpok_sc_init(char *, char *);
-void gerpok_sc_addentry(GMutex *, TitleInput *, int);
+void gerpok_sc_addentry(GMutex *, Tuple *, int);
 void gerpok_sc_cleaner(void);
 int gerpok_sc_catch_error(void);
 char *gerpok_sc_fetch_error(void);
--- a/src/scrobbler/plugin.c	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/plugin.c	Fri Aug 10 10:03:10 2007 -0500
@@ -215,7 +215,7 @@
 	int run = 1;
 
 	while (run) {
-		TitleInput *tuple;
+		Tuple *tuple;
 		GTimeVal sleeptime;
 
 		/* Error catching */
@@ -243,16 +243,16 @@
 			if (tuple == NULL)
 				continue;
 
-			if (ishttp(tuple->file_name))
+			if (ishttp(tuple_get_string(tuple, "file-name")))
 				continue;
 
-			if(tuple->performer != NULL && tuple->track_name != NULL)
+			if(tuple_get_string(tuple, "artist") != NULL && tuple_get_string(tuple, "title") != NULL)
 			{
 				pdebug(fmt_vastr(
 					"submitting artist: %s, title: %s",
-					tuple->performer, tuple->track_name), DEBUG);
-				sc_addentry(m_scrobbler, tuple, tuple->length / 1000);
-				gerpok_sc_addentry(m_scrobbler, tuple, tuple->length / 1000);
+					tuple_get_string(tuple, "artist"), tuple_get_string(tuple, "title")), DEBUG);
+				sc_addentry(m_scrobbler, tuple, tuple_get_int(tuple, "length") / 1000);
+				gerpok_sc_addentry(m_scrobbler, tuple, tuple_get_int(tuple, "length") / 1000);
 			}
 			else
 				pdebug("tuple does not contain an artist or a title, not submitting.", DEBUG);
--- a/src/scrobbler/scrobbler.c	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/scrobbler.c	Fri Aug 10 10:03:10 2007 -0500
@@ -12,7 +12,7 @@
 #include "settings.h"
 #include <glib.h>
 
-#include <audacious/titlestring.h>
+#include <audacious/tuple.h>
 #include <audacious/util.h>
 
 #define SCROBBLER_HS_URL "http://post.audioscrobbler.com"
@@ -124,17 +124,18 @@
 	free(item);
 }
 
-static item_t *q_put(TitleInput *tuple, int len)
+static item_t *q_put(Tuple *tuple, int len)
 {
 	item_t *item;
+	const gchar *album;
 
 	item = malloc(sizeof(item_t));
 
-	item->artist = fmt_escape(tuple->performer);
-	item->title = fmt_escape(tuple->track_name);
+	item->artist = fmt_escape(tuple_get_string(tuple, "artist"));
+	item->title = fmt_escape(tuple_get_string(tuple, "title"));
 	snprintf(item->utctime, sizeof(item->utctime), "%ld", time(NULL));
 	snprintf(item->len, sizeof(item->len), "%d", len);
-	snprintf(item->track, sizeof(item->track), "%d", tuple->track_number);
+	snprintf(item->track, sizeof(item->track), "%d", tuple_get_int(tuple, "track-number"));
 
 #ifdef NOTYET
 	if(tuple->mb == NULL)
@@ -145,10 +146,10 @@
 		item->mb = fmt_escape((char*)tuple->mb);
 #endif
 
-	if(tuple->album_name == NULL)
+	if((album = tuple_get_string(tuple, "album")))
 		item->album = fmt_escape("");
 	else
-		item->album = fmt_escape((char*)tuple->album_name);
+		item->album = fmt_escape((char*) album);
 
 	q_nitems++;
 
@@ -655,7 +656,7 @@
 	return i;
 }
 
-static int sc_submit_np(TitleInput *tuple)
+static int sc_submit_np(Tuple *tuple)
 {
 	CURL *curl;
 	/* struct HttpPost *post = NULL , *last = NULL; */
@@ -672,8 +673,10 @@
 	/*cfa(&post, &last, "debug", "failed");*/
 
 	entry = g_strdup_printf("s=%s&a=%s&t=%s&b=%s&l=%d&n=%d&m=", sc_session_id,
-		tuple->performer, tuple->track_name, tuple->album_name ? tuple->album_name : "",
-		tuple->length / 1000, tuple->track_number);
+		tuple_get_string(tuple, "artist"),
+		tuple_get_string(tuple, "title"),
+		tuple_get_string(tuple, "album") ? tuple_get_string(tuple, "album") : "",
+		tuple_get_int(tuple, "length") / 1000, tuple_get_int(tuple, "track-number"));
 
 	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *) entry);
 	memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
@@ -878,15 +881,15 @@
 		ptr1 = ptr2 + 1;
 
 		{
-			TitleInput *tuple = bmp_title_input_new();
+			Tuple *tuple = tuple_new();
 
-			tuple->performer = g_strdup(xmms_urldecode_plain(artist));
-			tuple->track_name = g_strdup(xmms_urldecode_plain(title));
-			tuple->album_name = g_strdup(xmms_urldecode_plain(album));
+			tuple_associate_string(tuple, "artist", xmms_urldecode_plain(artist));
+			tuple_associate_string(tuple, "title", xmms_urldecode_plain(title));
+			tuple_associate_string(tuple, "album", xmms_urldecode_plain(album));
 
 			item = q_put(tuple, atoi(len));
 
-			bmp_title_input_free(tuple);
+			mowgli_object_unref(tuple);
 		}
 
 		pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%s i[%d]=%s m[%d]=%s b[%d]=%s",
@@ -1018,7 +1021,7 @@
 	pdebug("scrobbler starting up", DEBUG);
 }
 
-void sc_addentry(GMutex *mutex, TitleInput *tuple, int len)
+void sc_addentry(GMutex *mutex, Tuple *tuple, int len)
 {
 	g_mutex_lock(mutex);
 
--- a/src/scrobbler/scrobbler.h	Fri Aug 10 09:49:37 2007 -0500
+++ b/src/scrobbler/scrobbler.h	Fri Aug 10 10:03:10 2007 -0500
@@ -1,13 +1,13 @@
 #ifndef NET_H
 #define NET_H 1
 
-#include "audacious/titlestring.h"
+#include <audacious/tuple.h>
 
 #define SC_CURL_TIMEOUT 5
 
 int sc_idle(GMutex *);
 void sc_init(char *, char *);
-void sc_addentry(GMutex *, TitleInput *, int);
+void sc_addentry(GMutex *, Tuple *, int);
 void sc_cleaner(void);
 int sc_catch_error(void);
 char *sc_fetch_error(void);