Skip to content

Commit

Permalink
Support generators in MetadataSourcePlugin.get_artist method
Browse files Browse the repository at this point in the history
  • Loading branch information
JOJ0 committed Dec 30, 2022
1 parent bdfd992 commit c62a6a6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion beets/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ def get_artist(artists, id_key='id', name_key='name', join_key=None):
"""
artist_id = None
artist_string = ""
# Count items (supports generators as well as lists, dicts, ...)
total = sum(1 for _ in artists)
for idx, artist in enumerate(artists):
if not artist_id:
artist_id = artist[id_key]
Expand All @@ -694,7 +696,7 @@ def get_artist(artists, id_key='id', name_key='name', join_key=None):
# Move articles to the front.
name = re.sub(r'^(.*?), (a|an|the)$', r'\2 \1', name, flags=re.I)
# Use a join keyword if requested and available.
if idx < (len(artists) - 1): # Skip joining on last.
if idx < (total - 1): # Skip joining on last.
if join_key and artist.get(join_key, None):
name += " " + artist[join_key] + " "
else:
Expand Down

0 comments on commit c62a6a6

Please sign in to comment.