Asking Your Library
Outcome: you can ask the library
questions in words, shape the answers
into the listing you actually want,
and tell the difference between what
the database believes and what a
file says. Everything here is
transcript t03-queries.txt.
Listing and the query language
beet ls (or beet list) with no
arguments lists every track, one
line each, as Artist - Album -
Title. Arguments are a query:
terms matched against fields.
beet ls
beet ls albumartist:"Ada Volt & The Resistors"
Ada Volt & The Resistors - Ohm Sweet Ohm - Current Affairs
Ada Volt & The Resistors - Ohm Sweet Ohm - Ground Loop Blues
The grammar is small and worth learning whole:
- A bare word matches any field:
beet ls sunrisefinds the track by its title. field:valuenarrows it:album:Experiments,year:2021,artist:"Lab Tones"(quotes keep phrases together).- Terms combine as and:
beet ls artist:"Lab Tones" year:2021. - Prefixes add range and precision:
year:2020..2024,title:^Quiet(starts with), and a leading-or^negations have their own forms — the beets documentation lists them all; the two above cover most days.
beet ls -a asks the same questions
of albums instead of tracks:
Ada Volt & The Resistors - Ohm Sweet Ohm
The Lab Tones - First Experiments
The Lab Tones - First Experimnets
—that last line is the lab's
misspelled album before chapter 6
fixed it, and its presence
in an album listing is often how a
tag typo is first discovered. Keep
the track/album distinction in mind:
it is the same one chapter 6's
modify will need.
Shaping the answer
The default line is a summary, not a
law. -f takes a format string
with $field placeholders and prints
exactly what you ask, one line per
track:
beet ls -f '$albumartist - $title ($length, $format)'
The Lab Tones - Sine Wave Sunrise (0:04, MP3)
Ada Volt & The Resistors - Ground Loop Blues (0:05, FLAC)
This is the door to scripting:
beet ls -f '$path' is a playlist
generator, $mb_trackid is an audit
of what has been matched, and
$album_id — as chapter 6 will show —
is how you prove two identically
named albums are two records. A
placeholder for a field a track does
not have prints the field's name
literally, $genres-style surprises
included; when a format prints
something odd like that, the field
name is usually slightly different
from the one you guessed.
info: what the file says
beet info TITLE comes from the
info plugin (chapter 9) and is a
different witness: it ignores the
database and reads the file
itself, printing everything the tag
layer finds — tags, length, bitrate,
sample rate, format, and whether art
is embedded (art: True).
$ beet info "Sine Wave Sunrise"
.../library/The Lab Tones/First Experiments/01 Sine Wave Sunrise.mp3
albumartist: The Lab Tones
title: Sine Wave Sunrise
length: 4.048979591836734
format: MP3
art: True
Keep both witnesses in reach. ls
is fast and answers for thousands of
tracks at once, but it can only
repeat what the database recorded.
info is slow and one file at a
time, but it cannot be fooled by a
stale record — chapter 6's update
story is precisely a case of the two
disagreeing, and info is how the
lab proved which side held the truth.
stats: the library in one breath
beet stats
Tracks: 6
Total time: 22.1 seconds
Approximate total size: 159.0 KiB
Artists: 2
Albums: 3
Album artists: 2
Your numbers will be larger and more
interesting. stats is the quick
health check after any big operation:
imports should raise the counts by
what you fed them, cleanups should
lower them by what you removed, and
chapter 10's monthly routine starts
with exactly this glance.