| 1 |
Chromaprint/Acoustid Plugin |
| 2 |
=========================== |
| 3 |
|
| 4 |
Acoustic fingerprinting is a technique for identifying songs from the way they |
| 5 |
"sound" rather from their existing metadata. That means that beets' autotagger |
| 6 |
can theoretically use fingerprinting to tag files that don't have any ID3 |
| 7 |
information at all (or have completely incorrect data). This plugin uses an |
| 8 |
open-source fingerprinting technology called Chromaprint_ and its associated Web |
| 9 |
service, called Acoustid_. |
| 10 |
|
| 11 |
.. _acoustid: https://acoustid.org/ |
| 12 |
|
| 13 |
.. _chromaprint: https://acoustid.org/chromaprint |
| 14 |
|
| 15 |
Turning on fingerprinting can increase the accuracy of the |
| 16 |
autotagger---especially on files with very poor metadata---but it comes at a |
| 17 |
cost. First, it can be trickier to set up than beets itself (you need to set up |
| 18 |
the native fingerprinting library, whereas all of the beets core is written in |
| 19 |
pure Python). Also, fingerprinting takes significantly more CPU and memory than |
| 20 |
ordinary tagging---which means that imports will go substantially slower. |
| 21 |
|
| 22 |
If you're willing to pay the performance cost for fingerprinting, read on! |
| 23 |
|
| 24 |
Installing Dependencies |
| 25 |
----------------------- |
| 26 |
|
| 27 |
To get fingerprinting working, you'll need to install three things: |
| 28 |
|
| 29 |
1. pyacoustid_ Python library (version 0.6 or later). You can install it by |
| 30 |
installing ``beets`` with ``chroma`` extra |
| 31 |
|
| 32 |
.. code-block:: bash |
| 33 |
|
| 34 |
pip install "beets[chroma]" |
| 35 |
|
| 36 |
2. the Chromaprint_ library_ or |command-line-tool|_ |
| 37 |
3. an |audio-decoder|_ |
| 38 |
|
| 39 |
.. |command-line-tool| replace:: command line tool |
| 40 |
|
| 41 |
.. |audio-decoder| replace:: audio decoder |
| 42 |
|
| 43 |
.. _command-line-tool: |
| 44 |
|
| 45 |
Installing the Binary Command-Line Tool |
| 46 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 |
|
| 48 |
The simplest way to get up and running, especially on Windows, is to download_ |
| 49 |
the appropriate Chromaprint binary package and place the ``fpcalc`` (or |
| 50 |
``fpcalc.exe``) on your shell search path. On Windows, this means something like |
| 51 |
``C:\\Program Files``. On OS X or Linux, put the executable somewhere like |
| 52 |
``/usr/local/bin``. |
| 53 |
|
| 54 |
.. _download: https://acoustid.org/chromaprint |
| 55 |
|
| 56 |
.. _library: |
| 57 |
|
| 58 |
Installing the Library |
| 59 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 60 |
|
| 61 |
On OS X and Linux, you can also use a library installed by your package manager, |
| 62 |
which has some advantages (automatic upgrades, etc.). The Chromaprint site has |
| 63 |
links to packages for major Linux distributions. If you use Homebrew_ on Mac OS |
| 64 |
X, you can install the library with ``brew install chromaprint``. |
| 65 |
|
| 66 |
.. _audio-decoder: |
| 67 |
|
| 68 |
.. _homebrew: https://brew.sh/ |
| 69 |
|
| 70 |
Audio Decoder |
| 71 |
~~~~~~~~~~~~~ |
| 72 |
|
| 73 |
You will also need a mechanism for decoding audio files supported by the |
| 74 |
audioread_ library: |
| 75 |
|
| 76 |
- OS X has a number of decoders already built into Core Audio, so there's no |
| 77 |
need to install anything. |
| 78 |
- On Linux, you can install GStreamer_ with PyGObject_, FFmpeg_, or MAD_ with |
| 79 |
pymad_. How you install these will depend on your distribution. For example, |
| 80 |
on Ubuntu, run ``apt-get install gstreamer1.0 python-gi``. On Arch Linux, you |
| 81 |
want ``pacman -S gstreamer python2-gobject``. If you use GStreamer, be sure to |
| 82 |
install its codec plugins also (``gst-plugins-good``, etc.). |
| 83 |
|
| 84 |
Note that if you install beets in a virtualenv, you'll need it to have |
| 85 |
``--system-site-packages`` enabled for Python to see the GStreamer bindings. |
| 86 |
|
| 87 |
- On Windows, builds are provided by GStreamer_ |
| 88 |
|
| 89 |
.. _audioread: https://github.com/beetbox/audioread |
| 90 |
|
| 91 |
.. _core audio: https://developer.apple.com/documentation/coreaudio |
| 92 |
|
| 93 |
.. _ffmpeg: https://ffmpeg.org/ |
| 94 |
|
| 95 |
.. _gstreamer: https://gstreamer.freedesktop.org/ |
| 96 |
|
| 97 |
.. _mad: https://www.underbit.com/products/mad/ |
| 98 |
|
| 99 |
.. _pyacoustid: https://github.com/beetbox/pyacoustid |
| 100 |
|
| 101 |
.. _pygobject: https://wiki.gnome.org/Projects/PyGObject |
| 102 |
|
| 103 |
.. _pymad: https://spacepants.org/src/pymad/ |
| 104 |
|
| 105 |
To decode audio formats (MP3, FLAC, etc.) with GStreamer, you'll need the |
| 106 |
standard set of Gstreamer plugins. For example, on Ubuntu, install the packages |
| 107 |
``gstreamer1.0-plugins-good``, ``gstreamer1.0-plugins-bad``, and |
| 108 |
``gstreamer1.0-plugins-ugly``. |
| 109 |
|
| 110 |
Usage |
| 111 |
----- |
| 112 |
|
| 113 |
Once you have all the dependencies sorted out, enable the ``chroma`` plugin in |
| 114 |
your configuration (see :ref:`using-plugins`) to benefit from fingerprinting the |
| 115 |
next time you run ``beet import``. (The plugin doesn't produce any obvious |
| 116 |
output by default. If you want to confirm that it's enabled, you can try running |
| 117 |
in verbose mode once with ``beet -v import``.) |
| 118 |
|
| 119 |
You can also use the ``beet fingerprint`` command to generate fingerprints for |
| 120 |
items already in your library. (Provide a query to fingerprint a subset of your |
| 121 |
library.) The generated fingerprints will be stored in the library database. If |
| 122 |
you have the ``import.write`` config option enabled, they will also be written |
| 123 |
to files' metadata. |
| 124 |
|
| 125 |
.. note:: |
| 126 |
|
| 127 |
The ``chroma`` plugin turns Acoustid fingerprint matches into autotagger |
| 128 |
candidates by resolving them through the :doc:`musicbrainz` plugin, so you |
| 129 |
need to enable ``musicbrainz`` alongside ``chroma`` to get album and track |
| 130 |
candidates from acoustid lookups. If ``musicbrainz`` is not enabled, the |
| 131 |
``chroma`` plugin will still fingerprint your files and store the |
| 132 |
``acoustid_id`` and ``acoustid_fingerprint`` fields, but it will not |
| 133 |
contribute candidates during autotagging. |
| 134 |
|
| 135 |
.. _submitfp: |
| 136 |
|
| 137 |
Configuration |
| 138 |
------------- |
| 139 |
|
| 140 |
There is one configuration option in the ``chroma:`` section, ``auto``, which |
| 141 |
controls whether to fingerprint files during the import process. To disable |
| 142 |
fingerprint-based autotagging, set it to ``no``, like so: |
| 143 |
|
| 144 |
:: |
| 145 |
|
| 146 |
chroma: |
| 147 |
auto: no |
| 148 |
|
| 149 |
Submitting Fingerprints |
| 150 |
----------------------- |
| 151 |
|
| 152 |
You can help expand the Acoustid_ database by submitting fingerprints for the |
| 153 |
music in your collection. To do this, first `get an API key`_ from the Acoustid |
| 154 |
service. Just use an OpenID or MusicBrainz account to log in and you'll get a |
| 155 |
short token string. Then, add the key to your ``config.yaml`` as the value |
| 156 |
``apikey`` in a section called ``acoustid`` like so: |
| 157 |
|
| 158 |
:: |
| 159 |
|
| 160 |
acoustid: |
| 161 |
apikey: AbCd1234 |
| 162 |
|
| 163 |
Then, run ``beet submit``. (You can also provide a query to submit a subset of |
| 164 |
your library.) The command will use stored fingerprints if they're available; |
| 165 |
otherwise it will fingerprint each file before submitting it. |
| 166 |
|
| 167 |
.. _get an api key: https://acoustid.org/api-key |
| 168 |
|
| 169 |
Fingerprint Search |
| 170 |
------------------ |
| 171 |
|
| 172 |
The ``chromasearch`` command lets you search your local beets library for tracks |
| 173 |
with similar audio fingerprints. This is useful for identifying duplicate files, |
| 174 |
finding alternate encodings of the same recording, or locating tracks when |
| 175 |
metadata is missing or incorrect. |
| 176 |
|
| 177 |
To perform a search, run: |
| 178 |
|
| 179 |
.. code-block:: shell |
| 180 |
|
| 181 |
beet chromasearch -s FINGERPRINT |
| 182 |
|
| 183 |
The fingerprint must be provided using the ``-s`` (``--search``) option. You can |
| 184 |
generate a fingerprint using the external ``fpcalc`` tool from the Chromaprint_ |
| 185 |
project. For example: |
| 186 |
|
| 187 |
.. code-block:: shell |
| 188 |
|
| 189 |
fpcalc -plain somefile.mp3 |
| 190 |
|
| 191 |
By default the whole library is searched, use a :doc:`query </reference/query>` |
| 192 |
to restrict the search: |
| 193 |
|
| 194 |
.. code-block:: shell |
| 195 |
|
| 196 |
beet chromasearch -s FINGERPRINT artist:"rolling stones" |
| 197 |
|
| 198 |
By default, the command returns the top 5 closest matches in your library. You |
| 199 |
can change the number of results using the ``-c`` (``--count``) option. |
| 200 |
|
| 201 |
When an exact match is found, the search normally stops early. To continue |
| 202 |
searching for additional similar items even after an exact match, use the |
| 203 |
``--full`` flag. |
| 204 |
|
| 205 |
The ``-w`` (``--write``) option causes the plugin to store fingerprints for |
| 206 |
files that do not already have them. This can improve search results over time |
| 207 |
by ensuring more items in your library are indexed. |