## Description
Fixes#4889.
When the first field of a path format is empty, the rendered fragment
starts with a separator (the reporter's untagged files gave `//00 ` from
the default path format). `util.components()` keeps that leading
separator as a root component. The default `replace` rules turn it into
`_`, but a custom `replace` config overrides the defaults, so the root
survives, the fragment comes back absolute and `os.path.join(basedir,
...)` throws the base directory away. With convert's `auto: yes` that
ended in:
```text
PermissionError: [Errno 13] Permission denied: b'//00 .mp3'
```
The fragment is always meant to be relative to the base directory, so
`Item.destination()` now strips leading separators before joining.
Nothing changes for the default replacements. Added a regression test
next to `test_destination_with_replacements`. It fails on master and
passes with the change.
## To Do
- [x] ~Documentation.~ Bug fix, no new options.
- [x] Changelog.
- [x] Tests.
## Description
The Discogs API reports a release's full date in `released`
("2000-08-13"), and only its year in `year`. `get_album_info` reads
`year` alone, so every Discogs match carries an empty month and day. On
top of that, `AlbumInfo` turns a set year into an explicit `month = 0,
day = 0`, so applying a Discogs match actively cleared those tags rather
than merely failing to fill them.
To obtain a full release date, parse `released`. Unfortunately, the
documentation doesn't provide an accurate description of an expected
format. To my observation, `released` dates are loosely
ISO8601-complaint, with month and day being optional. Unknown component
may be present but zero (e.g. `2000-00-00`), so zeroes are treated as
unknown.
Unparsable dates fall back to `year`.
A release with no master release is already assumed to be its own
original in the existing code, so `month` and `day` are used to fill
`original_month` and `original_day`.
## To Do
<!--
- If you believe one of below checkpoints is not required for the change
you
are submitting, cross it out and check the box nonetheless to let us
know.
For example: - [x] ~Changelog~
- Regarding the changelog, often it makes sense to add your entry only
once
reviewing is finished. That way you might prevent conflicts from other
PR's in
that file, as well as keep the chance high your description fits with
the
latest revision of your feature/fix.
- Regarding documentation, bugfixes often don't require additions to the
docs.
- Please remove the descriptive sentences in braces from the enumeration
below,
which helps to unclutter your PR description.
-->
- [x] Documentation. (If you've added a new command-line flag, for
example, find the appropriate page under `docs/` to describe it.)
- [x] Changelog. (Add an entry to `docs/changelog.rst` to the bottom of
one of the lists near the top of the document.)
- [x] Tests. (Very much encouraged but not strictly required.)
## Description
I've noticed a few open source projects adding an AI_POLICY.md to their
repositories. Considering the amount of PR's we're getting that seem to
be fully automated - I think adding one could be a good and obvious mark
of our policy with primarily AI driven contributions.
This is an early draft and I would like input from other maintainers to
shape this to reflect how we use AI tools on the beets project.
## To Do
- [x] Documentation. (If you've added a new command-line flag, for
example, find the appropriate page under `docs/` to describe it.)
- [ ] Changelog. (Add an entry to `docs/changelog.rst` to the bottom of
one of the lists near the top of the document.)
## Description
Fixes#7002.
Both `py7zr` and `rarfile` are optional dependencies specified under the
`import` extra (`beets[import]`).
When running the test suite in environments where `py7zr` is not
installed (e.g. minimal packaging buildroots such as Fedora Rawhide),
`ArchiveImportTask.handlers` does not register the 7z extraction
handler. Consequently, `TestImport7z` runs unconditionally and treats
`archive.7z` as an ordinary file rather than an archive, failing with:
```text
FAILED test/test_importer.py::TestImport7z::test_import_zip
E assert 0 == 1
E + where 0 = len(<beets.dbcore.db.Results object>)
E + where <beets.dbcore.db.Results object> = items()
WARNING beets:stages.py:58 No files imported from .../test/rsrc/archive.7z
```
Additionally, `TestImportRar` previously checked only for the presence
of the `unrar` executable via `has_program("unrar")`, but extraction
also depends on the Python `rarfile` package being importable.
This PR:
1. Adds `NEEDS_PY7ZR` (`is_importable("py7zr")`) and `NEEDS_RARFILE`
(`is_importable("rarfile") and has_program("unrar")`) test skip markers
in `beets.test.helper`.
2. Marks `TestImport7z` with `@NEEDS_PY7ZR`.
3. Marks `TestImportRar` with `@NEEDS_RARFILE`.
4. Adds an unreleased bug fix entry to `docs/changelog.rst`.
## To Do
- [x] ~Documentation.~
- [x] Changelog.
- [x] Tests.
- Adds the `merge_group` trigger to `.github/workflows/lint.yaml`, so
the existing lint workflow now runs for merge queue validation as well
as `pull_request` and `push`.
- Adds the `merge_group` trigger to `.github/workflows/ci.yaml` so the
main CI workflow runs for GitHub merge queue events, not just
`pull_request` and `push`.
## Description
LRCLIB commonly returns LRC timestamps with 3 decimal places
(`[mm:ss.xxx]`). `LINE_PARTS_PAT` and `LRC_TIMESTAMP_PAT` strictly
expected two digits (`\.\d\d`), causing `verify_synced_lyrics` to fail
when the final line of a song has millisecond precision and silently
fall back to `plainLyrics`.
Additionally, interior 3-decimal lines had timestamps dropped from ID3
`SYLT` frames and leaked raw bracketed tags into plain text extraction.
- Update regexes to accept `\.\d{2,3}`
- Parse both 2-digit (cs) and 3-digit (ms) fractions in `Lyrics.sylt`
- Add unit tests and changelog entry
## To Do
- [x] ~Documentation~
- [x] Changelog
- [x] Tests
LRCLIB commonly returns LRC timestamps with 3 decimal places ([mm:ss.xxx]).
LINE_PARTS_PAT and LRC_TIMESTAMP_PAT strictly expected two digits (\.\d\d),
causing verify_synced_lyrics to fail when the final line of a song has
millisecond precision (e.g. Final Light - Final Light ending with [06:07.301])
and fall back to plain text.
Additionally, interior 3-decimal lines had timestamps dropped from ID3 SYLT
frames and leaked raw bracketed tags into plain text extraction.
- Update regexes to accept \.\d{2,3}
- Parse both 2-digit (cs) and 3-digit (ms) fractions in Lyrics.sylt
- Add unit tests and changelog entry
Fixes#3979.
The docs suggested `beet dup -C 'md5sum {file}'` as a checksum command,
but it can never match anything: the plugin uses the command's entire
output as the checksum, and md5sum prints the file's path after the
hash, so two copies of the same file always look different. The docs
also didn't explain how the command is run (split shlex-style with
`{file}` substituted per argument, no shell, so no pipes or
redirection).
Reworded the `checksum` option description to cover that, dropped the
broken md5sum example and added a small wrapper-script recipe for
commands like md5sum. I checked the recipe end to end on a throwaway
library with duplicate files (paths with spaces included); the
duplicates plugin tests pass and sphinx-lint/docstrfmt are clean on the
changed files.
Closes#5076
Supersedes #6690
#### What changed
- Added a built-in `-l` / `--limit` flag to the `list` command, so
result limiting now lives in `beets` core instead of the `limit` plugin.
- Threaded `limit` support through the main query path:
`beets.ui.commands.list` -> `Library.items()` / `Library.albums()` ->
`dbcore._get_results()`.
- Updated query execution so limits are applied in the database when
possible, and after in-memory sorting when sorting depends on flexible
or computed fields.
- Refactored sort selection into model-level `field_sort()` logic, which
also improves sorting for related database fields.
- Deprecated `LimitPlugin` and updated docs/changelog to point users to
`beet ls -l <number>`.
#### Architecture impact
- This moves result limiting from optional plugin behavior into the main
`list` command flow, making it a first-class CLI capability.
- The database layer now has clearer responsibility for deciding whether
`LIMIT` can be pushed into SQL or must be applied after slow sorting.
- Sort handling is more centralized and model-aware, which reduces
special-case logic in query parsing and improves support for related
fields.
#### High-level outcome
- Users get a simpler and more discoverable way to limit `list` results.
- `list` now works correctly with `limit` even when sorting by flexible
attributes or related fields.
- The old `limit` plugin is being phased out in favor of a smaller, more
integrated command path.
- We can later add this flag to other commands such as `modify`, `write`
and `update`.
## Summary
- Fix 404 link to `test/test_query.py` in `CONTRIBUTING.rst` — file
moved to `test/dbcore/test_query.py`
- Add crawler-blocking and unreachable sites to `linkcheck_ignore` in
`docs/conf.py`:
- `sonos.com`, `stackoverflow.com`, `superuser.com`,
`support.discogs.com` — return 403 to bots
- `forge.kanis.fr` — SSL certificate mismatch
- `id3.org` — intermittent 500 errors
These failures have been causing the docs linkcheck CI job to fail on
every run, unrelated to any code changes.
This PR improves how listens are matched to library items in the shared
`playcount` code used by the `listenbrainz` and `lastimport` plugins.
**Prefer an exact MBID match over title queries**
Previously, all matchers were simply OR'd together, so the preference
for MBID matches stated in the comments wasn't really applied. Instead,
listens with an MBID match could also update tracks with a different
MBID, just because they had a substring match on their title. For
example, a listen for "Song" would also update play counts for "Song
(inst.)", even though the library already contained "Song" with the
listen's exact MBID and the instrumental has a different one.
**Simplify matcher queries**
The query was previously written as `(title && artist) || (title &&
album)`, which is distributively the same as `title && (artist ||
album)`. Rewriting it clarifies the intent, where the title must match
and the artist or album confirms the match.
**Prefer exact title/artist/album matches over substring matches**
Try to match the exact title and artist/album first (case-insensitive
via `StringQuery`), only then fall back to the previous substring
matching.
This helps in cases where multiple variants of a song with distinct
listen counts exist, like "Song" and "Song (inst.)" or "Song (Japanese
ver.)". This commit stops "Song" from also updating those separate
variants if an exact match of "Song" exists.
Nonetheless, if the library only has an item named "Song (feat.
Artist)", "Song" will still update its play count through the substring
match.
Try to match the exact title and artist/album first (case-insensitive via StringQuery),
only then fall back to the previous substring matching.
This helps in cases where multiple variants of a song with distinct listen counts exist, like "Song" and "Song (inst.)" or "Song (Japanese ver.)".
This commit stops "Song" from also updating those separate variants if an exact match of "Song" exists.
Nonetheless, if the library only has an item named "Song (feat. Artist)", "Song" will still update its play count through the substring match.
The query was previously written as `(title && artist) || (title && album)`, which is distributively the same as `title && (artist || album)`.
Rewriting it clarifies the intent, where the title must match and the artist or album confirms the match.
Previously, all matchers were simply OR'd together, so the preference for MBID matches stated in the comments wasn't really applied.
Instead, listens with an MBID match could also update tracks with a different MBID, just because they had a substring match on their title.
For example, a listen for "Song" would also update play counts for "Song (inst.)", even though the library already contained "Song" with the listen's exact MBID and the instrumental has a different one.
Fixes#4057.
Deezer credits some compilations to a single "main" artist instead of
the Various Artists entity, so beets never flagged them as VA and ended
up dumping every track artist into the album artist field. This treats a
release as a compilation when its album artist only performs on a
minority of the tracks, in addition to the existing Various Artists id
check.
Added two tests for the deezer plugin (a compilation credited to a
single artist, and a normal single-artist album that should not be
flagged); both pass locally.
Fixes#166
When beets can't confidently match an album, the interactive import
prompt now offers a "Rescan directory" option alongside Skip/Use
as-is/etc. It re-reads the task's directories from disk and re-runs the
match, so files can be cleaned up (duplicates, junk) mid-import without
restarting the whole `beet import` run.
- New `Action.RESCAN` enum member (actions.py) and `set_choice` wiring
(tasks.py).
- New "r" `PromptChoice`, shown for album tasks with a toppath, added to
both the "no candidates" and "pick a candidate" prompt variants since
they share the same choice list (session.py).
- New `rescan_tasks()` generator and a `RESCAN` branch in the
`user_query` pipeline stage that re-extends the pipeline with
freshly-discovered tasks, mirroring the existing `TRACKS`/`ALBUMS`
branches (stages.py).
- Documents the new choice in the auto-tagger guide
(docs/guides/tagger.rst).
- Changelog entry.
## Design notes
Kept here rather than as long inline comments (per review feedback), so
the code stays readable.
**Discovery is delegated, not reimplemented.** Every group
`rescan_tasks` yields comes from `ImportTaskFactory.paths()` — the same
`albums_in_dir` / flat-mode / single-file logic the initial scan uses —
so the two can't disagree about what counts as an album. `rescan_tasks`
only decides *where* to re-walk and filters the results back down to
this task.
**Scope heuristic.** Re-walking the whole `toppath` is correct but
wasteful (rescanning one album in a large library shouldn't re-scan the
rest). When every directory in `task.paths` lives under `task.paths[0]`
(a plain album, or a nested multi-disc album whose disc dirs are
children of the album root), that subtree is the whole scope — walk it
directly, no filtering needed. Otherwise (flattened sibling discs with
no wrapping directory) walk one level up from `task.paths[0]` — the
shared parent — and keep only the groups still related to the original
directories, so an unrelated sibling album picked up by that same walk
is left alone.
**Emitted tasks keep the original `toppath`.** Discovery runs through a
factory scoped to the walk root, but the emitted tasks are built by a
second factory scoped to `task.toppath`. Using the rescanned directory
as `toppath` caused two regressions (found by @snejus, now covered by
tests): with `move=True`, pruning stops at `toppath`, so the emptied
source directory was left behind; with `resume=True`, progress is keyed
by `toppath`, so stale progress state was left behind.
**The choice is withheld, and re-guarded, for tasks with no directory
scope.** `_get_choices` only offers "Rescan directory" when
`task.toppath` is set and the task isn't a "Group albums" result (items
grouped by tag, not directory). `user_query` re-checks `not
task.is_album or task.toppath is None or task.is_grouped` before
entering `rescan_tasks`, because a plugin can force `choice_flag =
Action.RESCAN` via `import_task_choice`, bypassing the offered choices;
without the guard a singleton or query-produced task would be wrapped
back into a mismatched album-style task (or hit the `assert` in
`rescan_tasks`).
**The `r` shortcut** is now reserved by the default album-task prompt,
displacing any plugin-provided choice bound to the same letter. The
singleton-task prompt is unaffected, since Rescan is never offered
there.
## Known limitations
The rescan scope is reconstructed from `task.paths`, which can't fully
recover the original discovery grouping in a few layouts. These are
accepted for now (per [this
discussion](https://github.com/beetbox/beets/pull/6945#issuecomment-5526926259));
a rescan in these cases either re-prompts for something already handled
or splits an album, but never corrupts the library:
- **Flattened sibling discs at different depths** (one disc nested a
level deeper than its sibling): `task.paths[0]` isn't an ancestor of
every disc, so a shallower sibling can be dropped from the rescanned
album.
- **A loose album sharing a sibling-disc set's parent**
(`Artist/track.mp3` beside `Artist/Set Disc 1/` + `Artist/Set Disc 2/`):
rescanning the disc set walks `Artist` and the ancestor-match filter can
re-offer the already-imported loose album.
- **A pre-existing plain subdirectory** (e.g. a bonus-tracks folder)
inside a rescanned album's directory: the rescan rediscovers it while
its own original task is still pending, so it can be imported twice.
An earlier revision of this PR fixed all three (lowest-common-ancestor
scoping + a rescan-"generation" mechanism to drop superseded tasks) but
was judged too complex/verbose for the benefit; that history is on the
PR if it's wanted later.
## Example
Don McLean has multiple albums named "The Best of Don McLean". In this
case 2 of them were smashed together in the same directory.
```
/volume2/ConsolidatedMusic/Don McLean/The Best of Don McLean (29 items)
No matching release found for 29 tracks.
For help, see: https://beets.readthedocs.org/en/latest/faq.html#nomatch
➜ [S]kip, Use as-is, as Tracks, Group albums, Rescan directory,
Enter search, enter Id, aBort? r
/volume2/ConsolidatedMusic/Don McLean/The Best of Don McLean (20 items)
Match (93.1%):
Don McLean - The Best of Don McLean
≠ country, tracks, data source
MusicBrainz, CD, 1991, GB, EMI International, CDP 7983602, None
https://musicbrainz.org/release/4e620700-089d-4dbe-bd75-f3e0ab65fae9
* Artist: Don McLean
* Album: The Best of Don McLean
* (#1) American Pie (8:32)
* (#2) Castles in the Air (1981 version) (3:41)
* (#3) Dreidel (3:46)
* (#4) Winterwood (3:11)
* (#5) Everyday (2:26)
* (#6) Sister Fatima (2:33)
* (#7) Empty Chairs (3:26)
* (#8) The Birthday Song (2:37)
* (#9) Wonderful Baby (2:04)
* (#10) La La I Love You (3:46)
* (#11) Vincent (4:01)
* (#12) Crossroads (3:39)
* (#13) And I Love You So (4:16)
* (#14) Fools Paradise (4:05)
* (#15) If We Try (3:34)
* (#16) Mountains of Mourne (4:29)
* (#17) The Grave (3:12)
* (#18) Respectable (2:28)
* (#19) Going for the Gold (2:43)
* (#20) Crying (3:40)
```