Introduce a `--pretend` option to the lastgenre plugin, allowing users
to preview genre changes without making any modifications to their
library. This feature enhances user control by showing potential changes
before they are applied.
A bit niche but I tried setting my bareasc prefix to an empty string,
and was getting an obtuse error. This should help make clearer what is
happening when queries fail.
The exception is not properly raised up the stack in the first place
because it happens across 2 FFI boundaries: the DB query
(Python -> SQLite), and the custom DB function (SQLite -> Python).
Thus Python cannot forwarded it back to itself through SQLite, and it's
treated as an "unraisable" exception.
We could override `sys.unraisablehook` to not print anything for the
original exception, and store it in a global for the outer Python
interpreter to fetch and raise properly, but that's pretty hacky,
limited to a single DB instance and query at once, and risks swallowing
other "unraisable" exceptions.
Instead we just tell the user to look above for what Python prints.
Sample output:
```
Exception ignored in: <function unidecode_expect_ascii at 0x7f7fa20bb060>
Traceback (most recent call last):
File "site-packages/unidecode/__init__.py", line 60, in unidecode_expect_ascii
bytestring = string.encode('ASCII')
^^^^^^^^^^^^^
AttributeError: 'bytes' object has no attribute 'encode'
Traceback (most recent call last):
File "site-packages/beets/dbcore/db.py", line 988, in query
cursor = self.db._connection().execute(statement, subvals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: user-defined function raised exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages/beets/__main__.py", line 9, in <module>
sys.exit(main())
^^^^^^
File "site-packages/beets/ui/__init__.py", line 1865, in main
_raw_main(args)
File "site-packages/beets/ui/__init__.py", line 1852, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "site-packages/beets/ui/commands.py", line 1599, in list_func
list_items(lib, decargs(args), opts.album)
File "site-packages/beets/ui/commands.py", line 1594, in list_items
for item in lib.items(query):
^^^^^^^^^^^^^^^^
File "site-packages/beets/library.py", line 1695, in items
return self._fetch(Item, query, sort or self.get_default_item_sort())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/library.py", line 1673, in _fetch
return super()._fetch(model_cls, query, sort)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/dbcore/db.py", line 1301, in _fetch
rows = tx.query(sql, subvals)
^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/dbcore/db.py", line 991, in query
raise DBCustomFunctionError()
beets.dbcore.db.DBCustomFunctionError: beets defined custom SQLite function failed; see the other errors above for details
```
A bit niche but I tried setting my bareasc prefix to an empty string,
and was getting an obtuse error. This should help make clearer what is
happening when queries fail.
The exception is not properly raised up the stack in the first place
because it happens across 2 FFI boundaries: the DB query
(Python -> SQLite), and the custom DB function (SQLite -> Python).
Thus Python cannot forwarded it back to itself through SQLite, and it's
treated as an "unraisable" exception.
We could override `sys.unraisablehook` to not print anything for the
original exception, and store it in a global for the outer Python
interpreter to fetch and raise properly, but that's pretty hacky,
limited to a single DB instance and query at once, and risks swallowing
other "unraisable" exceptions.
Instead we just tell the user to look above for what Python prints.
Sample output:
```
Exception ignored in: <function unidecode_expect_ascii at
0x7f7fa20bb060>
Traceback (most recent call last):
File "site-packages/unidecode/__init__.py", line 60, in
unidecode_expect_ascii
bytestring = string.encode('ASCII')
^^^^^^^^^^^^^
AttributeError: 'bytes' object has no attribute 'encode'
Traceback (most recent call last):
File "site-packages/beets/dbcore/db.py", line 988, in query
cursor = self.db._connection().execute(statement, subvals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: user-defined function raised exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages/beets/__main__.py", line 9, in <module>
sys.exit(main())
^^^^^^
File "site-packages/beets/ui/__init__.py", line 1865, in main
_raw_main(args)
File "site-packages/beets/ui/__init__.py", line 1852, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "site-packages/beets/ui/commands.py", line 1599, in list_func
list_items(lib, decargs(args), opts.album)
File "site-packages/beets/ui/commands.py", line 1594, in list_items
for item in lib.items(query):
^^^^^^^^^^^^^^^^
File "site-packages/beets/library.py", line 1695, in items
return self._fetch(Item, query, sort or
self.get_default_item_sort())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/library.py", line 1673, in _fetch
return super()._fetch(model_cls, query, sort)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/dbcore/db.py", line 1301, in _fetch
rows = tx.query(sql, subvals)
^^^^^^^^^^^^^^^^^^^^^^
File "site-packages/beets/dbcore/db.py", line 991, in query
raise DBCustomFunctionError()
beets.dbcore.db.DBCustomFunctionError: beets defined SQLite function
failed; see the other errors above for details
```
Only include non-empty artist and album filters in Spotify track
search and metadata candidate queries to prevent incorrect matches when
the album field is missing or empty.
closes#5189
Prevents this crash:
```
$ beet import ~/Music/Music/_/[1405]/00.mp3
Traceback (most recent call last):
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/bin/.beet-wrapped", line 9, in <module>
sys.exit(main())
~~~~^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/__init__.py", line 1859, in main
_raw_main(args)
~~~~~~~~~^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/__init__.py", line 1838, in _raw_main
subcommand.func(lib, suboptions, subargs)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/commands.py", line 1390, in import_func
import_files(lib, byte_paths, query)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/commands.py", line 1330, in import_files
session.run()
~~~~~~~~~~~^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/importer/session.py", line 234, in run
pl.run_parallel(QUEUE_SIZE)
~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 471, in run_parallel
raise exc_info[1].with_traceback(exc_info[2])
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 336, in run
out = self.coro.send(msg)
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 219, in coro
func(*(args + (task,)))
~~~~^^^^^^^^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/importer/stages.py", line 141, in lookup_candidates
plugins.send("import_task_start", session=session, task=task)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/plugins.py", line 505, in send
result = handler(**arguments)
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/plugins.py", line 200, in wrapper
return func(*args, **kwargs)
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beetsplug/fromfilename.py", line 165, in filename_task
apply_matches(d, self._log)
~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beetsplug/fromfilename.py", line 124, in apply_matches
item.title = str(d[item][title_field])
~~~~~~~^^^^^^^^^^^^^
KeyError: 'title'
```
Simplify wording by replacing flowery or pretentious terms throughout the project.
A bouquet refers to trees or flowers. The etymology is pretty clear on
the Latin root via French.
Co-authored-by: Sebastian Mohr <sebastian@mohrenclan.de>
- Switch default `text_diff_added` color from bold **red** to bold
**green**; unify all diff/case comparisons to use `text_diff_added` and
`text_diff_removed` colors consistently.
- Simplify color handling and setup: introduce cached color config
(validation + legacy normalization), consolidate regexes
- Remove unused colors names
- Update `ui` configuration docs.
### `beet write -p year:2000..2005`
#### Before
<img width="1261" height="460" alt="image"
src="https://github.com/user-attachments/assets/70207350-6d9a-48d8-a314-457ac07c5ad1"
/>
#### After
<img width="1257" height="536" alt="image"
src="https://github.com/user-attachments/assets/efcf3453-016a-490f-84ab-dedfb2aca97b"
/>
### `beet move -p albumtype:broadcast`
#### Before
<img width="1103" height="505" alt="image"
src="https://github.com/user-attachments/assets/9e76c5d6-d878-4535-9da3-a949e6c0830c"
/>
#### After
<img width="1134" height="508" alt="image"
src="https://github.com/user-attachments/assets/3dc03988-8011-4072-8840-6f0a0d12350f"
/>
## Summary by Sourcery
Improve default diff colors from red to green and streamline color
handling by refactoring ANSI code management, removing legacy logic, and
unifying diff highlighting. Also extract a cached changed_prefix
property and update UI config documentation.
Enhancements:
- Introduce cached get_color_config and consolidate ANSI escape regex
patterns to simplify color configuration parsing
- Refactor diff highlighting to consistently use text_diff_added and
text_diff_removed and simplify _colordiff implementation
- Add ChangeRepresentation.changed_prefix cached property for consistent
‘not equal’ prefix formatting
Documentation:
- Update UI configuration documentation to reflect new default colors
and removed settings
Chores:
- Remove unused color names and legacy normalization code
Addresses some fixes and additions mentioned here #5915 and some I
collected myself over the years.
Of course genres and sub-genres classifications always are rather
opinionated, but I consider them useful for others too. Critical
feedback is welcome.
experimental, even though a tag last.fm very often returns (in top 20
tag charts!), it is too broad of a term to be pinned downed with any
particular genre, thus can't really be used for canonicalization.