diff --git a/plugins/audioscrobbler/Makefile.am b/plugins/audioscrobbler/Makefile.am
index 8ab5eae..44c43de 100644
--- a/plugins/audioscrobbler/Makefile.am
+++ b/plugins/audioscrobbler/Makefile.am
@@ -4,7 +4,10 @@ plugin_LTLIBRARIES = libaudioscrobbler.l
 libaudioscrobbler_la_SOURCES = \
 	rb-audioscrobbler-plugin.c			\
 	rb-audioscrobbler.c				\
-	rb-audioscrobbler.h
+	rb-audioscrobbler.h				\
+	rb-lastfm-source.c				\
+	rb-lastfm-source.h
+	
 	
 libaudioscrobbler_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
 libaudioscrobbler_la_LIBADD = 				\
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
old mode 100644
new mode 100755
index ba23e2a..e23b26d
--- a/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-plugin.c
@@ -30,6 +30,7 @@ #include <glib.h>
 #include <glib-object.h>
 
 #include "rb-audioscrobbler.h"
+#include "rb-lastfm-source.h"
 #include "rb-plugin.h"
 #include "rb-debug.h"
 #include "rb-shell.h"
@@ -48,6 +49,8 @@ typedef struct
 	RBPlugin parent;
 	RBAudioscrobbler *audioscrobbler;
 	GtkWidget *preferences;
+
+	RBSource *lastfm_source;
 } RBAudioscrobblerPlugin;
 
 typedef struct
@@ -129,6 +132,9 @@ impl_activate (RBPlugin *bplugin,
 								proxy_config);
 	}
 	g_object_unref (G_OBJECT (proxy_config));
+
+	plugin->lastfm_source = rb_lastfm_source_new (shell);
+	rb_shell_append_source (shell, plugin->lastfm_source, NULL);
 }
 
 static void
@@ -137,6 +143,9 @@ impl_deactivate	(RBPlugin *bplugin,
 {
 	RBAudioscrobblerPlugin *plugin = RB_AUDIOSCROBBLER_PLUGIN (bplugin);
 
+	rb_source_delete_thyself (plugin->lastfm_source);
+	plugin->lastfm_source = NULL;
+
 	if (plugin->audioscrobbler) {
 		g_object_unref (plugin->audioscrobbler);
 		plugin->audioscrobbler = NULL;
@@ -161,15 +170,11 @@ impl_create_configure_dialog (RBPlugin *
 
 		widget =  rb_audioscrobbler_get_config_widget (plugin->audioscrobbler);
 
-		plugin->preferences = gtk_dialog_new_with_buttons (_("Last.fm Profile Preferences"),
+		plugin->preferences = gtk_dialog_new_with_buttons (_("Audioscrobbler preferences"),
 								   NULL,
 								   GTK_DIALOG_DESTROY_WITH_PARENT,
 								   GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 								   NULL);
-		gtk_container_set_border_width (GTK_CONTAINER (plugin->preferences), 5);
-		gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (plugin->preferences)->vbox), 2);
-		gtk_dialog_set_has_separator (GTK_DIALOG (plugin->preferences), FALSE);
-		
 		g_signal_connect (G_OBJECT (plugin->preferences),
 				  "response",
 				  G_CALLBACK (preferences_response_cb),
@@ -182,4 +187,3 @@ impl_create_configure_dialog (RBPlugin *
 	gtk_widget_show_all (plugin->preferences);
 	return plugin->preferences;
 }
-
diff --git a/plugins/audioscrobbler/rb-lastfm-source.c b/plugins/audioscrobbler/rb-lastfm-source.c
new file mode 100755
index 0000000..e15a51d
--- /dev/null
+++ b/plugins/audioscrobbler/rb-lastfm-source.c
@@ -0,0 +1,1017 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * 
+ *  arch-tag: Implementation of last.fm station source object
+ *
+ *  Copyright (C) 2006 Matt Novenstern <fisxoj@gmail.com>
+ *
+ *  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 of the License, or
+ *  (at your option) any later 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.
+ *
+ */
+
+/*  The author would like to extend thanks to Ian Holmes, author of Last Exit,
+*   an alternative last.fm player written in C#, the code of which was
+*   extraordinarily useful in the creation of this code
+*/
+
+/* TODO LIST
+*  1. Create interface, menu option to add station (artist or tag)
+*  2. Automatically add neighbor radio, since it is available by default - DONE
+*  3. if subscriber, make user radio (low priority)
+*  4. Code for adding lastfm:// URIs to DB
+*/
+
+
+#include <config.h>
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <glade/glade.h>
+
+#include <gconf/gconf-value.h>
+
+#include <libsoup/soup.h>
+#include <libsoup/soup-uri.h>
+
+#include "md5.h"
+
+#include "eel-gconf-extensions.h"
+
+#include "rb-proxy-config.h"
+#include "rb-preferences.h"
+
+#include "rb-audioscrobbler.h"
+#include "rb-lastfm-source.h"
+
+#include "rhythmdb-query-model.h"
+#include "rb-glade-helpers.h"
+#include "rb-stock-icons.h"
+#include "rb-entry-view.h"
+#include "rb-property-view.h"
+#include "rb-util.h"
+#include "rb-file-helpers.h"
+#include "rb-preferences.h"
+#include "rb-dialog.h"
+#include "rb-station-properties-dialog.h"
+#include "rb-new-station-dialog.h"
+#include "rb-debug.h"
+#include "eel-gconf-extensions.h"
+
+#define LASTFM_URL "http://ws.audioscrobbler.com"
+#define PLATFORM_STRING "linux"
+#define RB_LASTFM_VERSION "1.1.1"
+#define EXTRA_URI_ENCODE_CHARS	"&+"
+
+
+static void rb_lastfm_source_class_init (RBLastfmSourceClass *klass);
+static void rb_lastfm_source_init (RBLastfmSource *source);
+static GObject *rb_lastfm_source_constructor (GType type, guint n_construct_properties,
+					      GObjectConstructParam *construct_properties);
+static void rb_lastfm_source_finalize (GObject *object);
+static void rb_lastfm_source_set_property (GObject *object,
+			                  guint prop_id,
+			                  const GValue *value,
+			                  GParamSpec *pspec);
+static void rb_lastfm_source_get_property (GObject *object,
+			                  guint prop_id,
+			                  GValue *value,
+			                  GParamSpec *pspec);
+
+static void rb_lastfm_source_songs_view_sort_order_changed_cb (RBEntryView *view,
+							       RBLastfmSource *source);
+static void rb_lastfm_source_do_query (RBLastfmSource *source);
+
+//source-specific methods
+static void rb_lastfm_source_do_handshake (RBLastfmSource *source);
+static char * rb_lastfm_source_get_password (void);
+static char * rb_lastfm_source_get_username (void);
+static char * rb_lastfm_source_get_playback_uri (RhythmDBEntry *entry, gpointer data);
+static void rb_lastfm_perform (RBLastfmSource *lastfm,
+			   char *url,
+			   char *post_data,
+			   SoupMessageCallbackFn response_handler);
+void rb_lastfm_message_cb (SoupMessage *req, gpointer user_data);
+static void rb_lastfm_change_station (char *station, RBLastfmSource *source);
+
+static void	     rb_lastfm_proxy_config_changed_cb (RBProxyConfig *config,
+								RBLastfmSource *source);
+static void rb_lastfm_source_drag_cb (GtkWidget *widget,
+				     GdkDragContext *dc,
+				     gint x, gint y,
+				     GtkSelectionData *selection_data, 
+				     guint info, guint time,
+				     RBLastfmSource *source);
+
+static void rb_lastfm_source_dispose (GObject *object);
+								
+static gchar *	     mkmd5 (char *string);
+
+/* RBSource implementation methods */
+static void impl_delete (RBSource *asource);
+static GList *impl_get_ui_actions (RBSource *source);
+static RBEntryView *impl_get_entry_view (RBSource *asource);
+static void impl_get_status (RBSource *asource, char **text, char **progress_text, float *progress);
+static RBSourceEOFType impl_handle_eos (RBSource *asource);
+static gboolean impl_receive_drag 			(RBSource *source, GtkSelectionData *data);
+//static void impl_delete_thyself (RBSource *asource);
+
+void rb_lastfm_source_new_station (char *uri, char *title, RBLastfmSource *source);
+static void rb_lastfm_source_skip_track (GtkAction *action, RBLastfmSource *source);
+static void rb_lastfm_source_love_track (GtkAction *action, RBLastfmSource *source);
+static void rb_lastfm_source_ban_track (GtkAction *action, RBLastfmSource *source);
+static char *rb_lastfm_source_title_from_uri (char *uri);
+
+struct RBLastfmSourcePrivate
+{
+	GtkWidget *vbox;
+	GtkWidget *paned;
+	/*GtkWidget *vbox2;
+	GtkWidget *hbox;
+	GtkWidget *tuner;
+	GtkWidget *gobutton;
+	GtkWidget *typecombo;
+	GtkWidget *label; */
+	RhythmDB *db;
+
+	GtkActionGroup *action_group;
+	
+	RBEntryView *stations;
+
+	RhythmDBEntryType entry_type;
+	char *session;
+	
+	gboolean subscriber;
+	char *base_url;
+	char *base_path;
+	char *stream_url;
+	gboolean framehack;
+	char *update_url;
+	gboolean banned;
+	gboolean connected;
+	
+	char *status;
+	
+	SoupSession *soup_session;
+	RBProxyConfig *proxy_config;
+};
+
+G_DEFINE_TYPE (RBLastfmSource, rb_lastfm_source, RB_TYPE_SOURCE);
+#define RB_LASTFM_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_LASTFM_SOURCE, RBLastfmSourcePrivate))
+
+enum
+{
+	PROP_0,
+	PROP_ENTRY_TYPE,
+	PROP_SHELL_PLAYER,
+	PROP_PROXY_CONFIG
+};
+
+static GtkActionEntry rb_lastfm_source_actions [] =
+{
+	{ "LastfmSkipSong", GTK_STOCK_MEDIA_NEXT, N_("Next Song"), NULL,
+	  N_("Skip the current track"),
+	  G_CALLBACK (rb_lastfm_source_skip_track) },
+	{ "LastfmLoveSong", GTK_STOCK_ADD, N_("<3 Song"), NULL,
+	  N_("Mark this song as loved"),
+	  G_CALLBACK (rb_lastfm_source_love_track) },
+	{ "LastfmBanSong", GTK_STOCK_CANCEL, N_("Ban Song"), NULL,
+	  N_("Ban the current track from being played again"),
+	  G_CALLBACK (rb_lastfm_source_ban_track) }
+};
+
+static const GtkTargetEntry lastfm_drag_types[] = {
+	{  "text/plain", 0, 0 },
+	{  "_NETSCAPE_URL", 0, 1 }
+};
+
+static void
+rb_lastfm_source_class_init (RBLastfmSourceClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	RBSourceClass *source_class = RB_SOURCE_CLASS (klass);
+
+	object_class->finalize = rb_lastfm_source_finalize;
+	object_class->dispose = rb_lastfm_source_dispose;
+	object_class->constructor = rb_lastfm_source_constructor;
+
+	object_class->set_property = rb_lastfm_source_set_property;
+	object_class->get_property = rb_lastfm_source_get_property;
+
+	source_class->impl_can_copy = (RBSourceFeatureFunc) rb_false_function;
+	source_class->impl_can_delete = (RBSourceFeatureFunc) rb_false_function;
+	source_class->impl_can_pause = (RBSourceFeatureFunc) rb_false_function;
+	source_class->impl_delete = impl_delete;
+	source_class->impl_get_entry_view = impl_get_entry_view;
+	source_class->impl_get_status = impl_get_status;
+	source_class->impl_get_ui_actions = impl_get_ui_actions;
+	source_class->impl_handle_eos = impl_handle_eos;
+	source_class->impl_receive_drag = impl_receive_drag;
+	//source_class->impl_delete_thyself = impl_delete_thyself;
+
+	g_object_class_install_property (object_class,
+					 PROP_ENTRY_TYPE,
+					 g_param_spec_pointer ("entry-type",
+							       "Entry type",
+							       "Type of the entries which should be displayed by this source",
+							       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+	g_object_class_install_property (object_class,
+					 PROP_PROXY_CONFIG,
+					 g_param_spec_object ("proxy-config",
+							      "RBProxyConfig",
+							      "RBProxyConfig object",
+							      RB_TYPE_PROXY_CONFIG,
+							      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+
+	g_type_class_add_private (klass, sizeof (RBLastfmSourcePrivate));
+}
+
+static void
+rb_lastfm_source_init (RBLastfmSource *source)
+{
+	gint size;
+	GdkPixbuf *pixbuf;
+
+	source->priv = RB_LASTFM_SOURCE_GET_PRIVATE (source);
+
+	source->priv->vbox = gtk_vbox_new (FALSE, 5);
+
+	gtk_container_add (GTK_CONTAINER (source), source->priv->vbox);
+	
+	gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
+	pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+					   "stock_channel",
+					   size,
+					   0, NULL);
+	rb_source_set_pixbuf (RB_SOURCE (source), pixbuf);
+	if (pixbuf != NULL) {
+		g_object_unref (pixbuf);
+	}
+	
+}
+
+static void
+rb_lastfm_source_finalize (GObject *object)
+{
+	RBLastfmSource *source;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (RB_IS_LASTFM_SOURCE (object));
+
+	source = RB_LASTFM_SOURCE (object);
+
+	g_return_if_fail (source->priv != NULL);
+
+	rb_debug ("finalizing lastfm source");
+
+	if (source->priv->db) {
+		g_object_unref (source->priv->db);
+		source->priv->db = NULL;
+	}
+	g_object_unref (G_OBJECT (source->priv->proxy_config));
+
+	G_OBJECT_CLASS (rb_lastfm_source_parent_class)->finalize (object);
+}
+
+static GObject *
+rb_lastfm_source_constructor (GType type, guint n_construct_properties,
+			      GObjectConstructParam *construct_properties)
+{
+	RBLastfmSource *source;
+	RBLastfmSourceClass *klass;
+	RBShell *shell;
+	GObject *shell_player;
+	
+	klass = RB_LASTFM_SOURCE_CLASS (g_type_class_peek (RB_TYPE_LASTFM_SOURCE));
+
+	source = RB_LASTFM_SOURCE (G_OBJECT_CLASS (rb_lastfm_source_parent_class)
+			->constructor (type, n_construct_properties, construct_properties));
+
+	g_object_get (G_OBJECT (source), "shell", &shell, NULL);
+	g_object_get (G_OBJECT (shell), "db", &source->priv->db, NULL);
+	shell_player = rb_shell_get_player (shell);
+	g_object_unref (G_OBJECT (shell));
+
+	//Set up station tuner
+	/*source->priv->tuner = gtk_vbox_new (FALSE, 5);
+	source->priv->vbox2 = gtk_vbox_new (FALSE, 5);
+	source->priv->hbox = gtk_hbox_new (FALSE, 5);
+	
+	source->priv->label = gtk_label_new ("Enter the artist or global tag to build a radio station out of:");
+	
+	source->priv->gobutton = gtk_button_new_with_label ("Add");
+	g_signal_connect_object (G_OBJECT (source->priv->gobutton),
+				 "clicked",
+				 G_CALLBACK (rb_lastfm_source_add_station_cb),
+				 source, 0);
+	source->priv->typecombo = gtk_combo_box_new_text ();
+	gtk_combo_box_append_text (GTK_COMBO_BOX (source->priv->typecombo), "Artist");
+	gtk_combo_box_append_text (GTK_COMBO_BOX (source->priv->typecombo), "Tag");
+	
+	gtk_box_pack_start_defaults (GTK_BOX (source->priv->hbox),
+								 GTK_WIDGET (source->priv->typecombo)); */
+	
+	/* set up stations view */
+	source->priv->stations = rb_entry_view_new (source->priv->db, shell_player,
+						    NULL,
+						    FALSE, FALSE);
+	rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_TITLE, TRUE);
+	// rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_GENRE, FALSE);
+	rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_RATING, TRUE);
+	rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_LAST_PLAYED, TRUE);
+	g_signal_connect_object (G_OBJECT (source->priv->stations),
+				 "sort-order-changed",
+				 G_CALLBACK (rb_lastfm_source_songs_view_sort_order_changed_cb),
+				 source, 0);
+
+	// Drag and drop URIs
+	g_signal_connect_object (G_OBJECT (source->priv->stations), 
+				 "drag_data_received",
+				 G_CALLBACK (rb_lastfm_source_drag_cb),
+				 source, 0);
+	gtk_drag_dest_set (GTK_WIDGET (source->priv->stations),
+			   GTK_DEST_DEFAULT_ALL,
+			   lastfm_drag_types, 2,
+			   GDK_ACTION_COPY | GDK_ACTION_MOVE);
+	
+	// Pack the vbox
+	/*gtk_paned_pack1 (GTK_PANED (source->priv->paned),
+					 GTK_WIDGET (source->priv->tuner), FALSE, FALSE); */
+	
+	gtk_paned_pack2 (GTK_PANED (source->priv->paned),
+			 GTK_WIDGET (source->priv->stations), TRUE, FALSE);
+	
+	gtk_box_pack_start_defaults (GTK_BOX (source->priv->vbox), GTK_WIDGET (source->priv->stations));
+	
+	source->priv->paned = gtk_vpaned_new ();
+	
+	gtk_widget_show_all (GTK_WIDGET (source));
+	
+	//Source type register moved to rb_lastfm_source_new...
+/*	if (source->priv->entry_type == RHYTHMDB_ENTRY_TYPE_INVALID ||
+	    source->priv->entry_type == NULL)
+		source->priv->entry_type = LASTFM_STATION_ENTRY_TYPE; */
+	
+	source->priv->entry_type->get_playback_uri = (RhythmDBEntryStringFunc) rb_lastfm_source_get_playback_uri;
+	source->priv->entry_type->get_playback_uri_data = source;
+	
+	source->priv->action_group = _rb_source_register_action_group (RB_SOURCE (source),
+								       "LastfmActions",
+								       rb_lastfm_source_actions,
+								       G_N_ELEMENTS (rb_lastfm_source_actions),
+								       source);
+	
+	rb_lastfm_source_do_query (source);
+
+	return G_OBJECT (source);
+}
+
+static void
+rb_lastfm_source_set_property (GObject *object,
+			      guint prop_id,
+			      const GValue *value,
+			      GParamSpec *pspec)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE (object);
+
+	switch (prop_id) {
+	case PROP_ENTRY_TYPE:
+		source->priv->entry_type = g_value_get_pointer (value);
+		break;
+	case PROP_PROXY_CONFIG:
+			source->priv->proxy_config = g_value_get_object (value);
+			g_object_ref (G_OBJECT (source->priv->proxy_config));
+			g_signal_connect_object (G_OBJECT (source->priv->proxy_config),
+						 "config-changed",
+						 G_CALLBACK (rb_lastfm_proxy_config_changed_cb),
+						 source, 0);
+			break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+rb_lastfm_source_get_property (GObject *object,
+			      guint prop_id,
+			      GValue *value,
+			      GParamSpec *pspec)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE (object);
+
+	switch (prop_id) {
+	case PROP_ENTRY_TYPE:
+		g_value_set_pointer (value, source->priv->entry_type);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+RBSource *
+rb_lastfm_source_new (RBShell *shell)
+{
+	RBSource *source;
+	RBProxyConfig *proxy_config;
+	RhythmDBEntryType type;
+	char *uri;
+	
+	type = rhythmdb_entry_register_type(NULL);
+	
+	g_object_get (G_OBJECT (shell), 
+		      "proxy-config", &proxy_config,
+			  NULL);
+	
+	source = RB_SOURCE (g_object_new (RB_TYPE_LASTFM_SOURCE,
+					  "name", _("Last.fm"),
+					  "shell", shell,
+					  "entry-type", type,
+					  "proxy-config", proxy_config,
+					  NULL));
+	rb_shell_register_entry_type_for_source (shell, source, 
+						 type);
+	
+	//create default neighbour radio station
+	uri = g_strdup_printf("lastfm://user/%s/neighbours", rb_lastfm_source_get_username());
+	rb_lastfm_source_new_station(
+		uri,
+		_("Neighbour Radio"),
+		RB_LASTFM_SOURCE (source));
+	
+	g_object_unref(proxy_config);
+	g_free(uri);
+	return source;
+}
+
+static GList*
+impl_get_ui_actions (RBSource *source)
+{
+	GList *actions = NULL;
+	
+	actions = g_list_prepend (actions, g_strdup ("LastfmLoveSong"));
+	actions = g_list_prepend (actions, g_strdup ("LastfmBanSong"));
+	actions = g_list_prepend (actions, g_strdup ("LastfmSkipSong"));
+
+	return actions;
+}
+
+static RBEntryView *
+impl_get_entry_view (RBSource *asource)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE (asource);
+
+	return source->priv->stations;
+}
+
+static RBSourceEOFType
+impl_handle_eos (RBSource *asource)
+{
+	return RB_SOURCE_EOF_RETRY;
+}
+
+static void
+impl_get_status (RBSource *asource, char **text, char **progress_text, float *progress)
+{
+	RhythmDBQueryModel *model;
+	guint num_entries;
+	RBLastfmSource *source = RB_LASTFM_SOURCE (asource);
+
+	g_object_get (G_OBJECT (source), "query-model", &model, NULL);
+	num_entries = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL);
+	g_object_unref (G_OBJECT (model));
+
+	//*text = g_strdup_printf (ngettext ("%d station", "%d stations", num_entries),
+	//		       num_entries);
+	*text = g_strdup_printf("Status: %s",source->priv->status);
+}
+
+static void
+impl_delete (RBSource *asource)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE (asource);
+	GList *l;
+
+	for (l = rb_entry_view_get_selected_entries (source->priv->stations); l != NULL; l = g_list_next (l)) {
+		rhythmdb_entry_delete (source->priv->db, l->data);
+	}
+
+	rhythmdb_commit (source->priv->db);
+}
+
+static void
+rb_lastfm_source_songs_view_sort_order_changed_cb (RBEntryView *view,
+						   RBLastfmSource *source)
+{
+	rb_debug ("sort order changed");
+
+	rb_entry_view_resort_model (view);
+}
+
+static void
+rb_lastfm_source_do_query (RBLastfmSource *source)
+{
+	RhythmDBQueryModel *station_query_model = NULL;
+	GPtrArray *query;
+
+	query = rhythmdb_query_parse (source->priv->db,
+				      RHYTHMDB_QUERY_PROP_EQUALS,
+				      RHYTHMDB_PROP_TYPE,
+				      source->priv->entry_type,
+				      RHYTHMDB_QUERY_END);
+	station_query_model = rhythmdb_query_model_new_empty (source->priv->db);
+	rhythmdb_do_full_query_parsed (source->priv->db, 
+				       RHYTHMDB_QUERY_RESULTS (station_query_model), 
+				       query);
+
+	rhythmdb_query_free (query);
+	query = NULL;
+	
+	rb_entry_view_set_model (source->priv->stations, station_query_model);
+	g_object_set (G_OBJECT (source), "query-model", station_query_model, NULL);
+
+	g_object_unref (G_OBJECT (station_query_model));
+}
+
+/*RhythmDBEntryType rhythmdb_entry_lastfm_get_type (void) 
+{
+	static RhythmDBEntryType lastfm_type = RHYTHMDB_ENTRY_TYPE_INVALID;
+       
+	if (lastfm_type == RHYTHMDB_ENTRY_TYPE_INVALID) {
+		lastfm_type = rhythmdb_entry_register_type (NULL);
+	}
+
+	return lastfm_type;
+}
+*/
+
+static void rb_lastfm_source_do_handshake (RBLastfmSource *source)
+{
+	char *password = "";
+	char *username = "";
+	
+	// Retrieve password from GConf, which is managed by the audioscrobbler plugin.
+
+	password = rb_lastfm_source_get_password();
+		rb_debug ("Last.fm password: %s", password);
+	
+	username = rb_lastfm_source_get_username();
+		rb_debug("Last.fm username: %s", username);
+	if (strcmp(username,"") == 0 || strcmp(password, "") == 0) {
+		rb_debug ("no username or no password");
+		return;
+	}
+	
+	source->priv->status = _("Preforming Handshake with server");
+	char *HandshakeURL = g_strdup_printf("%s/radio/handshake.php?version=1.1.1&platform=linux&username=%s&passwordmd5=%s&debug=0&partner=",
+							LASTFM_URL,
+							username,
+							password);
+	rb_debug("Last.fm sending handshake");
+	rb_lastfm_perform (source, HandshakeURL, NULL, rb_lastfm_message_cb);
+	g_free(HandshakeURL);
+	g_free(username);
+	g_free(password);
+	return;
+}
+
+static char * rb_lastfm_source_get_password (void)
+{
+	gchar *pass;
+	gchar *md5_pass;
+	pass = eel_gconf_get_string (CONF_AUDIOSCROBBLER_PASSWORD);
+	md5_pass = mkmd5(pass);
+	
+	if (pass != NULL) {
+		pass = md5_pass;
+		return pass;
+	}
+	g_free(md5_pass);
+	g_free(pass);
+return "";
+}	
+
+static char * rb_lastfm_source_get_username (void)
+{
+	gchar *user;
+	user = eel_gconf_get_string (CONF_AUDIOSCROBBLER_USERNAME);
+	if (user != NULL) {
+		return user;
+	}
+	g_free(user);
+return "";
+}
+
+static char * rb_lastfm_source_get_playback_uri (RhythmDBEntry *entry, gpointer data)
+{
+	RBLastfmSource *source;
+	source = RB_LASTFM_SOURCE (data);
+
+	if (entry == NULL) {
+		rb_debug("NULL entry");
+	}
+	if (data == NULL) {
+		rb_debug("NULL source pointer");
+	}
+		
+	if (!source->priv->connected) {
+		rb_lastfm_source_do_handshake(source);
+		
+		return NULL;
+	}
+	
+
+	char *location;
+	location = (char *) rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
+	rb_lastfm_change_station (location, source);
+	rb_debug (source->priv->stream_url);
+	return g_strdup(source->priv->stream_url);
+}
+
+static void
+rb_lastfm_perform (RBLastfmSource *lastfm,
+			   char *url,
+			   char *post_data,
+			   SoupMessageCallbackFn response_handler)
+{
+	SoupMessage *msg;
+	msg = soup_message_new ("GET", url);
+	
+	if (msg == NULL)
+		return;
+	
+	soup_message_set_http_version (msg, SOUP_HTTP_1_1); // SOUP_HTTP_1_1 = 1
+	
+	rb_debug ("Last.fm commuinicating with %s", url);
+	
+	
+	if (post_data != NULL) {
+		rb_debug ("Communicating with Last.fm: %s", post_data);
+		soup_message_set_request (msg, 
+					  "application/x-www-form-urlencoded",
+					  SOUP_BUFFER_SYSTEM_OWNED, 
+					  post_data, 
+					  strlen (post_data));
+	}
+
+	/* create soup session, if we haven't got one yet */
+	if (!lastfm->priv->soup_session) {
+		SoupUri *uri;
+		
+		uri = rb_proxy_config_get_libsoup_uri (lastfm->priv->proxy_config);
+		lastfm->priv->soup_session = soup_session_async_new_with_options (
+					"proxy-uri", uri,
+					NULL);
+		if (uri)
+			soup_uri_free (uri);
+	}
+	
+	soup_session_queue_message (lastfm->priv->soup_session,
+				    msg,
+				    (SoupMessageCallbackFn) response_handler,
+				    lastfm);
+}
+
+void rb_lastfm_message_cb (SoupMessage *req, gpointer user_data)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE(user_data);
+	gchar *body;
+	
+	if ((req->response).body == NULL) {
+		rb_debug ("Lastfm: Server failed to respond:");
+		return;
+	}
+	
+	body = g_malloc0 ((req->response).length + 1);
+	memcpy (body, (req->response).body, (req->response).length);
+	
+	rb_debug("response body: %s", body);
+	
+	g_strstrip (body);
+	gchar **pieces = g_strsplit (body, "\n", 6);
+	
+	int i;
+	for (i = 0; pieces[i] != NULL; i++) {
+		gchar **values = g_strsplit (pieces[i], "=", 2);
+			if (strcmp(values[0],"session") ==0) {
+				if (strcmp(values[1],"FAILED") == 0) {
+					source->priv->status = _("Handshake failed");
+					rb_debug ("Lastfm failed to connect to the server");
+					return;
+				}
+				rb_debug(g_strdup_printf("Session ID: %s", values[1]));
+				source->priv->status = _("Handsake successful");
+				source->priv->session = g_strdup (values[1]);
+				rb_debug(source->priv->session);
+				source->priv->connected = TRUE;
+			} else if (strcmp(values[0],"stream_url") ==0) {
+				source->priv->stream_url = g_strdup (values[1]);
+				rb_debug(source->priv->stream_url);
+			} else if (strcmp(values[0],"subscriber") ==0) {
+				if (strcmp(values[1],"0") == 0) {
+					source->priv->subscriber = FALSE;
+				} else {
+					source->priv->subscriber = TRUE;
+				}
+			} else if (strcmp(values[0],"framehack") ==0) {
+				if (strcmp(values[1],"0") == 0) {
+					source->priv->framehack = FALSE;
+				} else {
+					source->priv->framehack = TRUE;
+				}
+			} else if (strcmp(values[0],"base_url") ==0) {
+				source->priv->base_url = g_strdup (values[1]);
+			} else if (strcmp(values[0],"base_path") ==0) {
+				source->priv->base_path = g_strdup (values[1]);
+			} else if (strcmp(values[0],"update_url") ==0) {
+				source->priv->update_url = g_strdup (values[1]);
+			} else if (strcmp(values[0],"banned") ==0) {
+				if (strcmp(values[1],"0") ==0) {
+					source->priv->banned = FALSE;
+				} else {
+					source->priv->status = _("The server marked you as banned, no connection");
+					source->priv->banned = TRUE;
+					source->priv->connected = FALSE;
+				}
+			} else if (strcmp(values[0],"response") ==0) {
+				if (strcmp(values[1], "OK") == 0) {
+					source->priv->status = _("Success!");
+					rb_debug("Successfully communicated");
+					source->priv->connected = TRUE;
+				} else {
+					source->priv->connected = FALSE;
+				}
+			} else if (strcmp(values[0],"stationname") ==0) {
+				rb_debug("Received station name from server: %s", values[1]);
+				gchar **data = g_strsplit (g_strdown(pieces[i - 1]), "=",2);
+				RhythmDBEntry *entry;
+				entry = rhythmdb_entry_lookup_by_location(source->priv->db, data[1]);
+				GValue titlestring = {0,};
+				g_value_init (&titlestring, G_TYPE_STRING);
+				g_value_set_string (&titlestring, values[1]);
+				
+				if (entry == NULL) {
+					entry = rhythmdb_entry_new (source->priv->db, source->priv->entry_type, data[1]);
+					rhythmdb_entry_set_uninserted (source->priv->db, entry, RHYTHMDB_PROP_TITLE, &titlestring);
+				} else {
+					rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_TITLE, &titlestring);
+				}
+				g_value_unset (&titlestring);
+				rhythmdb_commit (source->priv->db);
+				
+			}
+	}
+}
+
+static void rb_lastfm_change_station (char *station, RBLastfmSource *source)
+{
+	if (source->priv->connected != TRUE) {
+		rb_lastfm_source_do_handshake (source);
+		return;
+	}
+	
+	char *url;
+	//char *safe_station;
+	//gchar *base;
+	//base = g_strconcat(source->priv->base_url, source->priv->base_path, NULL);
+	
+	
+	url = g_strdup_printf("%s/radio/adjust.php?session=%s&url=%s&debug=0",
+		LASTFM_URL,
+		source->priv->session,
+		station);
+	
+	//g_free (base);
+	rb_lastfm_perform (source, url, NULL, rb_lastfm_message_cb);
+	g_free (url);
+	//g_free (safe_station);
+}
+
+static gchar *
+mkmd5 (char *string)
+{
+	md5_state_t md5state;
+	guchar md5pword[16];
+	gchar md5_response[33];
+
+	int j = 0;
+
+	memset (md5_response, 0, sizeof (md5_response));
+
+	md5_init (&md5state);
+	md5_append (&md5state, (unsigned char*)string, strlen (string));
+	md5_finish (&md5state, md5pword);
+
+	for (j = 0; j < 16; j++) {
+		char a[3];
+		sprintf (a, "%02x", md5pword[j]);
+		md5_response[2*j] = a[0];
+		md5_response[2*j+1] = a[1];
+	}
+
+	return (g_strdup (md5_response));
+}
+
+static void
+rb_lastfm_proxy_config_changed_cb (RBProxyConfig *config,
+					   RBLastfmSource *source)
+{
+	SoupUri *uri;
+
+	if (source->priv->soup_session) {
+		uri = rb_proxy_config_get_libsoup_uri (config);
+		g_object_set (G_OBJECT (source->priv->soup_session),
+					"proxy-uri", uri,
+					NULL);
+		if (uri)
+			soup_uri_free (uri);
+	}
+}
+
+
+void rb_lastfm_source_new_station (char *uri, char *title, RBLastfmSource *source)
+{
+	RhythmDBEntry *entry;
+	
+	rb_debug ("adding lastfm: %s, %s",uri, title);
+	
+	entry = rhythmdb_entry_lookup_by_location (source->priv->db, uri);
+	if (entry) {
+		rb_debug ("uri %s already in db", uri); 
+		return;
+	}
+	
+	entry = rhythmdb_entry_new (source->priv->db, source->priv->entry_type, uri);
+	GValue titlestring = {0,};
+	g_value_init (&titlestring, G_TYPE_STRING);
+	g_value_set_string (&titlestring, title);
+	rhythmdb_entry_set_uninserted (source->priv->db, entry, RHYTHMDB_PROP_TITLE, &titlestring);
+	g_value_unset (&titlestring);
+	g_value_init (&titlestring, G_TYPE_DOUBLE);
+	g_value_set_double (&titlestring, 0.0);
+	rhythmdb_entry_set_uninserted (source->priv->db, entry, RHYTHMDB_PROP_RATING, &titlestring);
+	rhythmdb_commit (source->priv->db);
+	return;
+}
+
+static void
+rb_lastfm_source_dispose (GObject *object)
+{
+	RBLastfmSource *source;
+
+	source = RB_LASTFM_SOURCE (object);
+
+	if (source->priv->db) {
+		g_object_unref (source->priv->db);
+		source->priv->db = NULL;
+	}
+
+	G_OBJECT_CLASS (rb_lastfm_source_parent_class)->dispose (object);
+}
+
+static void
+rb_lastfm_source_love_track (GtkAction *action, RBLastfmSource *source)
+{
+	if (source->priv->connected != TRUE) {
+		rb_lastfm_source_do_handshake (source);
+		return;
+	}
+	
+	source->priv->status = g_strdup ("Marking song loved...");
+	
+	char *url;
+	url = g_strdup_printf("%s/radio/control.php?session=%s&command=love&debug=0",
+		LASTFM_URL,
+		source->priv->session);
+	rb_lastfm_perform (source, url, NULL, rb_lastfm_message_cb);
+	g_free (url);
+}
+
+static void
+rb_lastfm_source_skip_track (GtkAction *action, RBLastfmSource *source)
+{
+	if (source->priv->connected != TRUE) {
+		rb_lastfm_source_do_handshake (source);
+		return;
+	}
+	
+	source->priv->status = g_strdup ("Skipping song...");
+	
+	char *url;
+
+	url = g_strdup_printf("%s/radio/control.php?session=%s&command=skip&debug=0",
+		LASTFM_URL, 
+		source->priv->session);
+	rb_lastfm_perform (source, url, NULL, rb_lastfm_message_cb);
+	g_free (url);
+}
+
+static void
+rb_lastfm_source_ban_track (GtkAction *action, RBLastfmSource *source)
+{
+	if (source->priv->connected != TRUE) {
+		rb_lastfm_source_do_handshake (source);
+		return;
+	}
+	
+	source->priv->status = g_strdup ("Banning song...");
+	
+	char *url;
+	url = g_strdup_printf("%s/radio/control.php?session=%s&command=ban&debug=0",
+		LASTFM_URL,
+		source->priv->session);
+	rb_lastfm_perform (source, url, NULL, rb_lastfm_message_cb);
+	g_free (url);
+	
+}
+
+
+static void
+rb_lastfm_source_drag_cb (GtkWidget *widget,
+				     GdkDragContext *dc,
+				     gint x, gint y,
+				     GtkSelectionData *selection_data, 
+				     guint info, guint time,
+				     RBLastfmSource *source)
+{
+	impl_receive_drag (RB_SOURCE (source) , selection_data);
+}
+
+static gboolean
+impl_receive_drag (RBSource *asource, GtkSelectionData *selection_data)
+{
+	char *uri;
+	char *title = NULL;
+	RBLastfmSource *source = RB_LASTFM_SOURCE (asource);
+	
+	uri = (char *)selection_data->data;
+	rb_debug ("parsing uri %s", uri);
+	
+	if (strstr(uri, "lastfm://") == NULL)
+		return FALSE;
+	
+	//title = g_strdup ("New Station");
+	title = rb_lastfm_source_title_from_uri (uri);
+	
+	
+	rb_lastfm_source_new_station (uri, title, source);
+	return TRUE;
+}
+
+
+static char *rb_lastfm_source_title_from_uri (char *uri)
+{
+	char *title = g_strstrip(uri);
+	gchar **data = g_strsplit (uri, "/", 0);
+	
+	if (strstr(uri, "globaltags") != NULL)
+		title = g_strdup_printf("Global Tag %s", data[3]);
+	
+	if (strcmp(data[2], "artist") == 0)
+	{
+		//Check if the station is from an artist page, if not, it is a similar
+		// artist station, and the server should return a name that change_station
+		// will handle for us.
+		if (data[4] != NULL) {
+			if (strcmp(data[4], "similarartists") == 0)
+				title = g_strdup_printf ("Artists similar to %s",data[3]);
+			if (strcmp(data[4], "fans") == 0)
+				title = g_strdup_printf ("Artists Liked by fans of %s",data[3]);
+		}
+			
+	}
+	
+	if (strcmp(data[2], "user") == 0)
+	{
+		if (strcmp(data[4], "neighbours") == 0)
+			title = g_strdup_printf ("%s's Neighbour Radio", data[3]);
+		//subscriber?
+	}
+	
+	
+return gnome_vfs_unescape_string (title, NULL);
+}
+
+/*
+static void 
+impl_delete_thyself (RBSource *asource)
+{
+	RBLastfmSource *source = RB_LASTFM_SOURCE (asource);
+	rhythmdb_entry_delete_by_type (source->priv->db, source->priv->entry_type);
+	rhythmdb_commit (source->priv->db);
+	rb_source_delete_thyself (RB_SOURCE (source));
+} */
diff --git a/plugins/audioscrobbler/rb-lastfm-source.h b/plugins/audioscrobbler/rb-lastfm-source.h
new file mode 100755
index 0000000..466910e
--- /dev/null
+++ b/plugins/audioscrobbler/rb-lastfm-source.h
@@ -0,0 +1,61 @@
+/* 
+ *  arch-tag: Header for last.fm station source
+ *
+ *  Copyright (C) 2006 Matt Novenstern  <fisxoj@gmail.com>
+ *
+ *  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 of the License, or
+ *  (at your option) any later 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_LASTFM_SOURCE_H
+#define __RB_LASTFM_SOURCE_H
+
+#include "rb-shell.h"
+#include "rb-source.h"
+
+G_BEGIN_DECLS
+
+#define RB_TYPE_LASTFM_SOURCE         (rb_lastfm_source_get_type ())
+#define RB_LASTFM_SOURCE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_LASTFM_SOURCE, RBLastfmSource))
+#define RB_LASTFM_SOURCE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_LASTFM_SOURCE, RBLastfmSourceClass))
+#define RB_IS_LASTFM_SOURCE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_LASTFM_SOURCE))
+#define RB_IS_LASTFM_SOURCE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_LASTFM_SOURCE))
+#define RB_LASTFM_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_LASTFM_SOURCE, RBLastfmSourceClass))
+
+typedef struct RBLastfmSourcePrivate RBLastfmSourcePrivate;
+
+typedef struct
+{
+	RBSource parent;
+
+	RBLastfmSourcePrivate *priv;
+} RBLastfmSource;
+
+typedef struct
+{
+	RBSourceClass parent;
+} RBLastfmSourceClass;
+
+GType		rb_lastfm_source_get_type	(void);
+GType           rb_lastfm_source_register_type    (GTypeModule *module);
+
+RBSource *	rb_lastfm_source_new		(RBShell *shell);
+
+void	lastfm_set_stream_URL 	(gchar URL);
+
+
+G_END_DECLS
+
+#endif /* __RB_LASTFM_SOURCE_H */
