Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "join keyword" in MetadataSourcePlugin.get_artist() #4515

Merged
merged 5 commits into from
Jan 6, 2023

Conversation

JOJ0
Copy link
Member

@JOJ0 JOJ0 commented Oct 10, 2022

Description

  • Handle "join keyword" in MetadataSourcePlugin.get_artist() and make use of the new functionality in the Discogs source plugin.
  • Fixes Discogs plugin replacing Feat. or Ft. with a comma #4401 (Note that despite being discussed here, no version bump of python3-discogs-client is required since the data attribute being used, contains the required "join" field already.)

To Do

  • Documentation.
  • Changelog.
  • Tests.

JOJ0 added a commit to JOJ0/beets that referenced this pull request Oct 10, 2022
@JOJ0
Copy link
Member Author

JOJ0 commented Oct 10, 2022

Some example outputs while importing:

Old behaviour:

(beets)    ~/git/beets   fix_discogs_multi_artist ●  beet import ~/Sync/beets_test_music/Good\ Looking\ -\ Makoto\ Featuring\ MC\ Conrad

/home/jojo/Sync/beets_test_music/Good Looking - Makoto Featuring MC Conrad (2 items)
Finding tags for album "MC Conrad, Makoto - Golden Girl".
Candidates:
1. MC Conrad, Makoto - Golden Girl (67.4%) (id, source) (Discogs, Vinyl, 2005, UK, Good Looking Records, GLR066-12)
2. MC Conrad, Makoto - Golden Girl (56.4%) (id, tracks, source, ...) (Discogs, Vinyl, 2004, UK, Good Looking Records, GLR066W-12)
3. MC Conrad & Makoto - Golden Girl (54.2%) (id, tracks, media, ...) (12" Vinyl, 2005, GB, Good Looking Records, GLR066-12)
4. MC Lars - Hipster Girl (26.7%) (id, artist, album, ...) (2007, XW)
5. MC Conrad - Vocalist 01 (21.4%) (missing tracks, id, tracks, ...) (CD, 2000, GB, Good Looking Records, GLRV01)
6. MC Conrad - Logical Progression Level 4 (14.4%) (missing tracks, id, tracks, ...) (2xCD, 2001, GB, Good Looking Records, GLRCD004)
7. MC Conrad - Logical Progression Level 4 (11.3%) (missing tracks, id, tracks, ...) (3xCD, 2001, GB, Good Looking Records, GLRCD004X)
8. LTJ Bukem, MC Conrad - Progression Sessions 10 - Germany Live 2004 (9.3%) (missing tracks, id, tracks, ...) (Discogs, 2xCD, 2004, UK, Good Looking Records, GLRPS010X-2)
9. LTJ Bukem, MC Conrad - Progression Sessions 10 - Germany Live 2004 (6.9%) (missing tracks, id, tracks, ...) (Discogs, 3xCD, 2004, US, Benz Street, BZ 10017-2)
10. Various Artists - Makoto Feat. Deeizm MC: Non Stop Live Mix @ Tokyo (6.6%) (missing tracks, id, tracks, ...) (Discogs, 2xCD, 2006, Japan, Fenomeno Inc., FENO-0006)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? b
(beets)    ~/git/beets   fix_discogs_multi_artist ● 

New behaviour:

(beets)    ~/git/beets   fix_discogs_multi_artist ●  beet import ~/Sync/beets_test_music/Good\ Looking\ -\ Makoto\ Featuring\ MC\ Conrad

/home/jojo/Sync/beets_test_music/Good Looking - Makoto Featuring MC Conrad (2 items)
Finding tags for album "MC Conrad, Makoto - Golden Girl".
Candidates:
1. MC Conrad & Makoto - Golden Girl (74.3%) (id, artist) (Discogs, Vinyl, 2005, UK, Good Looking Records, GLR066-12)
2. MC Conrad And Makoto - Golden Girl (63.2%) (id, tracks, artist, ...) (Discogs, Vinyl, 2004, UK, Good Looking Records, GLR066W-12)
3. MC Conrad & Makoto - Golden Girl (54.2%) (id, tracks, media, ...) (12" Vinyl, 2005, GB, Good Looking Records, GLR066-12)
4. いきものがかり - GOLDEN GIRL (30.5%) (id, tracks, artist, ...) (CD, 2014, TW, Epic Records, 88875045072)
5. MC Conrad - Vocalist 01 (21.4%) (missing tracks, id, tracks, ...) (CD, 2000, GB, Good Looking Records, GLRV01)
6. MC Conrad - Logical Progression Level 4 (14.4%) (missing tracks, id, tracks, ...) (2xCD, 2001, GB, Good Looking Records, GLRCD004)
7. LTJ Bukem Featuring MC Conrad - Progression Sessions 10 - Germany Live 2004 (13.9%) (missing tracks, id, tracks, ...) (Discogs, 2xCD, 2004, UK, Good Looking Records, GLRPS010X-2)
8. Various Artists - Makoto Feat. Deeizm MC: Non Stop Live Mix @ Tokyo (12.0%) (missing tracks, id, tracks, ...) (Discogs, 2xCD, 2006, Japan, Fenomeno Inc., FENO-0006)
9. MC Conrad - Logical Progression Level 4 (11.3%) (missing tracks, id, tracks, ...) (3xCD, 2001, GB, Good Looking Records, GLRCD004X)
10. LTJ Bukem Featuring MC Conrad - Progression Sessions 10 - Germany Live 2004 (11.2%) (missing tracks, id, tracks, ...) (Discogs, 3xCD, 2004, US, Benz Street, BZ 10017-2)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? b
(beets)    ~/git/beets   fix_discogs_multi_artist ● 

Another example of new behaviour:

(beets)    ~/git/beets   fix_discogs_multi_artist ●  beet import ~/Sync/beets_test_music/DJ\ Marky\ -\ LK/

/home/jojo/Sync/beets_test_music/DJ Marky - LK (2 items)
Finding tags for album "DJ Marky & XRS, Stamina MC - LK Carolina Carol Bela".
Candidates:
1. DJ Marky & XRS Featuring Stamina MC - LK 'Carolina Carol Bela' (72.7%) (id, artist, tracks) (Discogs, Vinyl, 2002, UK, V Recordings, V035)
2. DJ Marky & XRS Featuring Stamina MC - LK 'Carolina Carol Bela' (64.2%) (id, tracks, artist) (Discogs, Vinyl, 2002, UK, V Recordings, V035)
3. DJ Marky & XRS feat. Stamina MC - LK 'Carolina Carol Bela' (54.9%) (id, tracks, media, ...) (12" Vinyl, 2002, GB, V Recordings, V035)
4. DJ Marky & XRS - LK 'Carolina Carol Bela' (53.5%) (id, tracks, artist, ...) (Discogs, CDr, 2002, UK, V Recordings, VCD035)
5. DJ Marky & XRS featuring Stamina MC - LK 'Carolina Carol Bela' (52.9%) (id, tracks, missing tracks, ...) (Discogs, CD, 2002, UK, V Recordings, V035CD)
6. DJ Marky & XRS - LK 'Carolina Carol Bela' (51.0%) (id, tracks, artist, ...) (12" Vinyl, 2002, GB, V Recordings, V 035)
7. DJ Marky & XRS feat. Stamina MC - LK 'Carolina Carol Bela' (49.0%) (id, tracks, media, ...) (CD, 2002, GB, V Recordings, V035CD)
8. DJ Marky & XRS - LK (remix) / Love Fantasy (35.0%) (id, tracks, album, ...) (12" Vinyl, 2002, GB, V Recordings, V 035R)
9. DJ Marky & XRS - Butterfly / Moments of Lust (remixes) (26.9%) (id, tracks, album, ...) (12" Vinyl, 2006, GB, Innerground Records, INN014)
10. Goldie - Drum&BassArena - The Classics (9.3%) (missing tracks, id, tracks, ...) (Discogs, 2xCD, 2005, UK, Ministry Of Sound, DABA01)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? b

@JOJ0
Copy link
Member Author

JOJ0 commented Oct 15, 2022

Ready for a final review.

JOJ0 added a commit to JOJ0/beets that referenced this pull request Oct 30, 2022
@zaptrem
Copy link

zaptrem commented Dec 26, 2022

Excited for this PR!

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! This is looking good overall—please see one suggestion within.

beets/plugins.py Outdated
Comment on lines 706 to 707
else:
artist = ', '.join(artist_names).replace(' ,', ',') or None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have this wrong, but would it work to move this "fallback" up into the loop? That is, the loop could look like this:

if join_key and artist.get(join_key, None):
    ...
else:
   name += ', '

I'm honestly not 100% sure where the replace call should go… it's a little mysterious to me why a , would appear in the string in the first place.

The reason I suggest this is that it could deal better with a situation where some artists have a join_key value and others don't (when there are more than 2 artists). In that case, you'd probably want to use a comma for pairs of artists that would otherwise not have another joiner.

Copy link
Member Author

@JOJ0 JOJ0 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the suggestion. Well, I think I managed to massively simplify this, which I think makes this method much more readable. It works well with Discogs as the metadata source, but some more testing reveals that it's problematic with the beatport4 plugin. Here we don't have a simple list to handle but a generator which does not answer well on my len() call:

  File "/home/jojo/git/beets-beatport4/beetsplug/beatport4.py", line 629, in _get_artist
    return MetadataSourcePlugin.get_artist(
  File "/home/jojo/git/beets/beets/plugins.py", line 697, in get_artist
    if idx < (len(artists) - 1):  # Skip joining on last.
TypeError: object of type 'generator' has no len()

I need to find another way of finding out whether I'm handling the last object of artists.... Suggestions welcome.

Copy link
Member Author

@JOJ0 JOJ0 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way to count the items in a way generators as well as dicts and lists or any other iterable should be allowed to be passed as the artists object.

Still this is better and more readable than my first version? What do you think?

And btw. I forgot to mention before: I removed the "mysterious" string replace method. It was mysterious to me as well why this was there in the original get_artist() code. I would like to leave it out. I don't see the point of keeping it. It probably would just lead to confusion again in the future :-) You agree?

@JOJ0 JOJ0 force-pushed the fix_discogs_multi_artist branch 3 times, most recently from fab1d77 to c62a6a6 Compare December 30, 2022 09:58
JOJ0 added 3 commits January 2, 2023 13:47
Add an optional argument to MetadataSourcePlugin.get_artist method that enables
making use of a field containing a keyword supposed to be used to combine
artists together into a single string like "Feat.", "And", "Vs." and so on.
@JOJ0 JOJ0 force-pushed the fix_discogs_multi_artist branch from c62a6a6 to 75209d3 Compare January 2, 2023 12:47
@JOJ0
Copy link
Member Author

JOJ0 commented Jan 2, 2023

Pulled in master because of the recent Sphinx issue. All checks green again and ready for a final review @sampsyo. Thanks!

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice; looking good!

I did a heap of git blame digging and traced the origin of that .replace call back to the discogs plugin here:
3eb6f8e

That still doesn't really explain why it was needed in the first place. I think we are safe to drop it and, if it crops back up because of some weird Discogs data formatting issues, we can reexamine on a case-by-case basis.

beets/plugins.py Outdated
for artist in artists:
artist_string = ""
# Count items (supports generators as well as lists, dicts, ...)
total = sum(1 for _ in artists)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A different option for dealing with generators (iteratables, in general) passed here would be to eagerly convert the artists to a list. That is, you could do:

artists_list = list(artists)

…and then simply use len(artists_list).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that. Thanks!

I just realilsed that my way of solving it didn't work anyway! Sorry for not testing better. It seems a generator is exhausted when it was counted with the sum(...) hack (it's been looped through to the end). I can't loop through it then because it's empty! Alright, sorry again, will fix soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's exactly the case!

beets/plugins.py Outdated
# Use a join keyword if requested and available.
if idx < (total - 1): # Skip joining on last.
if join_key and artist.get(join_key, None):
name += " " + artist[join_key] + " "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider f" {artist[join_key]} " for legibility.

@JOJ0 JOJ0 force-pushed the fix_discogs_multi_artist branch from 75209d3 to 5df959e Compare January 3, 2023 08:00
JOJ0 added 2 commits January 3, 2023 09:08
- Originally a list of "artists" was generated and joined together to a final
  string later.
- This simplifies by concatinating to a final string within the main loop.
- Also this commit gets rid of a mysterious replacement code (` ,' -> ',')
@JOJ0 JOJ0 force-pushed the fix_discogs_multi_artist branch from 5df959e to f1794e8 Compare January 3, 2023 08:08
@JOJ0
Copy link
Member Author

JOJ0 commented Jan 3, 2023

I put both suggested fixes into the original commits to keep commit-clutter minimal. I think we are done :-)

@sampsyo
Copy link
Member

sampsyo commented Jan 6, 2023

That does it! Nice work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discogs plugin replacing Feat. or Ft. with a comma
3 participants