def findArtist(name, limit=1): with mb_lock: artistlist = [] artistResults = None chars = set('!?*') if any((c in chars) for c in name): name = '"' + name + '"' try: artistResults = musicbrainzngs.search_artists( query='artist:' + name, limit=limit)['artist-list'] except WebServiceError, e: logger.warn('Attempt to query MusicBrainz for %s failed (%s)' % (name, str(e))) time.sleep(5) if not artistResults: return False for result in artistResults: if 'disambiguation' in result: uniquename = unicode(result['sort-name'] + " (" + result['disambiguation'] + ")") else: uniquename = unicode(result['sort-name']) if result['name'] != uniquename and limit == 1: logger.info( 'Found an artist with a disambiguation: %s - doing an album based search' % name) artistdict = findArtistbyAlbum(name) if not artistdict: logger.info( 'Cannot determine the best match from an artist/album search. Using top match instead' ) artistlist.append({ # Just need the artist id if the limit is 1 # 'name': unicode(result['sort-name']), # 'uniquename': uniquename, 'id': unicode(result['id']), # 'url': unicode("http://musicbrainz.org/artist/" + result['id']),#probably needs to be changed # 'score': int(result['ext:score']) }) else: artistlist.append(artistdict) else: artistlist.append({ 'name': unicode(result['sort-name']), 'uniquename': uniquename, 'id': unicode(result['id']), 'url': unicode("http://musicbrainz.org/artist/" + result['id']), #probably needs to be changed 'score': int(result['ext:score']) }) return artistlist
def findArtist(name, limit=1): with mb_lock: artistlist = [] artistResults = None chars = set('!?*') if any((c in chars) for c in name): name = '"'+name+'"' q, sleepytime = startmb(forcemb=True) try: artistResults = musicbrainzngs.search_artists(query=name,limit=limit)['artist-list'] except WebServiceError, e: logger.warn('Attempt to query MusicBrainz for %s failed (%s)' % (name, str(e))) time.sleep(5) time.sleep(sleepytime) if not artistResults: return False for result in artistResults: if 'disambiguation' in result: uniquename = unicode(result['sort-name'] + " (" + result['disambiguation'] + ")") else: uniquename = unicode(result['sort-name']) if result['name'] != uniquename and limit == 1: logger.info('Found an artist with a disambiguation: %s - doing an album based search' % name) artistdict = findArtistbyAlbum(name) if not artistdict: logger.info('Cannot determine the best match from an artist/album search. Using top match instead') artistlist.append({ # Just need the artist id if the limit is 1 # 'name': unicode(result['sort-name']), # 'uniquename': uniquename, 'id': unicode(result['id']), # 'url': unicode("http://musicbrainz.org/artist/" + result['id']),#probably needs to be changed # 'score': int(result['ext:score']) }) else: artistlist.append(artistdict) else: artistlist.append({ 'name': unicode(result['sort-name']), 'uniquename': uniquename, 'id': unicode(result['id']), 'url': unicode("http://musicbrainz.org/artist/" + result['id']),#probably needs to be changed 'score': int(result['ext:score']) }) return artistlist
def findArtist(name, limit=1): with mb_lock: artistlist = [] artistResults = None chars = set("!?*") if any((c in chars) for c in name): name = '"' + name + '"' try: artistResults = musicbrainzngs.search_artists(query="artist:" + name, limit=limit)["artist-list"] except WebServiceError, e: logger.warn("Attempt to query MusicBrainz for %s failed (%s)" % (name, str(e))) time.sleep(5) if not artistResults: return False for result in artistResults: if "disambiguation" in result: uniquename = unicode(result["sort-name"] + " (" + result["disambiguation"] + ")") else: uniquename = unicode(result["sort-name"]) if result["name"] != uniquename and limit == 1: logger.info("Found an artist with a disambiguation: %s - doing an album based search" % name) artistdict = findArtistbyAlbum(name) if not artistdict: logger.info("Cannot determine the best match from an artist/album search. Using top match instead") artistlist.append( { # Just need the artist id if the limit is 1 # 'name': unicode(result['sort-name']), # 'uniquename': uniquename, "id": unicode(result["id"]), # 'url': unicode("http://musicbrainz.org/artist/" + result['id']),#probably needs to be changed # 'score': int(result['ext:score']) } ) else: artistlist.append(artistdict) else: artistlist.append( { "name": unicode(result["sort-name"]), "uniquename": uniquename, "id": unicode(result["id"]), "url": unicode("http://musicbrainz.org/artist/" + result["id"]), # probably needs to be changed "score": int(result["ext:score"]), } ) return artistlist