| 1 |
Lyrics Plugin |
| 2 |
============= |
| 3 |
|
| 4 |
The ``lyrics`` plugin fetches and stores song lyrics from databases on the Web. |
| 5 |
Namely, the current version of the plugin uses Genius.com_, Tekstowo.pl_, |
| 6 |
LRCLIB_, lrcmux_ and, optionally, the Google Custom Search API. |
| 7 |
|
| 8 |
.. _genius.com: https://genius.com/ |
| 9 |
|
| 10 |
.. _lrclib: https://lrclib.net/ |
| 11 |
|
| 12 |
.. _lrcmux: https://lrcmux.dev/ |
| 13 |
|
| 14 |
.. _tekstowo.pl: https://www.tekstowo.pl/ |
| 15 |
|
| 16 |
Install |
| 17 |
------- |
| 18 |
|
| 19 |
Firstly, enable ``lyrics`` plugin in your configuration (see |
| 20 |
:ref:`using-plugins`). Then, install ``beets`` with ``lyrics`` extra |
| 21 |
|
| 22 |
.. code-block:: bash |
| 23 |
|
| 24 |
pip install "beets[lyrics]" |
| 25 |
|
| 26 |
Fetch Lyrics During Import |
| 27 |
-------------------------- |
| 28 |
|
| 29 |
When importing new files, beets will now fetch lyrics for files that don't |
| 30 |
already have them. The lyrics will be stored in the beets database. The plugin |
| 31 |
also sets a few useful flexible attributes: |
| 32 |
|
| 33 |
- ``lyrics_backend``: name of the backend that provided the lyrics |
| 34 |
- ``lyrics_url``: URL of the page where the lyrics were found |
| 35 |
- ``lyrics_instrumental``: whether the backend marked the track as instrumental |
| 36 |
- ``lyrics_language``: original language of the lyrics |
| 37 |
- ``lyrics_translation_language``: language of the lyrics translation (if |
| 38 |
translation is enabled) |
| 39 |
|
| 40 |
When a backend reports an instrumental track, beets leaves the lyrics text empty |
| 41 |
and sets ``lyrics_instrumental`` instead. |
| 42 |
|
| 43 |
If the ``import.write`` config option is on, then the lyrics will also be |
| 44 |
written to the files' tags. |
| 45 |
|
| 46 |
Configuration |
| 47 |
------------- |
| 48 |
|
| 49 |
To configure the plugin, make a ``lyrics:`` section in your configuration file. |
| 50 |
Default configuration: |
| 51 |
|
| 52 |
.. code-block:: yaml |
| 53 |
|
| 54 |
lyrics: |
| 55 |
auto: yes |
| 56 |
auto_ignore: null |
| 57 |
translate: |
| 58 |
api_key: |
| 59 |
from_languages: [] |
| 60 |
to_language: |
| 61 |
dist_thresh: 0.11 |
| 62 |
fallback: null |
| 63 |
force: no |
| 64 |
keep_synced: no |
| 65 |
google_API_key: null |
| 66 |
google_engine_ID: 009217259823014548361:lndtuqkycfu |
| 67 |
lrcmux: |
| 68 |
url: https://api.lrcmux.dev |
| 69 |
sources: [] |
| 70 |
print: no |
| 71 |
rest_directory: null |
| 72 |
sources: [lrclib, google, genius, lrcmux] |
| 73 |
synced: no |
| 74 |
|
| 75 |
The available options are: |
| 76 |
|
| 77 |
- **auto**: Fetch lyrics automatically during import. |
| 78 |
- **auto_ignore**: A beets query string of items to skip when fetching lyrics |
| 79 |
during auto import. For example, to skip tracks from Bandcamp or with a Techno |
| 80 |
genre: |
| 81 |
|
| 82 |
.. code-block:: yaml |
| 83 |
|
| 84 |
lyrics: |
| 85 |
auto_ignore: | |
| 86 |
data_source:bandcamp |
| 87 |
, |
| 88 |
genres:techno |
| 89 |
|
| 90 |
Default: ``null`` (nothing is ignored). See :doc:`/reference/query` for the |
| 91 |
query syntax. |
| 92 |
|
| 93 |
- **translate**: |
| 94 |
|
| 95 |
- **api_key**: Api key to access your Azure Translator resource. (see |
| 96 |
:ref:`lyrics-translation`) |
| 97 |
- **from_languages**: By default all lyrics with a language other than |
| 98 |
``translate_to`` are translated. Use a list of language codes to restrict |
| 99 |
them. |
| 100 |
- **to_language**: Language code to translate lyrics to. |
| 101 |
|
| 102 |
- **dist_thresh**: The maximum distance between the artist and title combination |
| 103 |
of the music file and lyrics candidate to consider them a match. Lower values |
| 104 |
will make the plugin more strict, higher values will make it more lenient. |
| 105 |
This does not apply to the ``lrclib`` backend as it matches durations. |
| 106 |
- **fallback**: By default, the file will be left unchanged when no lyrics are |
| 107 |
found. Use the empty string ``''`` to reset the lyrics in such a case. |
| 108 |
- **force**: By default, beets won't fetch lyrics if the files already have |
| 109 |
ones. To instead always fetch lyrics, set the ``force`` option to ``yes``. |
| 110 |
- **keep_synced**: When enabled, tracks that already have synced lyrics are |
| 111 |
skipped even when ``force`` is set. Useful when re-fetching lyrics for a |
| 112 |
library that contains a mix of synced and plain lyrics and you only want to |
| 113 |
fill in the gaps. Default: ``no``. |
| 114 |
- **google_API_key**: Your Google API key (to enable the Google Custom Search |
| 115 |
backend). |
| 116 |
- **google_engine_ID**: The custom search engine to use. Default: The `beets |
| 117 |
custom search engine`_, which gathers an updated list of sources known to be |
| 118 |
scrapeable. |
| 119 |
- **lrcmux**: |
| 120 |
|
| 121 |
- **url**: Base URL of the lrcmux_ instance to use. Override this to point at |
| 122 |
a self-hosted instance. |
| 123 |
- **sources**: List of lrcmux provider IDs to restrict the search to, e.g. |
| 124 |
``[ytmusic, kugou]``. Prefix an entry with ``!`` to exclude that provider |
| 125 |
instead, e.g. ``["!musixmatch"]``. Leave empty (the default) to use all |
| 126 |
providers. |
| 127 |
|
| 128 |
- **print**: Print lyrics to the console. |
| 129 |
- **rest_directory**: The directory to which reStructuredText_ (ReST) rendered |
| 130 |
lyric documents will be output. See :ref:`rendering-lyrics`. |
| 131 |
- **sources**: List of sources to search for lyrics. An asterisk ``*`` expands |
| 132 |
to all available sources. The ``google`` source will be automatically |
| 133 |
deactivated if no ``google_API_key`` is setup. By default, ``musixmatch`` and |
| 134 |
``tekstowo`` are excluded because they block the beets User-Agent. |
| 135 |
- **synced**: Prefer synced lyrics over plain lyrics if a source offers them. |
| 136 |
``lrclib`` and ``lrcmux`` both provide synced lyrics. Using this option, |
| 137 |
existing synced lyrics are not replaced by newly fetched plain lyrics (even |
| 138 |
when ``force`` is enabled). To allow that replacement, disable ``synced``. |
| 139 |
When synced lyrics are written to an ID3-tagged file (MP3, AIFF, etc.) the |
| 140 |
plugin stores the timestamped data in the ``SYLT`` (synchronized lyrics) frame |
| 141 |
and plain text (without timestamps) in the ``USLT`` (unsynchronized lyrics) |
| 142 |
frame, so players that support only one of the two formats can still show the |
| 143 |
correct lyrics. |
| 144 |
|
| 145 |
.. _beets custom search engine: https://cse.google.com/cse?cx=009217259823014548361:lndtuqkycfu |
| 146 |
|
| 147 |
Fetching Lyrics Manually |
| 148 |
------------------------ |
| 149 |
|
| 150 |
The ``lyrics`` command provided by this plugin fetches lyrics for items that |
| 151 |
match a query (see :doc:`/reference/query`). For example, ``beet lyrics magnetic |
| 152 |
fields absolutely cuckoo`` will get the lyrics for the appropriate Magnetic |
| 153 |
Fields song, ``beet lyrics magnetic fields`` will get lyrics for all my tracks |
| 154 |
by that band, and ``beet lyrics`` will get lyrics for my entire library. The |
| 155 |
lyrics will be added to the beets database and, if ``import.write`` is on, |
| 156 |
embedded into files' metadata. |
| 157 |
|
| 158 |
The ``-p, --print`` option to the ``lyrics`` command makes it print lyrics out |
| 159 |
to the console so you can view the fetched (or previously-stored) lyrics. |
| 160 |
|
| 161 |
The ``-f, --force`` option forces the command to fetch lyrics, even for tracks |
| 162 |
that already have lyrics. |
| 163 |
|
| 164 |
The ``--keep-synced`` option skips tracks that already have synced lyrics, |
| 165 |
regardless of the ``force`` flag. This is handy when you want to re-fetch plain |
| 166 |
lyrics without touching tracks that already have a synced version. Use |
| 167 |
``--no-keep-synced`` to override a ``keep_synced: yes`` configuration for a |
| 168 |
single command run. |
| 169 |
|
| 170 |
Inversely, the ``-l, --local`` option restricts operations to lyrics that are |
| 171 |
locally available, which show lyrics faster without using the network at all. |
| 172 |
|
| 173 |
.. _rendering-lyrics: |
| 174 |
|
| 175 |
Rendering Lyrics into Other Formats |
| 176 |
----------------------------------- |
| 177 |
|
| 178 |
The ``-r directory, --write-rest directory`` option renders all lyrics as |
| 179 |
reStructuredText_ (ReST) documents in ``directory``. That directory, in turn, |
| 180 |
can be parsed by tools like Sphinx_ to generate HTML, ePUB, or PDF documents. |
| 181 |
|
| 182 |
Minimal ``conf.py`` and ``index.rst`` files are created the first time the |
| 183 |
command is run. They are not overwritten on subsequent runs, so you can safely |
| 184 |
modify these files to customize the output. |
| 185 |
|
| 186 |
Sphinx supports various builders_, see a few suggestions: |
| 187 |
|
| 188 |
.. admonition:: Build an HTML version |
| 189 |
|
| 190 |
:: |
| 191 |
|
| 192 |
sphinx-build -b html <dir> <dir>/html |
| 193 |
|
| 194 |
.. admonition:: Build an ePUB3 formatted file, usable on ebook readers |
| 195 |
|
| 196 |
:: |
| 197 |
|
| 198 |
sphinx-build -b epub3 <dir> <dir>/epub |
| 199 |
|
| 200 |
.. admonition:: Build a PDF file, which incidentally also builds a LaTeX file |
| 201 |
|
| 202 |
:: |
| 203 |
|
| 204 |
sphinx-build -b latex <dir> <dir>/latex && make -C <dir>/latex all-pdf |
| 205 |
|
| 206 |
.. _builders: https://www.sphinx-doc.org/en/master/usage/builders/index.html |
| 207 |
|
| 208 |
.. _restructuredtext: https://sourceforge.net/projects/docutils/ |
| 209 |
|
| 210 |
.. _sphinx: https://www.sphinx-doc.org/en/master/ |
| 211 |
|
| 212 |
Activate Google Custom Search |
| 213 |
----------------------------- |
| 214 |
|
| 215 |
You need to `register for a Google API key |
| 216 |
<https://console.cloud.google.com/apis/credentials>`__. Set the |
| 217 |
``google_API_key`` configuration option to your key. |
| 218 |
|
| 219 |
Then add ``google`` to the list of sources in your configuration (or use default |
| 220 |
list, which includes it as long as you have an API key). If you use default |
| 221 |
``google_engine_ID``, we recommend limiting the sources to ``google`` as the |
| 222 |
other sources are already included in the Google results. |
| 223 |
|
| 224 |
Optionally, you can `define a custom search engine`_. Get your search engine's |
| 225 |
token and use it for your ``google_engine_ID`` configuration option. By default, |
| 226 |
beets use a list of sources known to be scrapeable. |
| 227 |
|
| 228 |
Note that the Google custom search API is limited to 100 queries per day. After |
| 229 |
that, the lyrics plugin will fall back on other declared data sources. |
| 230 |
|
| 231 |
.. _define a custom search engine: https://programmablesearchengine.google.com/about/ |
| 232 |
|
| 233 |
.. _lyrics-translation: |
| 234 |
|
| 235 |
Activate On-the-Fly Translation |
| 236 |
------------------------------- |
| 237 |
|
| 238 |
We use Azure to optionally translate your lyrics. To set up the integration, |
| 239 |
follow these steps: |
| 240 |
|
| 241 |
1. `Create a Translator resource`_ on Azure. |
| 242 |
Make sure the region of the translator resource is set to Global. You |
| 243 |
will get 401 unauthorized errors if not. The region of the resource group |
| 244 |
does not matter. |
| 245 |
2. `Obtain its API key`_. |
| 246 |
3. Add the API key to your configuration as ``translate.api_key``. |
| 247 |
4. Configure your target language using the ``translate.to_language`` option. |
| 248 |
|
| 249 |
For example, with the following configuration |
| 250 |
|
| 251 |
.. code-block:: yaml |
| 252 |
|
| 253 |
lyrics: |
| 254 |
translate: |
| 255 |
api_key: YOUR_TRANSLATOR_API_KEY |
| 256 |
to_language: de |
| 257 |
|
| 258 |
You should expect lyrics like this: |
| 259 |
|
| 260 |
:: |
| 261 |
|
| 262 |
Original verse / Ursprünglicher Vers |
| 263 |
Some other verse / Ein anderer Vers |
| 264 |
|
| 265 |
.. _create a translator resource: https://learn.microsoft.com/en-us/azure/ai-services/translator/create-translator-resource |
| 266 |
|
| 267 |
.. _obtain its api key: https://learn.microsoft.com/en-us/python/api/overview/azure/ai-translation-text-readme?view=azure-python&preserve-view=true#get-an-api-key |