Skip to content

Commit

Permalink
Merge pull request metabrainz#457 from trolley/master
Browse files Browse the repository at this point in the history
Fall back to track artist tags for genre on comps.
  • Loading branch information
zas committed Feb 15, 2016
2 parents d1d4d4d + 780bb2b commit cf375a8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
11 changes: 11 additions & 0 deletions picard/mbxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ def recording_to_metadata(node, track):
m['~recordingcomment'] = nodes[0].text
elif name == 'artist_credit':
artist_credit_to_metadata(nodes[0], m)
if 'name_credit' in nodes[0].children:
for name_credit in nodes[0].name_credit:
if 'artist' in name_credit.children:
for artist in name_credit.artist:
trackartist = track.append_track_artist(artist.id)
if 'tag_list' in artist.children:
add_folksonomy_tags(artist.tag_list[0],
trackartist)
if 'user_tag_list' in artist.children:
add_user_folksonomy_tags(artist.user_tag_list[0],
trackartist)
elif name == 'relation_list':
_relations_to_metadata(nodes, m)
elif name == 'tag_list':
Expand Down
26 changes: 22 additions & 4 deletions picard/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
}


class TrackArtist(DataObject):
def __init__(self, id):
DataObject.__init__(self, id)


class Track(DataObject, Item):

def __init__(self, id, album=None):
Expand All @@ -45,6 +50,7 @@ def __init__(self, id, album=None):
self.linked_files = []
self.num_linked_files = 0
self.metadata = Metadata()
self._track_artists = []

def __repr__(self):
return '<Track %s %r>' % (self.id, self.metadata["title"])
Expand Down Expand Up @@ -118,10 +124,10 @@ def is_video(self):

def is_pregap(self):
return self.metadata['~pregap'] == '1'

def is_data(self):
return self.metadata['~datatrack'] == '1'

def is_silence(self):
return self.metadata['~silence'] == '1'

Expand All @@ -136,6 +142,13 @@ def ignored_for_completeness(self):
return True
return False

def append_track_artist(self, id):
"""Append artist id to the list of track artists
and return an TrackArtist instance"""
track_artist = TrackArtist(id)
self._track_artists.append(track_artist)
return track_artist

def _customize_metadata(self):
tm = self.metadata

Expand Down Expand Up @@ -163,8 +176,13 @@ def _convert_folksonomy_tags_to_genre(self):
if self.album.release_group:
self.merge_folksonomy_tags(tags, self.album.release_group.folksonomy_tags)
if not tags and config.setting['artists_tags']:
for artist in self.album.get_album_artists():
self.merge_folksonomy_tags(tags, artist.folksonomy_tags)
# For compilations use each track's artists to look up tags
if self.metadata['musicbrainz_albumartistid'] == VARIOUS_ARTISTS_ID:
for artist in self._track_artists:
self.merge_folksonomy_tags(tags, artist.folksonomy_tags)
else:
for artist in self.album.get_album_artists():
self.merge_folksonomy_tags(tags, artist.folksonomy_tags)
# Ignore tags with zero or lower score
tags = dict((name, count) for name, count in tags.items() if count > 0)
if not tags:
Expand Down

0 comments on commit cf375a8

Please sign in to comment.