Art and Plugins
Outcome: your albums can carry
their cover art — as a file beside
the music and as a picture inside
the files themselves — and you have
met the plugin system that gives
beets its extra commands, including
a web interface that serves your
library as JSON. Evidence:
transcripts t08-fetchart-embedart.txt
and t09-web-plugin.txt, and the
info plugin has been at work since
chapter 5.
Plugins, in one paragraph
A plugin is switched on by listing its name in the config:
plugins: duplicates info web fetchart embedart
That one line is the whole ceremony:
beets loads those modules at
startup, their commands appear in
beet help, and their import-time
hooks start running. Plugins reach
deep — some add fields, some react
to imports, some (like web) run
servers — so the catalogue deserves
a skim before an install spree, and
a plugin that cannot load (missing
Python package, usually) complains
at startup and is skipped rather
than taking beets down with it.
fetchart: where covers come from
The fetchart plugin finds album
art and records it as the album's
artpath. Its sources, in the
lab's configuration, was exactly
one:
fetchart:
sources: filesystem
The filesystem source looks in
the album's own folder for an image
with a cover-ish name — cover.jpg
is the canonical one. The lab
dropped an orange square by that
name beside the FLAC album and:
beet fetchart albumartist:"Ada Volt & The Resistors"
Ada Volt & The Resistors - Ohm Sweet Ohm: found album art
Two things in that story matter
beyond the trick. First, album A
needed no command at all: an image
in the source folder at import
time is noticed by the importer
itself, carried into the new folder,
and set as the art — the command is
for art that arrives later. Second,
a flag inverts the meaning of
"local": beet fetchart -f means
fetch fresh, ignoring what's here,
and with local sources only, it
dutifully found nothing (the lab
ran it first, and chapter 13 keeps
the story). The remote sources —
the Cover Art Archive, Amazon,
iTunes and others, used when the
config does not restrict sources —
are documented-only here: they are
other people's servers, they were
not needed to prove the machinery,
and what art they return for a
given pressing is exactly the kind
of claim this guide does not make
unrun.
embedart: the picture moves in
An artpath is a file beside the
music. Some players read it; some
don't. embedart writes the picture
into each audio file, where
practically every player looks:
beet embedart --yes albumartist:"Ada Volt & The Resistors"
embedart: Embedding album art into Ada Volt & The Resistors - Ohm Sweet Ohm
The check is structural, and
ffprobe performs it: the FLAC
file's streams go from audio-only to
audio plus mjpeg — the picture,
riding inside the file. Remember
from chapter 8 that this changes
your files' bytes; embedding is a
small, deliberate act of file
surgery, done once per album, and
the reason checksum-based duplicate
hunting later draws a blank is
usually sitting right here.
web: the library as JSON
The web plugin serves the library
over HTTP — its own tiny player page
for browsers, and underneath it a
plain JSON API. The lab bound it to
the safest address there is,
loopback only, on its assigned
port:
web:
host: 127.0.0.1
port: 18088
beet web &
curl -s http://127.0.0.1:18088/stats
{"albums":2,"items":6}
/item/ and /album/ answer with
the full records, field by field —
every fact beet ls -f can print,
as data a script can consume. That
is the point of the plugin: not the
little web page, but your library as
an interface something else can
build on. Two cautions, both real.
The server is a development server
(its own startup banner says so):
fine on loopback for your scripts,
not a thing to expose to a network —
beets' web plugin has no login, and
anyone who can reach the port can
read the catalogue (and, through
its file endpoints, more). And it
needs the Flask packages from
chapter 3; without them you get a
startup error naming the plugin and
beets carries on web-less.