[rhythmbox] artdisplay: add MusicBrainz cover art search (bug #410684)
- From: Jonathan Matthew <jmatthew src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rhythmbox] artdisplay: add MusicBrainz cover art search (bug #410684)
- Date: Sat, 29 Aug 2009 10:30:22 +0000 (UTC)
commit c492b9d99de6efd760d7f351dba88e26eb5ad8e4
Author: Jonathan Matthew <jonathan d14n org>
Date: Sat Aug 29 20:28:19 2009 +1000
artdisplay: add MusicBrainz cover art search (bug #410684)
This only works for songs that have musicbrainz album ID tags.
Perhaps it'll learn how to search later on.
plugins/artdisplay/artdisplay/CoverArtDatabase.py | 3 +-
plugins/artdisplay/artdisplay/Makefile.am | 1 +
.../artdisplay/MusicBrainzCoverArtSearch.py | 106 ++++++++++++++++++++
3 files changed, 109 insertions(+), 1 deletions(-)
---
diff --git a/plugins/artdisplay/artdisplay/CoverArtDatabase.py b/plugins/artdisplay/artdisplay/CoverArtDatabase.py
index 1c25ca0..219fe9c 100644
--- a/plugins/artdisplay/artdisplay/CoverArtDatabase.py
+++ b/plugins/artdisplay/artdisplay/CoverArtDatabase.py
@@ -33,6 +33,7 @@ import gobject
from PodcastCoverArtSearch import PodcastCoverArtSearch
from DiscogsCoverArtSearch import DiscogsCoverArtSearch
+from MusicBrainzCoverArtSearch import MusicBrainzCoverArtSearch
from EmbeddedCoverArtSearch import EmbeddedCoverArtSearch
from urllib import unquote
@@ -47,7 +48,7 @@ except:
from LocalCoverArtSearch import LocalCoverArtSearch
ART_SEARCHES_LOCAL = [LocalCoverArtSearch, EmbeddedCoverArtSearch]
-ART_SEARCHES_REMOTE = [PodcastCoverArtSearch, DiscogsCoverArtSearch]
+ART_SEARCHES_REMOTE = [PodcastCoverArtSearch, MusicBrainzCoverArtSearch, DiscogsCoverArtSearch]
OLD_ART_FOLDER = '~/.gnome2/rhythmbox/covers'
ART_FOLDER = os.path.join(rb.user_cache_dir(), 'covers')
diff --git a/plugins/artdisplay/artdisplay/Makefile.am b/plugins/artdisplay/artdisplay/Makefile.am
index a318ad2..c3b3c7f 100644
--- a/plugins/artdisplay/artdisplay/Makefile.am
+++ b/plugins/artdisplay/artdisplay/Makefile.am
@@ -8,6 +8,7 @@ plugin_PYTHON = \
LocalCoverArtSearchGIO.py \
CoverArtDatabase.py \
DiscogsCoverArtSearch.py \
+ MusicBrainzCoverArtSearch.py \
__init__.py
# the amazon cover art search no longer works
diff --git a/plugins/artdisplay/artdisplay/MusicBrainzCoverArtSearch.py b/plugins/artdisplay/artdisplay/MusicBrainzCoverArtSearch.py
new file mode 100644
index 0000000..4583ee0
--- /dev/null
+++ b/plugins/artdisplay/artdisplay/MusicBrainzCoverArtSearch.py
@@ -0,0 +1,106 @@
+# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
+#
+# Copyright (C) 2009 Jonathan Matthew <jonathan d14n org>
+#
+# 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 urllib
+import xml.dom.minidom as dom
+
+import rb
+import rhythmdb
+
+# musicbrainz URLs
+MUSICBRAINZ_RELEASE_URL = "http://musicbrainz.org/ws/1/release/%s?type=xml"
+MUSICBRAINZ_RELEASE_PREFIX = "http://musicbrainz.org/release/"
+MUSICBRAINZ_RELEASE_SUFFIX = ".html"
+
+# Amazon URL bits
+AMAZON_IMAGE_URL = "http://images.amazon.com/images/P/%s.01.LZZZZZZZ.jpg"
+
+class MusicBrainzCoverArtSearch (object):
+
+ def __init__(self):
+ pass
+
+ def __get_release_cb (self, data):
+ if data is None:
+ print "musicbrainz release request returned nothing"
+ self.callback(self, self.entry, [], *self.callback_args)
+ return;
+
+ try:
+ parsed = dom.parseString(data)
+
+ # just look for an ASIN tag
+ asin_tags = parsed.getElementsByTagName('asin')
+ if len(asin_tags) > 0:
+ asin = asin_tags[0].firstChild.data
+
+ print "got ASIN %s" % asin
+ image_url = AMAZON_IMAGE_URL % asin
+
+ self.callback(self, self.entry, [image_url], *self.callback_args)
+ else:
+ print "no ASIN for this release"
+ except Exception, e:
+ print "exception parsing musicbrainz response: %s" % e
+ self.callback(self, self.entry, [], *self.callback_args)
+
+ def search (self, db, entry, is_playing, callback, *args):
+
+ self.callback = callback
+ self.callback_args = args
+ self.entry = entry
+
+ # if we've got an album ID, we can get the album info directly
+ album_id = db.entry_get(entry, rhythmdb.PROP_MUSICBRAINZ_ALBUMID)
+ if album_id != "":
+ # these sometimes look like full URLs, sometimes not
+ if album_id.startswith(MUSICBRAINZ_RELEASE_PREFIX):
+ album_id = album_id[len(MUSICBRAINZ_RELEASE_PREFIX):]
+
+ if album_id.endswith(MUSICBRAINZ_RELEASE_SUFFIX):
+ album_id = album_id[:-len(MUSICBRAINZ_RELEASE_SUFFIX)]
+
+ print "stripped release ID: %s" % album_id
+
+ url = MUSICBRAINZ_RELEASE_URL % (album_id)
+ loader = rb.Loader()
+ loader.get_url(url, self.__get_release_cb)
+ return
+
+ # otherwise, maybe we can search for the album..
+
+ # nothing to do
+ callback (self, entry, [], *args)
+
+ def search_next (self):
+ return False
+
+ def get_result_pixbuf (self, search_results):
+ return None
+
+ def get_best_match_urls (self, search_results):
+ return search_results
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]