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

Remediate / refactor wikidata plugin #372

Open
wants to merge 4 commits into
base: 2.0
Choose a base branch
from

Conversation

Sophist-UK
Copy link
Contributor

  1. Reduce log verbosity, particularly INFO but also DEBUG, and provide additional information.

  2. Refactor code to reduce nesting, primarily using early returns, but also simplifying and generally cleaning.

  3. Fix a few small bugs whose symptoms would probably not be noticed.

I have tested this version, however I don't have not yet found any of my music that has Wikidata genres.

1. Reduce log verbosity, particularly INFO but also DEBUG, and provide additional information.

2. Refactor code to reduce nesting, primarily using early returns, but also simplifying and generally cleaning.

3. Fix a few small bugs whose symptoms would probably not be noticed.

I have tested this version, however I don't have not yet found any of my music that has Wikidata genres.
@Sophist-UK Sophist-UK marked this pull request as draft February 6, 2024 17:35
It wasn't working due to a refactor screwup by me.

But it is now working and a number of other less major bugs have also been dealt with e.g. album not loading after wikidata network errors, duplicate lookups etc.
@Sophist-UK
Copy link
Contributor Author

The MB data I used to test this was release:0cc705d1-ea84-4a28-b6f5-812e295129f0.

@Sophist-UK Sophist-UK marked this pull request as ready for review February 6, 2024 21:46
Because we should try to get all genre plugins to create hidden variables named `~genre_` + plugin-name.
@Sophist-UK
Copy link
Contributor Author

Ok - this is now working perfectly as far as I can tell. Review may be difficult as it is both a refactor and contains various bug fixes, most notably when wikidata network errors occur, the album will never resolve.

Additional functionality: Avoid duplicate albumartist and artist lookups

@Sophist-UK
Copy link
Contributor Author

As an aside, I am unsure how it has a codacy issue of a method being over complex when the refactoring reduced the complexity of the code substantially. However, if needed I can refactor it a little more to reduce the complexity further.

Copy link
Member

@phw phw left a comment

Choose a reason for hiding this comment

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

Thanks for this detailed refactoring. I'm finally catching up on reviewing plugins. Not much to say really about this, looks good and simplifies the code. Only some small comments.

As an aside, I am unsure how it has a codacy issue of a method being over complex when the refactoring reduced the complexity of the code substantially. However, if needed I can refactor it a little more to reduce the complexity further.

Yes, codacy is just being silly I think. Let's ignore it.

found = True
wikidata_url = relation.target[0].text
self.process_wikidata(Wikidata.ARTIST, wikidata_url, item_id)
log.info('WIKIDATA: wikidata url found for ARTIST: %s', wikidata_url)
Copy link
Member

Choose a reason for hiding this comment

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

This is really minor, but the other code paths have this log message before the self.process_wikidata call. Would be nice to have it consistent.

found = True
wikidata_url = relation.target[0].text
log.info('WIKIDATA: wikidata url found for WORK: %s', wikidata_url)
self.process_wikidata(Wikidata.WORK, wikidata_url, item_id)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about moving the code to find the wikidata url into a helper function? Something like:

def get_wikidata_url(node):
    if 'relation_list' in node.children:
        for relation in response.metadata[0].work[0].relation_list[0].relation:
            if relation.type == 'wikidata' and 'target' in relation.children:
                return relation.target[0].text
    return None

The use it like:

wikidata_url = response.metadata[0].work[0]
if wikidata_url:
    found = True
    log.info('WIKIDATA: wikidata url found for WORK: %s', wikidata_url)
    self.process_wikidata(Wikidata.WORK, wikidata_url, item_id)

Since genres can be gathered from multiple sources and the genre tag may be overwritten,
we also set a hidden variable _genre_wikidata to the same values for use in scripts.
'''
PLUGIN_VERSION = '1.4.6'
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest setting this to 1.5, after all this PR also adds a small feature by providing the ~wikidata_genre variable.

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.

2 participants