and put to use in Spotify plugin.
- Make _get_id() a staticmethod usable from outside a metadata source plugin.
- id_regex now has to be passed as an argument instead of assuming it is
accessible via an instance variable (self.id_regex).
- In the Spotify plugin, import spotify_id_regex from util.id_extractors
- 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 (` ,' -> ',')
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.
In
766c8b190b from [1]
a slight hack was introduced that allowed to add new arguments to
plugin events without breaking legacy plugins that did not feature
those arguments in the signature of their handler functions.
When improving logging management for plugins in
327b62b610 from [2]
this hack was removed, to be restored with
7f34c101d7 from [3]
Now in addition to inspecting the function signature, an assumption is
made about the string message of the TypeError that occurs for legacy
handler functions (namely, that it start with func.__name__).
In Python 3.10, the TypeError uses func.__qualname__ [4], however, due
to the patch [5]. Thus, checking whether the TypeError is due to an
outdated function signature or something internal to the handler fais.
As a fix, instead of using __name__ or __qualname__ depending on Python
version, let's just revert to the old hack from [1], I'm not seeing a
significant advantage in [3]. The latter might be a bit faster since it
doesn't construct a new dict for each call, but only for legacy calls in
the excption handler. I doubt that really matters, and if it does, we
should try to think of a better fix than inspecting error messages with
no guarantees about their content in such a central place in the code.
[1] https://github.com/beetbox/beets/pull/652
[2] https://github.com/beetbox/beets/pull/1320
[3] https://github.com/beetbox/beets/pull/1359
[4] https://docs.python.org/3.10/glossary.html#term-qualified-name
[5] https://bugs.python.org/issue40679
This function is called from library.Item._getters(), making it a hot
path when exporting data. We cache plugin instances but previously we
reran `import` for each module on each call. We now return the cached
values providing a speed boost for `beet export`.
This has a small effect on `beet ls` speed: for me it went 11.00s ->
10.40.
It had a significant effect on `beet export` speed when combined with
https://github.com/beetbox/beets/pull/3762/.
Before:
$ time /home/sam/.local/bin/beet 'export' '--library' '--format' 'jsonlines' '--include-keys' 'artist,title,path,mb_artistid,mb_trackid' 'artist+ title+' > /dev/null
Executed in 25.13 secs
After:
$ time /home/sam/.local/bin/beet 'export' '--library' '--format' 'jsonlines' '--include-keys' 'artist,title,path,mb_artistid,mb_trackid' 'artist+ title+' > /dev/null
Executed in 10.49 secs