This commit fixes headphones issue 576.

Changed getArtist to use the musicbrainzngs library, identical output.
(old musicbrainz 2 library is deprecated and broken)
This commit is contained in:
Patrick Speiser
2012-05-27 11:44:31 +02:00
parent 214d46493c
commit c8cc29b1ab
+38 -33
View File
@@ -160,11 +160,8 @@ def findRelease(name, limit=1):
def getArtist(artistid, extrasonly=False): def getArtist(artistid, extrasonly=False):
with mb_lock: with mb_lock:
artist_dict = {} artist_dict = {}
#Get all official release groups
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), releaseGroups=True)
artist = None artist = None
attempt = 0 attempt = 0
@@ -173,36 +170,51 @@ def getArtist(artistid, extrasonly=False):
while attempt < 5: while attempt < 5:
try: try:
artist = q.getArtistById(artistid, inc) artist = musicbrainzngs.get_artist_by_id(artistid,includes=["releases","release-groups"],release_status="official",release_type="album")['artist']
break break
except WebServiceError, e: except WebServiceError, e:
logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e))) logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
attempt += 1 attempt += 1
time.sleep(5) time.sleep(5)
except Exception,e:
pass
if not artist: if not artist:
return False return False
time.sleep(sleepytime) time.sleep(sleepytime)
artist_dict['artist_name'] = artist.name if 'disambiguation' in artist:
artist_dict['artist_sortname'] = artist.sortName uniquename = unicode(artist['sort-name'] + " (" + artist['disambiguation'] + ")")
artist_dict['artist_uniquename'] = artist.getUniqueName() else:
artist_dict['artist_type'] = u.extractFragment(artist.type) uniquename = unicode(artist['sort-name'])
artist_dict['artist_begindate'] = artist.beginDate artist_dict['artist_name'] = unicode(artist['name'])
artist_dict['artist_enddate'] = artist.endDate artist_dict['artist_sortname'] = unicode(artist['sort-name'])
artist_dict['artist_uniquename'] = uniquename
artist_dict['artist_type'] = unicode(artist['type'])
artist_dict['artist_begindate'] = None
artist_dict['artist_enddate'] = None
if 'life-span' in artist:
if 'begin' in artist['life-span']:
artist_dict['artist_begindate'] = unicode(artist['life-span']['begin'])
if 'end' in artist['life-span']:
artist_dict['artist_enddate'] = unicode(artist['life-span']['end'])
releasegroups = [] releasegroups = []
if not extrasonly: if not extrasonly:
for rg in artist['release-group-list']:
for rg in artist.getReleaseGroups(): if rg['type'] != 'Album': #only add releases without a secondary type
continue
releasegroups.append({ releasegroups.append({
'title': rg.title, 'title': unicode(rg['title']),
'id': u.extractUuid(rg.id), 'id': unicode(rg['id']),
'url': rg.id, 'url': u"http://musicbrainz.org/release-group/" + rg['id'],
'type': u.getReleaseTypeName(rg.type) 'type': unicode(rg['type'])
}) })
# See if we need to grab extras # See if we need to grab extras
@@ -214,33 +226,26 @@ def getArtist(artistid, extrasonly=False):
includeExtras = False includeExtras = False
if includeExtras or headphones.INCLUDE_EXTRAS: if includeExtras or headphones.INCLUDE_EXTRAS:
includes = [m.Release.TYPE_COMPILATION, m.Release.TYPE_REMIX, m.Release.TYPE_SINGLE, m.Release.TYPE_LIVE, m.Release.TYPE_EP, m.Release.TYPE_SOUNDTRACK] includes = ["single", "ep", "compilation", "soundtrack", "live", "remix"]
for include in includes: for include in includes:
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, include), releaseGroups=True)
artist = None artist = None
attempt = 0 attempt = 0
while attempt < 5:#this may be redundant with musicbrainzngs, it seems to retry and wait by itself, i will leave it in for rembo to review
while attempt < 5:
try: try:
artist = q.getArtistById(artistid, inc) artist = musicbrainzngs.get_artist_by_id(artistid,includes=["releases","release-groups"],release_status=['official'],release_type=include)['artist']
break break
except WebServiceError, e: except WebServiceError, e:#update exceptions
logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e))) logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
attempt += 1 attempt += 1
time.sleep(5) time.sleep(5)
if not artist: if not artist:
continue continue
for rg in artist['release-group-list']:
for rg in artist.getReleaseGroups():
releasegroups.append({ releasegroups.append({
'title': rg.title, 'title': unicode(rg['title']),
'id': u.extractUuid(rg.id), 'id': unicode(rg['id']),
'url': rg.id, 'url': u"http://musicbrainz.org/release-group/" + rg['id'],
'type': u.getReleaseTypeName(rg.type) 'type': unicode(rg['type'])
}) })
artist_dict['releasegroups'] = releasegroups artist_dict['releasegroups'] = releasegroups