diff --git a/beets/plugins.py b/beets/plugins.py index b55e1f2911..d137078c92 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -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] @@ -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: