No description
Find a file
Šarūnas Nejus c56cb69e32
fix: enable tracebacks for "user"/custom sqlite functions (#5383)
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
```
2025-09-19 21:16:38 +01:00
.github Add CODEOWNERS file to assign the entire repo to @maintainers 2025-09-06 17:43:15 +01:00
beets feat: mark SQLite custom functions as deterministic to allow caching 2025-09-19 21:11:51 +01:00
beetsplug Removed config options and fixed a bug with beet spotify command 2025-09-19 17:20:51 +02:00
docs Removed config options and fixed a bug with beet spotify command 2025-09-19 17:20:51 +02:00
extra Update release conversion logic accordingly 2025-08-10 16:25:05 +01:00
test style: remove extraneous pass statements 2025-09-19 21:11:51 +01:00
.git-blame-ignore-revs Updated git blame hashes yet again :) 2025-09-04 16:07:25 +02:00
.gitignore Utilize new way of declaring a NamedTuple 2024-08-25 16:26:19 +02:00
.pre-commit-config.yaml Configure docstrfmt 2025-08-10 16:25:04 +01:00
.readthedocs.yaml Fix path typo 2023-09-22 15:29:39 -04:00
CODE_OF_CONDUCT.rst Reformat all docs using docstrfmt 2025-08-10 16:25:05 +01:00
codecov.yml Make cov setup a bit more useful and upgrade cov upload action 2025-08-09 15:11:59 +01:00
CONTRIBUTING.rst Add a note about ownership 2025-09-06 17:43:16 +01:00
LICENSE Update copyright dates to 2016 2015-12-30 15:42:06 +00:00
poetry.lock Capitalization and some more minor adjustments. Updated docstrfmt. 2025-09-04 12:49:46 +01:00
pyproject.toml Increment version to 2.4.0 2025-09-13 16:47:21 +00:00
README.rst Replace flowery language (#6002) 2025-09-15 09:02:22 +00:00
README_kr.rst Reformat all docs using docstrfmt 2025-08-10 16:25:05 +01:00
SECURITY.md Create security policy 2021-12-22 09:34:41 -08:00
setup.cfg Upload test results to codecov 2025-08-09 15:27:17 +01:00

.. image:: https://img.shields.io/pypi/v/beets.svg
    :target: https://pypi.python.org/pypi/beets

.. image:: https://img.shields.io/codecov/c/github/beetbox/beets.svg
    :target: https://codecov.io/github/beetbox/beets

.. image:: https://img.shields.io/github/actions/workflow/status/beetbox/beets/ci.yaml
    :target: https://github.com/beetbox/beets/actions

.. image:: https://repology.org/badge/tiny-repos/beets.svg
    :target: https://repology.org/project/beets/versions

beets
=====

Beets is the media library management system for obsessive music geeks.

The purpose of beets is to get your music collection right once and for all. It
catalogs your collection, automatically improving its metadata as it goes. It
then provides a suite of tools for manipulating and accessing your music.

Here's an example of beets' brainy tag corrector doing its thing:

::

    $ beet import ~/music/ladytron
    Tagging:
        Ladytron - Witching Hour
    (Similarity: 98.4%)
     * Last One Standing      -> The Last One Standing
     * Beauty                 -> Beauty*2
     * White Light Generation -> Whitelightgenerator
     * All the Way            -> All the Way...

Because beets is designed as a library, it can do almost anything you can
imagine for your music collection. Via plugins_, beets becomes a panacea:

- Fetch or calculate all the metadata you could possibly need: `album art`_,
  lyrics_, genres_, tempos_, ReplayGain_ levels, or `acoustic fingerprints`_.
- Get metadata from MusicBrainz_, Discogs_, and Beatport_. Or guess metadata
  using songs' filenames or their acoustic fingerprints.
- `Transcode audio`_ to any format you like.
- Check your library for `duplicate tracks and albums`_ or for `albums that are
  missing tracks`_.
- Clean up crufty tags left behind by other, less-awesome tools.
- Embed and extract album art from files' metadata.
- Browse your music library graphically through a Web browser and play it in any
  browser that supports `HTML5 Audio`_.
- Analyze music files' metadata from the command line.
- Listen to your library with a music player that speaks the MPD_ protocol and
  works with a staggering variety of interfaces.

If beets doesn't do what you want yet, `writing your own plugin`_ is shockingly
simple if you know a little Python.

.. _acoustic fingerprints: https://beets.readthedocs.org/page/plugins/chroma.html

.. _album art: https://beets.readthedocs.org/page/plugins/fetchart.html

.. _albums that are missing tracks: https://beets.readthedocs.org/page/plugins/missing.html

.. _beatport: https://www.beatport.com

.. _discogs: https://www.discogs.com/

.. _duplicate tracks and albums: https://beets.readthedocs.org/page/plugins/duplicates.html

.. _genres: https://beets.readthedocs.org/page/plugins/lastgenre.html

.. _html5 audio: https://html.spec.whatwg.org/multipage/media.html#the-audio-element

.. _lyrics: https://beets.readthedocs.org/page/plugins/lyrics.html

.. _mpd: https://www.musicpd.org/

.. _musicbrainz: https://musicbrainz.org/

.. _musicbrainz music collection: https://musicbrainz.org/doc/Collections/

.. _plugins: https://beets.readthedocs.org/page/plugins/

.. _replaygain: https://beets.readthedocs.org/page/plugins/replaygain.html

.. _tempos: https://beets.readthedocs.org/page/plugins/acousticbrainz.html

.. _transcode audio: https://beets.readthedocs.org/page/plugins/convert.html

.. _writing your own plugin: https://beets.readthedocs.org/page/dev/plugins.html

Install
-------

You can install beets by typing ``pip install beets`` or directly from Github
(see details here_). Beets has also been packaged in the `software
repositories`_ of several distributions. Check out the `Getting Started`_ guide
for more information.

.. _getting started: https://beets.readthedocs.org/page/guides/main.html

.. _here: https://beets.readthedocs.io/en/latest/faq.html#run-the-latest-source-version-of-beets

.. _software repositories: https://repology.org/project/beets/versions

Contribute
----------

Thank you for considering contributing to ``beets``! Whether you're a programmer
or not, you should be able to find all the info you need at CONTRIBUTING.rst_.

.. _contributing.rst: https://github.com/beetbox/beets/blob/master/CONTRIBUTING.rst

Read More
---------

Learn more about beets at `its Web site`_. Follow `@b33ts`_ on Mastodon for news
and updates.

.. _@b33ts: https://fosstodon.org/@beets

.. _its web site: https://beets.io/

Contact
-------

- Encountered a bug you'd like to report? Check out our `issue tracker`_!

  - If your issue hasn't already been reported, please `open a new ticket`_ and
    we'll be in touch with you shortly.
  - If you'd like to vote on a feature/bug, simply give a :+1: on issues you'd
    like to see prioritized over others.
  - Need help/support, would like to start a discussion, have an idea for a new
    feature, or would just like to introduce yourself to the team? Check out
    `GitHub Discussions`_!

.. _github discussions: https://github.com/beetbox/beets/discussions

.. _issue tracker: https://github.com/beetbox/beets/issues

.. _open a new ticket: https://github.com/beetbox/beets/issues/new/choose

Authors
-------

Beets is by `Adrian Sampson`_ with a supporting cast of thousands.

.. _adrian sampson: https://www.cs.cornell.edu/~asampson/