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

Fix sort multivalue tags plugin #272

Closed

Conversation

Sophist-UK
Copy link
Contributor

Exclude certain multi-value tags from sorting because the order is important.


# Exclude the following tags because the sort order is related to other tags or has a meaning like primary artist
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the same true for at least artists, albumartists, work, musicbrainz_workid, label, catalognumber, country, date and releasetype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - this list is not correct. artist, artistsort, albumartist, albumartistsort are strings and not multi-value. It should have artists, ~albumartists, ~artists_sort, ~albumartists_sort in instead. And I think I agree about label and catalognumber (which match each other in sequence). releasetype is already in the list.

When I think (hard) about it, I can see that a medley could have multiple works in the sequence they are played, and that country and date are probably also in lock-step. So they should be added too.

@mineo
Copy link
Member

mineo commented Apr 4, 2014

Make a class to avoid polluting the global namespace with the exclude_tags variable.

I don't think this makes sense, you're trading one additional global variable at the module level (which is something we already have in plenty of picards modules) against a class with one static method and a class-level attribute.

@Sophist-UK
Copy link
Contributor Author

Ok. Just seemed to make more sense for plugins to have a consistent style and contain everything in a class But I can switch back easily enough.

# Exclude the following tags because the sort order is related to other tags or has a meaning like primary artist
_sort_multivalue_tags_exclude = [
'artists', '~artists_sort', 'musicbrainz_artistid',
'albumartist', '~albumartists_sort', 'musicbrainz_albumartistid',
Copy link
Member

Choose a reason for hiding this comment

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

After #268 albumartists should be added here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its a typo - albumartist should say albumartists.

@Sophist-UK
Copy link
Contributor Author

Diff comments addressed.

'releasetype',
]

def sort_multivalue_tags(album, metadata, *args):
for tag in metadata.keys():
Copy link
Member

Choose a reason for hiding this comment

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

You're getting the value a few lines later anyway, so you can just use metadata.iteritems here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only once we have killed off the id3metadata class. Until then we cannot use __getitem__ (which I suspect iteritems uses internally) because it calls get which is overloaded. Which is why your PR to kill ID3metadata is a good idea!!!

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, rawitems was the one that acts like dict.items or dict.iteritems.

@Sophist-UK
Copy link
Contributor Author

Should hopefully be ready to merge now.

Exclude certain multi-value tags from sorting because the order is
important.

Get raw list because id3metadata sub-class overrides the getall method.

Make a class to avoid polluting the global namespace with the
exclude_tags variable.
and move back to non-class form.
@mineo
Copy link
Member

mineo commented Jun 1, 2014

Does this plugin actually work as it is? If I enable it, it just splits tags like the track title etc. that are not multi-valued.

@Sophist-UK
Copy link
Contributor Author

It was working on my PC when I submitted it - though I haven't tested it against the latest daily build.

The code is pretty simple - I can't see how it can split a tag. When I get the chance I will retest it. It should e.g. sort Performer tags.

@mineo
Copy link
Member

mineo commented Jun 2, 2014

The problem seems to be that Metadata.iteritems yield key-value pairs but the value is not always an instance of list, so your length check (and the modifications afterwards) operate on a string.

@Sophist-UK
Copy link
Contributor Author

hmm - yes - metadata has an override for the standard dict iteritems which yields multi-value variables one-by-one. However, I am unsure why it does this - the only place I can find metadata.iteritems used elsewhere is at line c. 144 in file.py and this looks like it is expecting iteritems to yield a single multivalue not several single-values. In metadatabox.py c. line 381 we explicitly use the original dict.iteritems.

I can easily change the line to read dict.iteritems(metadata) but I will wait for your feedback on thee above analysis.

@mineo
Copy link
Member

mineo commented Oct 25, 2014

Please use dict.iteritems (or .rawitems of metadata).

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