mirror of
https://github.com/beetbox/beets.git
synced 2026-01-04 23:12:51 +01:00
Created autotagger file and enhanced the docs significantly.
This commit is contained in:
parent
676dc9c953
commit
037e59fe8f
3 changed files with 104 additions and 23 deletions
103
docs/dev/plugins/autotagger.rst
Normal file
103
docs/dev/plugins/autotagger.rst
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
Extending the Autotagger
|
||||
========================
|
||||
|
||||
.. currentmodule:: beets.metadata_plugins
|
||||
|
||||
Beets supports **metadata source plugins**, which allow it to fetch and match
|
||||
metadata from external services (such as Spotify, Discogs, or Deezer). This
|
||||
guide explains how to build your own metadata source plugin by extending the
|
||||
:py:class:`MetadataSourcePlugin`.
|
||||
|
||||
These plugins integrate directly with the autotagger, providing candidate
|
||||
metadata during lookups. To implement one, you must subclass
|
||||
:py:class:`MetadataSourcePlugin` and implement its abstract methods.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
Creating a metadata source plugin is very similar to writing a standard plugin
|
||||
(see :ref:`basic-plugin-setup`). The main difference is that your plugin must:
|
||||
|
||||
1. Subclass :py:class:`MetadataSourcePlugin`.
|
||||
2. Implement all required abstract methods.
|
||||
|
||||
Here`s a minimal example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# beetsplug/myawesomeplugin.py
|
||||
from typing import Sequence
|
||||
from beets.autotag.hooks import Item
|
||||
from beets.metadata_plugin import MetadataSourcePlugin
|
||||
|
||||
|
||||
class MyAwesomePlugin(MetadataSourcePlugin):
|
||||
|
||||
def candidates(
|
||||
self,
|
||||
items: Sequence[Item],
|
||||
artist: str,
|
||||
album: str,
|
||||
va_likely: bool,
|
||||
): ...
|
||||
|
||||
def item_candidates(self, item: Item, artist: str, title: str): ...
|
||||
|
||||
def track_for_id(self, track_id: str): ...
|
||||
|
||||
def album_for_id(self, album_id: str): ...
|
||||
|
||||
How Metadata Lookup Works
|
||||
-------------------------
|
||||
|
||||
When beets runs the autotagger, it queries **all enabled metadata source
|
||||
plugins** for potential matches:
|
||||
|
||||
- For **albums**, it calls :py:meth:`~MetadataSourcePlugin.candidates`.
|
||||
- For **individual items**, it calls
|
||||
:py:meth:`~MetadataSourcePlugin.item_candidates`.
|
||||
|
||||
The results are combined and scored. By default, candidate ranking is handled
|
||||
automatically by the beets core, but you can customize weighting by overriding:
|
||||
|
||||
- :py:meth:`~MetadataSourcePlugin.album_distance`
|
||||
- :py:meth:`~MetadataSourcePlugin.track_distance`
|
||||
|
||||
This is optional, if not overridden, both methods return a constant distance of
|
||||
`0.5`.
|
||||
|
||||
Implementing ID-based Lookups
|
||||
-----------------------------
|
||||
|
||||
Your plugin must also define:
|
||||
|
||||
- :py:meth:`~MetadataSourcePlugin.album_for_id` — fetch album metadata by ID.
|
||||
- :py:meth:`~MetadataSourcePlugin.track_for_id` — fetch track metadata by ID.
|
||||
|
||||
These methods should return `None` if your source doesn`t support ID lookups.
|
||||
IDs are expected to be strings. If your source uses specific formats, consider
|
||||
contributing an extractor regex to the core module:
|
||||
:py:mod:`beets.util.id_extractors`.
|
||||
|
||||
Best Practices
|
||||
--------------
|
||||
|
||||
Beets already ships with several metadata source plugins. Studying these
|
||||
implementations can help you follow conventions and avoid pitfalls. Good
|
||||
starting points include:
|
||||
|
||||
- `spotify`
|
||||
- `deezer`
|
||||
- `discogs`
|
||||
|
||||
Migration Guidance
|
||||
------------------
|
||||
|
||||
Older metadata plugins that extend :py:class:`beets.plugins.BeetsPlugin` should
|
||||
be migrated to :py:class:`MetadataSourcePlugin`. Legacy support will be removed
|
||||
in **beets v3.0.0**.
|
||||
|
||||
.. seealso::
|
||||
|
||||
- :py:mod:`beets.autotag`
|
||||
- :py:mod:`beets.metadata_plugins`
|
||||
|
|
@ -99,4 +99,5 @@ resources:
|
|||
|
||||
commands
|
||||
events
|
||||
autotagger
|
||||
other
|
||||
|
|
|
|||
|
|
@ -5,29 +5,6 @@ Further Reading
|
|||
:local:
|
||||
:depth: 2
|
||||
|
||||
Extending the Autotagger
|
||||
------------------------
|
||||
|
||||
.. currentmodule:: beets.metadata_plugins
|
||||
|
||||
Plugins can also be used to extend the autotagger functions i.e. the metadata
|
||||
lookup from external sources. For this your plugin has to extend the
|
||||
:py:class:`MetadataSourcePlugin` base class and implement all abstract methods.
|
||||
|
||||
On metadata lookup, the autotagger will try to find matching candidates from all
|
||||
enabled metadata source plugins. To do this, we will call the
|
||||
:py:meth:`MetadataSourcePlugin.candidates` (or
|
||||
:py:meth:`MetadataSourcePlugin.item_candidates`) with all available (local)
|
||||
metadata. The list of retrieved candidates will be ranked by their
|
||||
:py:meth:`MetadataSourcePlugin.album_distance` (or
|
||||
:py:meth:`MetadataSourcePlugin.track_distance`) and be presented to the user for
|
||||
selection (or automatically selected if the threshold is met).
|
||||
|
||||
Please have a look at the ``beets.autotag`` and especially the
|
||||
``beets.metadata_plugin`` modules for more information. Additionally, for a
|
||||
comprehensive example, see the ``musicbrainz`` or ``chroma`` plugins, which are
|
||||
included with beets.
|
||||
|
||||
Read Configuration Options
|
||||
--------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue