[rhythmbox] context: add last.fm utility module



commit 6e84a2f271e14c38b42758f33ec3cd71c845c615
Author: Jonathan Matthew <jonathan fibula d14n org>
Date:   Sat Oct 31 20:49:07 2009 +1000

    context: add last.fm utility module
    
    Only using the API key and URL prefix from it so far.

 plugins/context/context/AlbumTab.py  |   13 ++++-----
 plugins/context/context/ArtistTab.py |   11 +++----
 plugins/context/context/LastFM.py    |   47 ++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 13 deletions(-)
---
diff --git a/plugins/context/context/AlbumTab.py b/plugins/context/context/AlbumTab.py
index 488fea1..9143c91 100644
--- a/plugins/context/context/AlbumTab.py
+++ b/plugins/context/context/AlbumTab.py
@@ -30,6 +30,7 @@ import webkit
 import os
 from mako.template import Template
 import xml.dom.minidom as dom
+import LastFM
 
 class AlbumTab (gobject.GObject):
 
@@ -138,8 +139,6 @@ class AlbumDataSource (gobject.GObject):
 
     def __init__ (self):
         gobject.GObject.__init__ (self)
-        self.api_key = '27151108bfce62e12c1f6341437e0e83'
-        self.url_prefix = 'http://ws.audioscrobbler.com/2.0/?method='
         self.albums = None
         self.error = None
         self.max_albums_fetched = 8
@@ -163,9 +162,9 @@ class AlbumDataSource (gobject.GObject):
     def fetch_album_list (self, artist):
         self.artist = artist
         self.error  = None
-        url = "%sartist.gettopalbums&artist=%s&api_key=%s" % (self.url_prefix,
+        url = "%sartist.gettopalbums&artist=%s&api_key=%s" % (LastFM.URL_PREFIX,
                                                               artist.replace(" ", "+"),
-                                                              self.api_key)
+                                                              LastFM.API_KEY)
         try:
             ld = rb.Loader ()
             ld.get_url (url, self.fetch_album_list_cb, artist) 
@@ -209,10 +208,10 @@ class AlbumDataSource (gobject.GObject):
         return self.albums
 
     def fetch_album_info (self, artist, album, index):
-        url = "%salbum.getinfo&artist=%s&album=%s&api_key=%s" % (self.url_prefix,
+        url = "%salbum.getinfo&artist=%s&album=%s&api_key=%s" % (LastFM.URL_PREFIX,
                                                                  artist.replace(" ", "+"),
                                                                  album.replace(" ", "+"),
-                                                                 self.api_key)
+                                                                 LastFM.API_KEY)
 
         ld = rb.Loader()
         ld.get_url (url, self.fetch_album_tracklist, album, index)
@@ -233,7 +232,7 @@ class AlbumDataSource (gobject.GObject):
         self.albums[index]['summary'] = self.extract(parsed.getElementsByTagName ('summary'), 0)
 
         url = "%splaylist.fetch&playlistURL=lastfm://playlist/album/%s&api_key=%s" % (
-                     self.url_prefix, self.albums[index]['id'], self.api_key)
+                     LastFM.URL_PREFIX, self.albums[index]['id'], LastFM.API_KEY)
 
         ld = rb.Loader()
         ld.get_url (url, self.assemble_info, album, index)
diff --git a/plugins/context/context/ArtistTab.py b/plugins/context/context/ArtistTab.py
index 47a1cd6..368206f 100644
--- a/plugins/context/context/ArtistTab.py
+++ b/plugins/context/context/ArtistTab.py
@@ -28,6 +28,7 @@ import rb, rhythmdb
 import gtk, gobject
 import re, os
 import xml.dom.minidom as dom
+import LastFM
 
 import webkit
 from mako.template import Template
@@ -148,8 +149,6 @@ class ArtistDataSource (gobject.GObject):
 
     def __init__ (self):
         gobject.GObject.__init__ (self)
-        self.api_key = '27151108bfce62e12c1f6341437e0e83'
-        self.url_prefix = 'http://ws.audioscrobbler.com/2.0/?method='
 
         self.current_artist = None
         self.artist = {
@@ -195,8 +194,8 @@ class ArtistDataSource (gobject.GObject):
 
     def fetch_top_tracks (self, artist):
         artist = artist.replace (" ", "+")
-        url = '%sartist.%s&artist=%s&api_key=%s' % (self.url_prefix,
-            self.artist['top_tracks']['function'], artist, self.api_key)
+        url = '%sartist.%s&artist=%s&api_key=%s' % (LastFM.URL_PREFIX,
+            self.artist['top_tracks']['function'], artist, LastFM.API_KEY)
         ld = rb.Loader()
         ld.get_url (url, self.fetch_artist_data_cb, self.artist['top_tracks'])
 
@@ -210,8 +209,8 @@ class ArtistDataSource (gobject.GObject):
         self.current_artist = artist
         artist = artist.replace(" ", "+")
         for key, value in self.artist.items():
-            url = '%sartist.%s&artist=%s&api_key=%s' % (self.url_prefix,
-                value['function'], artist, self.api_key)
+            url = '%sartist.%s&artist=%s&api_key=%s' % (LastFM.URL_PREFIX,
+                value['function'], artist, LastFM.API_KEY)
             ld = rb.Loader()
             ld.get_url (url, self.fetch_artist_data_cb, value)
 
diff --git a/plugins/context/context/LastFM.py b/plugins/context/context/LastFM.py
new file mode 100644
index 0000000..e8ea9e1
--- /dev/null
+++ b/plugins/context/context/LastFM.py
@@ -0,0 +1,47 @@
+# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
+#
+# Copyright (C) 2009 Jonathan Matthew
+#
+# 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.
+
+import gobject
+import gconf
+
+# utility things for dealing with last.fm
+
+URL_PREFIX = 'http://ws.audioscrobbler.com/2.0/?method='
+
+# this is probably john iacona's key
+API_KEY = '27151108bfce62e12c1f6341437e0e83'
+
+# this isn't particularly well worded; maybe that's a sign that it's too ugly
+# maybe we could provide a form to fill in?
+NO_ACCOUNT_ERROR = _("This information is only available to last.fm users. Please enter your account details in the last.fm plugin configuration.")
+
+USERNAME_GCONF_KEY = "/apps/rhythmbox/audioscrobbler/username"
+
+def user_has_account():
+        username = gconf.client_get_default().get_string(USERNAME_GCONF_KEY)
+        return (username is not None and username != "")
+
+



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