Commit graph

205 commits

Author SHA1 Message Date
Karl Besser
3942753a63 Delete unnecessary comma in feat detection regex 2024-09-23 12:26:51 -04:00
Karl Besser
8c60d2b960 Add parentheses as delimiters for feat. detection
When checking whether a title or artist contains a feature, it now also
detects them when they are in parentheses or brackets, i.e., "Song Name
(feat. XYZ)" will return true.
2024-09-22 18:21:08 -04:00
Šarūnas Nejus
f36bc497c8
Fix lint issues
- Fix imports
- Fix pytest issues
- Do not assign lambda as variable
- Use isinstance instead of type to check type
- Rename ambiguously named variables
- Name custom errors with Error suffix
2024-09-21 11:59:18 +01:00
Šarūnas Nejus
85a17ee503
Reformat the codebase 2024-09-21 11:57:48 +01:00
Šarūnas Nejus
249d49942e
Make a change to test 2024-06-14 16:04:15 +01:00
Maxr1998
e64ee0b0cd
beetsplug: Error out on conflicts in template functions
Raises an exception if multiple plugins provide template functions for the same field.

Closes #5002, supersedes #5003.
2023-12-16 16:38:32 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
J0J0 Todos
284180ec75 Refactor MetadataSourcePlugin._get_id()
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
2023-03-08 18:12:31 +01:00
J0J0 Todos
f1794e8709 Support generators in MetadataSourcePlugin.get_artist method 2023-01-03 09:08:31 +01:00
J0J0 Todos
1b0f49fc3b Simplify MetadataSourcePlugin.get_artist method
- 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 (` ,' -> ',')
2023-01-03 09:08:21 +01:00
J0J0 Todos
fddeecb29f Add join_key arg to source plugin get_artist method
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.
2023-01-02 13:47:31 +01:00
Andrew Rogl
910354a6c6 fix unused import and flake8 2021-08-25 19:07:55 +10:00
Andrew Rogl
6d1316f463 pyupgrade beets dir 2021-08-25 16:05:28 +10:00
Adrian Sampson
07742a5f39
Remove unnecessary temporaries 2021-08-21 13:29:25 -04:00
Adrian Sampson
75c41c0546
Remove most six.PY2 checks 2021-08-19 16:45:11 -04:00
wisp3rwind
64dc3ec2a2 plugins: Python 3.10 compatibility
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
2021-03-23 09:51:44 +01:00
Sam Thursfield
3fec6d347a Use caching in plugins.find_plugins()
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
2020-12-15 14:16:09 +01:00
x1ppy
3c08911794 Add missing extra_tags parameter to MetadataSourcePlugin (#3540) 2020-04-07 12:12:50 -04:00
x1ppy
19d6dfc8f3 Support extra tags for MusicBrainz queries 2020-03-20 14:13:40 -04:00
Rahul Ahuja
11e00c549b Exclude empty albums from candidates 2019-10-06 00:07:23 -07:00
Rahul Ahuja
52961d71f5
Add defaults to docstring 2019-10-05 16:30:24 -07:00
Rahul Ahuja
19f045290e Fix docstring wording 2019-10-05 15:55:45 -07:00
Rahul Ahuja
a07972d02a Fix docstring wording 2019-10-05 15:53:41 -07:00
Rahul Ahuja
e2c63d4901 Improve docstring wording 2019-10-05 15:25:48 -07:00
Rahul Ahuja
ce90b2aae5 Improve documentation 2019-10-05 15:07:20 -07:00
Rahul Ahuja
14b8f30ead Appease flake8 2019-10-03 19:13:40 -07:00
Rahul Ahuja
a1885a571b Add documentation, fix circular import 2019-10-03 19:03:04 -07:00
Rahul Ahuja
f14137fcc2 Add BPSyncPlugin 2019-10-03 18:04:12 -07:00
Rahul Ahuja
ed80e915fe Move get_distance --> beets.plugins 2019-09-11 00:07:43 -07:00
Rahul Ahuja
876c0f733f Appease flake8 2019-09-10 23:52:35 -07:00
Rahul Ahuja
2b0cf3e002 Try absolute import 2019-09-10 22:39:06 -07:00
Rahul Ahuja
84b13475e0 Move get_distance to beets.autotag 2019-09-09 19:13:24 -07:00
Rahul Ahuja
1de0af669d Try absolute import 2019-09-09 18:45:12 -07:00
Rahul Ahuja
c531b1628e Avoid circular import 2019-09-09 18:28:20 -07:00
Rahul Ahuja
732e372ed2 Rename/move to plugins.MetadataSourcePlugin, fix formatting 2019-09-09 17:31:42 -07:00
Carl Suster
a82002e6c1 confit: replace with confuse in core beets 2019-06-01 09:51:56 +10:00
Carl Suster
546bf3af7e mediafile: import from standalone module 2019-05-29 09:35:14 +10:00
Carl Suster
4be2e1b5e6 Remove beets.util.inspect wrapper 2019-04-02 10:22:47 +11:00
Vladimir Zhelezov
520befb30a Fix #2826: introduce beets.util.inspect wrapper 2019-03-05 08:31:44 +01:00
Vladimir Zhelezov
3eb5907da8 Merge branch 'master' of https://github.com/beetbox/beets into 2826-deprecation-warnings 2019-03-04 21:01:19 +01:00
Adrian Sampson
22c8289269 Support plugin-provided named queries 2019-02-17 13:49:54 -05:00
Vladimir Zhelezov
3e0b2ad146 Fix #2826
Test for major Python version and use inspect.getargspec() or
inspect.getfullargspec() respectively to silence deprecation warnings in
Python 3
2018-12-10 08:40:32 +01:00
Adrian Sampson
bac8faad78 Resolve W605: invalid escape sequence
This came up in lots of regexes that weren't using "raw" literals.
2018-08-13 10:41:01 -04:00
wisp3rwind
318f0c4d16 Advanced fetchart source config: pep8 2018-02-24 11:26:50 +01:00
wordofglass
5a043f28bd Advanced fetchart source config: add validation function 2018-02-24 11:26:50 +01:00
wordofglass
971584b4b2 Improve readability of plugins.sanitize_choices 2018-02-24 11:26:50 +01:00
Michal Koutenský
1bb1bca779 Move the logging wrapper code into a helper function 2018-02-21 15:54:37 +01:00
Michal Koutenský
b140f249c1 Allow plugins to define early import stage functions 2018-02-19 10:45:47 +01:00
wordofglass
bb5629ea1d Remove untyped except statements 2017-04-29 00:05:20 +02:00
nathdwek@laptop
6e3a9d9bc5 collect search results from plugins with yield 2016-11-21 13:39:44 +01:00
nathdwek@laptop
a7fed5b2c4 plugins: document notify_info_yielded 2016-11-21 10:15:51 +01:00
nathdwek@laptop
2b468c1872 plugins: make the signature of notify_info_yielded clearer 2016-11-21 10:15:51 +01:00
nathdwek@laptop
91d1aa9763 plugins: rename notify_info_received->notify_info_yielded 2016-11-21 10:15:51 +01:00
nathdwek@laptop
18a14e8005 Use generators and decorators to match items:
The easy parts
2016-11-21 10:15:51 +01:00
Johnny Robeson
fcbfce3984 replace deprecated log.warn() with log.warning() 2016-08-09 00:33:38 -04:00
Wieland Hoffmann
3aa5682a77 chmod -x plugins.py 2016-07-05 20:25:00 +02:00
Johnny Robeson
e57b7faf69 replace basestring with six.text_types 2016-06-24 05:53:55 -04:00
Johnny Robeson
330306bbe2 remove bytes casts from object/method resolution code 2016-05-30 23:21:24 -04:00
Adrian Sampson
e54c7eec3d Standardize __future__ imports without parentheses
Since the list is short enough now, we don't need parentheses for the line
wrap. This is a little less ugly.
2016-02-28 15:03:51 -08:00
Peter Kessen
9918cbb34b Removed unicode_literals from plugins and vfs 2016-02-19 22:35:14 +01:00
Jack Wilsdon
12cd5306b7 Update copyright dates to 2016 2015-12-30 15:42:06 +00:00
Peter Kessen
3eb8008b11 added encoding as comment in files
added line like
# -*- coding: utf-8 -*-
to all files with correct license in header
2015-11-19 18:41:01 +01:00
Adrian Sampson
90178ab380 Always log a template literal (fix #1481)
Otherwise, we risk the user-provided string looking like a format string! If
it contains curly braces, it can behave unexpectedly.
2015-05-28 23:44:41 -04:00
Bruno Cauet
4ff7ac5712 Plugin events log level: restore assert == NOTSET 2015-03-25 12:55:44 +01:00
Bruno Cauet
7f34c101d7 Plugin events: restore backwards compatibility
An event listener that expects too few arguments won't crash, arguments
will be cut off instead. This restores a backwards-compatibility hack
that was removed in commit 327b62b6.
2015-03-19 13:37:53 +01:00
Bruno Cauet
06cc5346f2 Make less assumptions on plugin log levels 2015-02-11 09:11:34 +01:00
Bruno Cauet
5a1f499c64 Discogs plugin: fix event listener params
Also delete related deprecated comment.
2015-02-11 09:11:20 +01:00
Bruno Cauet
f1e13cf886 Offer verbose and very verbose modes
'verbose' is now an int and not a boolean. '-v' is level 1, '-vv' level
2. In the configuration it can be set with 'verbose: 1' or 'verbose: 2'.

Improve #1244: auditing current log levels of plugins remains.
2015-02-10 17:13:15 +01:00
Bruno Cauet
327b62b610 Improve logging management for plugins: fixes
Delete the remaining usages of BeetsPlugin.listen().

Since BeetsPlugin.listeners are wrapped by a loglevel-setting function,
we cannot easily check their unicity anymore.
BeetsPlugin._raw_listeners set holds the raw listeners.

Legacy plugins that did not handle enough arguments in their listenings
functions may break: dedicated code is now deleted for it would not work
with the decorated listeners.

Tests got fixed. Some modifications were done empirically: if it passes
then it's okay.
2015-02-10 16:55:06 +01:00
Bruno Cauet
4578c4f0e1 Improve logging management for plugins
Listeners get logging level modulations, like import_stages already did.

Add extensive tests:
- explicit plugin commands are logged like core beets (INFO or DEBUG)
- import stages are more silent
- event listeners are like import stages

Delete @BeetsPlugin.listen decorator since listeners need plugin instance
context to set its logging level.

Improve #1244. Next is multiple verbosity levels.
2015-02-10 15:30:15 +01:00
Bruno Cauet
c2f8cb9983 Merge branch 'master' into future
Conflicts:
	test/test_plugins.py
2015-01-21 10:04:33 +01:00
Bruno Cauet
d6a4046245 Avoid stacking logger prefixes 2015-01-20 17:34:01 +01:00
Bruno Cauet
438044c6ae Fix bytes/str with unicode-nazi
Further cleaning will require setting unicode_literals on plugins
2015-01-20 15:25:12 +01:00
Bruno Cauet
2dab8e5fd6 Import unicode_literals in beets package 2015-01-19 21:41:33 +01:00
Bruno Cauet
90b388b775 Use __future__ imports but unicode_literals everywhere
Include import of __future__ features division, absolute_imports and
print_function everywhere. Don't add unicode_literals yet for it is
harder to convert.

Goal is smoothing the transition to python 3.
2015-01-19 12:25:16 +01:00
Adrian Sampson
b273be9d59 Event handlers can now return values
Part of #1186, which I hope to break into smaller pieces.
2015-01-17 18:39:56 -08:00
Bruno Cauet
2e57d8660e Ensure there's no duplicate plugin listeners
A same function cannot be registered twice on a given event.
This will permit improvements of some plugins (e.g. smartplaylist)
2015-01-13 11:29:42 +01:00
Bruno Cauet
c8309cbe57 Simplify BeetsPlugin.listen()
Deduplicate code with BeetsPlugin.register_listener().
2015-01-13 11:11:16 +01:00
Adrian Sampson
e83b6ae297 Logging (#1208): prefix plugin names, expand docs
We now add the plugin name to messages in verbose mode. This may not be the
best final policy, but it does help make the output more readable when many
plugins are talking at once.
2015-01-11 15:39:54 -08:00
Adrian Sampson
6d5945daa4 Use logger.getChild (#1208)
Let the library do the string formatting for us.
2015-01-11 15:08:42 -08:00
Adrian Sampson
f871ef9e21 Verbosity affects plugins (#1208)
This restores the -v flag affecting plugins. By default, plugin loggers use
the NOTSET level, which just reuses the base `beets` logger level. The level
is only auto-adjusted for the importer when not in verbose mode.
2015-01-11 15:00:20 -08:00
Adrian Sampson
24317fd4c7 Rename BeetsPlugin._import_stages to import_stages
For #1208. Restores backwards-compatibility and matches the development docs.
2015-01-11 14:27:59 -08:00
Bruno Cauet
b27c5304d1 Merge branch 'master' into logging
Conflicts:
	beetsplug/fetchart.py
	beetsplug/mpdstats.py
2015-01-09 15:15:27 +01:00
Frederik “Freso” S. Olesen
4b1f0cbf48 Happy 2015. ;)
See 7a410f636b

Command used:

    git grep -l 'Copyright 201'|xargs sed -i -E 's/Copyright 201./Copyright 2015/'`
2015-01-08 21:37:09 +01:00
Bruno Cauet
427f7e7035 Automatic logger level changes on import
Breaking changes: plugins should set set _import_stages instead of
import_stages. From outside the latter is replaced by import_stages().
This is because it is now wrapped with log level-getting & -setting
statements.
2015-01-06 21:27:15 +01:00
Bruno Cauet
d38d264b6b Add BeetsPlugin._log: per-plugin logger 2015-01-06 21:27:08 +01:00
Bruno Cauet
30f158a95e Move "from beets import logging" statements
Move the import next to other beets-related imports
2015-01-05 10:05:21 +01:00
Bruno Cauet
7df8bef8b7 Update logging imports: logging → beets.logging 2015-01-04 17:02:27 +01:00
Bruno Cauet
e75f9a703d Convert beets core to lazy logging 2015-01-04 17:02:27 +01:00
Fabrice Laporte
ea0f7ced5d remove print 2014-12-17 22:24:50 +01:00
Fabrice Laporte
474adffe63 move helper functions from utils to plugins 2014-12-17 22:00:00 +01:00
pscn
291675330d Allow plugins to define the same flexible fields if they are of the same
type #1059
2014-11-04 21:20:35 +01:00
Adrian Sampson
67b7b87d82 Fix #1001: plugin conflict error message printing 2014-10-10 10:55:40 -07:00
Adrian Sampson
72436644a6 Merge pull request #909 from arogl/master
Clean up of logging messages as described here
2014-09-14 13:14:35 -07:00
Thomas Scholtes
475d4899ee Add tests for plugins providing flexible field types 2014-09-14 12:34:45 +02:00
Thomas Scholtes
3cbe9cbd10 Plugins can define types of flexible fields
This partially solves #647.
2014-09-14 12:34:45 +02:00
e5e4eaeacd39c5cfba4d7c852c48277ae50331e6
66aee8094f Clean up of logging messages as described here
All logging now prefers the ' (single quote) over the " (double quote)

https://github.com/sampsyo/beets/wiki/Hacking
2014-09-09 11:28:43 +10:00
Thomas Scholtes
1670cb4565 Flake8 fixes 2014-04-11 16:05:08 +02:00
Adrian Sampson
b3f31cbc0a rename Item.media_fields to _media_fields
Following the convention of the other field sets and such. This helps avoid
any confusion with user-specified fields (although it's unlikely people will
want to name a flexible field "media_fields" :).
2014-04-07 20:21:20 -07:00
Thomas Scholtes
55e5381bbd Merge branch 'extendable-mediafile'
Conflicts:
	beets/library.py
	docs/dev/plugins.rst
2014-04-07 23:49:29 +02:00