Skip to content

Commit

Permalink
Remove possible duplicate in workids and composers
Browse files Browse the repository at this point in the history
Since mutagen tag doesn't support set, `composers` will be
declared as set to avoid duplicate then forced to `list`.

Signed-off-by: ABCbum <[email protected]>
  • Loading branch information
ABCbum committed Jan 10, 2020
1 parent bd883c8 commit a4497bc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions whipper/common/mbngs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ def _getWorks(recording):

def _getWorksId(works):
"""Get work ids from "performance of" works"""
ids = []
ids = set() # using a set to prevent duplicates
for work in works:
ids.append(work['id'])
return ids
ids.add(work['id'])
# convert back to list since mutagen doesn't support set
return list(ids)


def _getComposers(works):
Expand All @@ -179,7 +180,7 @@ def _getComposers(works):
:rtype: list
"""
composers = []
composers = set() # using a set to prevent duplicates
valid_artist_rel_type = [
'd59d99ea-23d4-4a80-b066-edca32ee158f', # "Composer"
]
Expand All @@ -188,8 +189,9 @@ def _getComposers(works):
for artist_relation in work['artist-relation-list']:
if artist_relation['type-id'] in valid_artist_rel_type:
composerName = artist_relation['artist']['name']
composers.append(composerName)
return composers
composers.add(composerName)
# convert back to list since mutagen doesn't support set
return list(composers)


def _getPerformers(recording):
Expand All @@ -208,8 +210,7 @@ def _getPerformers(recording):
'guest', 'additional', 'solo'
]
if 'artist-relation-list' in recording:
artist_relation_list = recording['artist-relation-list']
for artist_relation in artist_relation_list:
for artist_relation in recording['artist-relation-list']:
if artist_relation['type-id'] in valid_type_id:
type = artist_relation['type']
name = artist_relation['artist']['name']
Expand All @@ -226,13 +227,13 @@ def _getPerformers(recording):
prefix += attribute + ' '
else:
others.append(attribute)
# if "guest performer: artist", `suffix` is `type` by default
# else "guest solo piano, organ : artist"
# if "guest performer: artist", `suffix` is `type` by
# default else "guest solo piano, organ : artist"
suffix = type if len(others) == 0 else ', '.join(others)
type = prefix + suffix

performer = "%s: %s" % (type, name)
performers.append(performer)
performer = "%s: %s" % (type, name)
performers.append(performer)
return performers


Expand Down

0 comments on commit a4497bc

Please sign in to comment.