[rhythmbox] audioscrobbler: submit track source when scrobbling



commit d5ba4dd2d085d02da1788978a849a97920c18783
Author: Jamie Nicol <jamie thenicols net>
Date:   Mon Aug 2 18:24:48 2010 +0100

    audioscrobbler: submit track source when scrobbling

 plugins/audioscrobbler/Makefile.am                 |    2 +
 plugins/audioscrobbler/rb-audioscrobbler-entry.c   |   30 +++++++---
 plugins/audioscrobbler/rb-audioscrobbler-entry.h   |    3 +-
 .../rb-audioscrobbler-radio-source.c               |   42 +++-----------
 .../rb-audioscrobbler-radio-track-entry.c          |   62 ++++++++++++++++++++
 .../rb-audioscrobbler-radio-track-entry.h          |   49 +++++++++++++++
 plugins/audioscrobbler/rb-audioscrobbler.c         |    4 +-
 tests/Makefile.am                                  |    5 +-
 8 files changed, 150 insertions(+), 47 deletions(-)
---
diff --git a/plugins/audioscrobbler/Makefile.am b/plugins/audioscrobbler/Makefile.am
index f68acb8..bb83e5b 100644
--- a/plugins/audioscrobbler/Makefile.am
+++ b/plugins/audioscrobbler/Makefile.am
@@ -19,6 +19,8 @@ libaudioscrobbler_la_SOURCES = \
 	rb-audioscrobbler.h				\
 	rb-audioscrobbler-radio-source.c		\
 	rb-audioscrobbler-radio-source.h		\
+	rb-audioscrobbler-radio-track-entry.h		\
+	rb-audioscrobbler-radio-track-entry.c		\
 	rb-lastfm-play-order.c				\
 	rb-lastfm-play-order.h
 
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-entry.c b/plugins/audioscrobbler/rb-audioscrobbler-entry.c
index e485ff0..15a5854 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-entry.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-entry.c
@@ -41,6 +41,7 @@
 #include <libsoup/soup.h>
 
 #include "rb-audioscrobbler-entry.h"
+#include "rb-audioscrobbler-radio-track-entry.h"
 
 
 void
@@ -83,7 +84,7 @@ rb_audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry)
 
 
 AudioscrobblerEntry *
-rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry)
+rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry, RBAudioscrobblerService *service)
 {
 	AudioscrobblerEntry *as_entry = g_new0 (AudioscrobblerEntry, 1);
 
@@ -103,14 +104,27 @@ rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry)
 		as_entry->mbid = g_strdup ("");
 	}
 
-	/*
-	 * TODO: identify the source type.  we just use 'P' for everything for now.
-	 * should use 'R' for iradio, 'P' for everything else except last.fm.
-	 * for last.fm, we need to extract the recommendation key from the db entry's
-	 * extra data (see RBLastfmTrackEntryData in rb-lastfm-source.c) and include
-	 * that in the source info here.
+	/* identify the source type. Currently we use:
+	 * L for an audioscrobbler-provided radio track when scrobbling to its own service
+	 * E for an audioscrobbler-provided radio track when scrobbling to a different service
+	 * P for everything else
+	 * TODO: Use R or E in some cases instead of P
 	 */
-	as_entry->source = g_strdup ("P");
+	if (rhythmdb_entry_get_entry_type (rb_entry) == RHYTHMDB_ENTRY_TYPE_AUDIOSCROBBLER_RADIO_TRACK) {
+		RBAudioscrobblerRadioTrackData *track_data;
+		track_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (rb_entry, RBAudioscrobblerRadioTrackData);
+
+		/* only use L if we have an auth code,
+		 * and the track is from the correct service (ie not for a Libre.fm track scrobbling to Last.fm)
+		 */
+		if (track_data->track_auth != NULL && track_data->service == service) {
+			as_entry->source = g_strdup_printf ("L%s", track_data->track_auth);
+		} else {
+			as_entry->source = g_strdup ("E");
+		}
+	} else {
+		as_entry->source = g_strdup ("P");
+	}
 
 	return as_entry;
 }
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-entry.h b/plugins/audioscrobbler/rb-audioscrobbler-entry.h
index 89ab70e..ddb31c4 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-entry.h
+++ b/plugins/audioscrobbler/rb-audioscrobbler-entry.h
@@ -31,6 +31,7 @@
 G_BEGIN_DECLS
 
 #include "rhythmdb.h"
+#include "rb-audioscrobbler-service.h"
 
 #define EXTRA_URI_ENCODE_CHARS	"&+"
 
@@ -64,7 +65,7 @@ void	     			rb_audioscrobbler_entry_free (AudioscrobblerEntry *entry);
 void          			rb_audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry);
 AudioscrobblerEncodedEntry *	rb_audioscrobbler_entry_encode (AudioscrobblerEntry *entry);
 
-AudioscrobblerEntry *		rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry);
+AudioscrobblerEntry *		rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry, RBAudioscrobblerService *service);
 
 AudioscrobblerEntry *		rb_audioscrobbler_entry_load_from_string (const char *string);
 void				rb_audioscrobbler_entry_save_to_string (GString *string, AudioscrobblerEntry *entry);
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
index 7a252c8..877c049 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
@@ -42,6 +42,7 @@
 #include <totem-pl-parser.h>
 
 #include "rb-audioscrobbler-radio-source.h"
+#include "rb-audioscrobbler-radio-track-entry.h"
 #include "rb-lastfm-play-order.h"
 #include "rb-debug.h"
 #include "rb-sourcelist.h"
@@ -103,25 +104,6 @@ rb_audioscrobbler_radio_type_get_default_name (RBAudioscrobblerRadioType type)
 	return radio_names[type];
 }
 
-/* entry data stuff */
-typedef struct
-{
-	char *image_url;
-	char *track_auth;
-	char *download_url;
-} RBAudioscrobblerRadioTrackEntryData;
-
-static void
-destroy_track_data (RhythmDBEntry *entry, gpointer meh)
-{
-	RBAudioscrobblerRadioTrackEntryData *data;
-
-	data = RHYTHMDB_ENTRY_GET_TYPE_DATA(entry, RBAudioscrobblerRadioTrackEntryData);
-	g_free (data->image_url);
-	g_free (data->track_auth);
-	g_free (data->download_url);
-}
-
 /* source declarations */
 struct _RBAudioscrobblerRadioSourcePrivate
 {
@@ -277,26 +259,17 @@ rb_audioscrobbler_radio_source_new (RBAudioscrobblerProfileSource *parent,
 	RBShell *shell;
 	RBPlugin *plugin;
 	RhythmDB *db;
-	RhythmDBEntryType track_entry_type;
 
 	g_object_get (parent, "shell", &shell, "plugin", &plugin, NULL);
 	g_object_get (shell, "db", &db, NULL);
 
-	track_entry_type = rhythmdb_entry_type_get_by_name (db, "audioscrobbler-radio-track");
-	if (track_entry_type == RHYTHMDB_ENTRY_TYPE_INVALID) {
-		track_entry_type = rhythmdb_entry_register_type (db, "audioscrobbler-radio-track");
-		track_entry_type->save_to_disk = FALSE;
-		track_entry_type->category = RHYTHMDB_ENTRY_NORMAL;
-
-		track_entry_type->entry_type_data_size = sizeof (RBAudioscrobblerRadioTrackEntryData);
-		track_entry_type->pre_entry_destroy = destroy_track_data;
-	}
+	rb_audioscrobbler_radio_track_register_entry_type (db);
 
 	source = g_object_new (RB_TYPE_AUDIOSCROBBLER_RADIO_SOURCE,
 	                       "shell", shell,
 	                       "plugin", plugin,
 	                       "name", station_name,
-	                       "entry-type", track_entry_type,
+	                       "entry-type", RHYTHMDB_ENTRY_TYPE_AUDIOSCROBBLER_RADIO_TRACK,
 	                       "parent", parent,
 	                       "service", service,
                                "username", username,
@@ -935,7 +908,7 @@ xspf_entry_parsed (TotemPlParser *parser,
 	RhythmDB *db;
 
 	RhythmDBEntry *entry;
-	RBAudioscrobblerRadioTrackEntryData *track_data;
+	RBAudioscrobblerRadioTrackData *track_data;
 	const char *value;
 	GValue v = {0,};
 	int i;
@@ -959,7 +932,8 @@ xspf_entry_parsed (TotemPlParser *parser,
 	} else {
 		rb_debug ("track entry %s already exists", uri);
 	}
-	track_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioscrobblerRadioTrackEntryData);
+	track_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioscrobblerRadioTrackData);
+	track_data->service = source->priv->service;
 
 	/* straightforward string copying */
 	for (i = 0; i < G_N_ELEMENTS (field_mapping); i++) {
@@ -1306,7 +1280,7 @@ delete_station_action_cb (GtkAction *action, RBAudioscrobblerRadioSource *source
 static const char *
 get_image_url_for_entry (RBAudioscrobblerRadioSource *source, RhythmDBEntry *entry)
 {
-	RBAudioscrobblerRadioTrackEntryData *data;
+	RBAudioscrobblerRadioTrackData *data;
 	RhythmDBEntryType entry_type;
 
 	if (entry == NULL) {
@@ -1319,7 +1293,7 @@ get_image_url_for_entry (RBAudioscrobblerRadioSource *source, RhythmDBEntry *ent
 		return NULL;
 	}
 
-	data = RHYTHMDB_ENTRY_GET_TYPE_DATA(entry, RBAudioscrobblerRadioTrackEntryData);
+	data = RHYTHMDB_ENTRY_GET_TYPE_DATA(entry, RBAudioscrobblerRadioTrackData);
 	return data->image_url;
 }
 
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.c b/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.c
new file mode 100644
index 0000000..a2c045c
--- /dev/null
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.c
@@ -0,0 +1,62 @@
+/*
+ * rb-audioscrobbler-radio-track-entry.c
+ *
+ * Copyright (C) 2010 Jamie Nicol <jamie thenicols net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ */
+
+#include "rb-audioscrobbler-radio-track-entry.h"
+
+static RhythmDBEntryType type = RHYTHMDB_ENTRY_TYPE_INVALID;
+
+static void
+destroy_track_data (RhythmDBEntry *entry, gpointer meh)
+{
+	RBAudioscrobblerRadioTrackData *data;
+	data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioscrobblerRadioTrackData);
+
+	g_free (data->image_url);
+	g_free (data->track_auth);
+	g_free (data->download_url);
+}
+
+void
+rb_audioscrobbler_radio_track_register_entry_type (RhythmDB *db)
+{
+	type = rhythmdb_entry_type_get_by_name (db, "audioscrobbler-radio-track");
+	if (type == RHYTHMDB_ENTRY_TYPE_INVALID) {
+		type = rhythmdb_entry_register_type (db, "audioscrobbler-radio-track");
+		type->save_to_disk = FALSE;
+		type->category = RHYTHMDB_ENTRY_NORMAL;
+
+		type->entry_type_data_size = sizeof (RBAudioscrobblerRadioTrackData);
+		type->pre_entry_destroy = destroy_track_data;
+	}
+}
+
+RhythmDBEntryType
+rhythmdb_entry_audioscrobbler_radio_track_get_type (void)
+{
+	return type;
+}
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.h b/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.h
new file mode 100644
index 0000000..f3b14b9
--- /dev/null
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.h
@@ -0,0 +1,49 @@
+/*
+ * rb-audioscrobbler-radio-track-entry.c
+ *
+ * Copyright (C) 2010 Jamie Nicol <jamie thenicols net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ */
+
+#ifndef __RB_AUDIOSCROBBLER_RADIO_TRACK_ENTRY_H
+#define __RB_AUDIOSCROBBLER_RADIO_TRACK_ENTRY_H
+
+#include "rhythmdb.h"
+#include "rb-audioscrobbler-service.h"
+
+#define RHYTHMDB_ENTRY_TYPE_AUDIOSCROBBLER_RADIO_TRACK (rhythmdb_entry_audioscrobbler_radio_track_get_type ())
+
+typedef struct
+{
+	char *image_url;
+	char *track_auth;
+	char *download_url;
+	RBAudioscrobblerService *service;
+} RBAudioscrobblerRadioTrackData;
+
+void rb_audioscrobbler_radio_track_register_entry_type (RhythmDB *db);
+
+RhythmDBEntryType rhythmdb_entry_audioscrobbler_radio_track_get_type (void);
+
+#endif /* #ifndef __RB_AUDIOSCROBBLER_RADIO_TRACK_ENTRY_H */
diff --git a/plugins/audioscrobbler/rb-audioscrobbler.c b/plugins/audioscrobbler/rb-audioscrobbler.c
index 8ae5cea..8a62426 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler.c
@@ -696,7 +696,7 @@ rb_audioscrobbler_offline_play_notify_cb (RhythmDB *db,
 	if (rb_audioscrobbler_is_queueable (rb_entry)) {
 		AudioscrobblerEntry *as_entry;
 		
-		as_entry = rb_audioscrobbler_entry_create (rb_entry);
+		as_entry = rb_audioscrobbler_entry_create (rb_entry, audioscrobbler->priv->service);
 		as_entry->play_time = g_value_get_ulong (metadata);
 		rb_audioscrobbler_add_to_queue (audioscrobbler, as_entry);
 	}
@@ -1085,7 +1085,7 @@ rb_audioscrobbler_song_changed_cb (RBShellPlayer *player,
 		/* even if it's the same song, it's being played again from
 		 * the start so we can queue it again.
 		 */
-		as_entry = rb_audioscrobbler_entry_create (entry);
+		as_entry = rb_audioscrobbler_entry_create (entry, audioscrobbler->priv->service);
 		as_entry->play_time = time (NULL);
 		audioscrobbler->priv->currently_playing = as_entry;
 		audioscrobbler->priv->now_playing_updated = FALSE;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 67a226b..77df821 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -36,8 +36,9 @@ test_rb_lib_SOURCES = \
 	$(test_utils)
 
 test_audioscrobbler_SOURCES = \
-	test-audioscrobbler.c					\
-	$(top_srcdir)/plugins/audioscrobbler/rb-audioscrobbler-entry.c \
+	test-audioscrobbler.c								\
+	$(top_srcdir)/plugins/audioscrobbler/rb-audioscrobbler-entry.c			\
+	$(top_srcdir)/plugins/audioscrobbler/rb-audioscrobbler-radio-track-entry.c	\
 	$(test_utils)
 
 test_widgets_SOURCES = \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]