#!/usr/bin/env python # -*- coding: utf-8 -*- # albumlist.py # # Copyright 2008 Piotr HusiatyƄski # # 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 from musicbrainz2 import webservice from musicbrainz2 import model def get_artist(name): "Returns single ArtistResult object" try: query = webservice.Query() qobj = webservice.ArtistFilter(name=name, limit=1) artist = query.getArtists(qobj) except webservice.WebServiceError, e: print e return None return artist[0] def get_artist_id(name): "Returns given artist ID string" artist = get_artist(name) if not artist: return None return artist.getArtist().id.split("/")[-1] def get_albums(name): "Returns list of given artist albums" artist_id = get_artist_id(name) if not artist_id: return None try: query = webservice.Query() qobj = webservice.ArtistIncludes( releases=(model.Release.TYPE_OFFICIAL, model.Release.TYPE_ALBUM)) artist = query.getArtistById(artist_id, qobj) except webservice.WebServiceError, e: print e return None album_list = [] for album in artist.releases: if not album.title in album_list: album_list.append(album.title) return album_list if __name__ == "__main__": # test import sys import pprint if len(sys.argv) < 2: print "Usage: python %s " % sys.argv[0] sys.exit(1) art_name = " ".join(sys.argv[1:]) print "Searching :", art_name pprint.pprint(get_albums(art_name))