Skip to content

Commit

Permalink
Support beets v2.x and require v1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
geigerzaehler committed Jul 11, 2024
1 parent 362ceb2 commit 33e7190
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 196 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

steps:
- run: sudo apt-get install flac mp3val oggz-tools
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pip install poetry
- uses: actions/setup-python@v3
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry
Expand All @@ -29,21 +29,23 @@ jobs:
- run: poetry run flake8
- run: poetry run pytest

build-beets-master:
build-beets-versions:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
beets:
- "git+https://github.com/beetbox/beets#master"
- "beets==1.6.1"

steps:
- run: sudo apt-get install flac mp3val oggz-tools
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pip install poetry
- uses: actions/setup-python@v3
- uses: actions/setup-python@v5
with:
python-version: 3.8
cache: poetry
- run: poetry env use $(which python)
- run: poetry install
# We cannot use `poetry add` because poetry does not install beets
# dependencies properly
- run: poetry run pip install "git+https://github.com/beetbox/beets#master"
- run: poetry add ${{ matrix.beets }}
- run: poetry run pytest
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Upcoming

- Require beets >=1.6.1 and support beets v2.x

## v0.14.0 2024-02-12

- Require Python ^3.8
Expand Down
88 changes: 37 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
beets-check
===========
# beets-check

[![Build Status](https://travis-ci.org/geigerzaehler/beets-check.svg?branch=master)](https://travis-ci.org/geigerzaehler/beets-check)
[![Coverage Status](https://coveralls.io/repos/geigerzaehler/beets-check/badge.png?branch=master)](https://coveralls.io/r/geigerzaehler/beets-check?branch=master)

*The [beets][] plugin for paranoid obsessive-compulsive music geeks.*
_The [beets][] plugin for paranoid obsessive-compulsive music geeks._

*beets-check* lets you verify the integrity of your audio files. It computes
_beets-check_ lets you verify the integrity of your audio files. It computes
and validates file checksums and uses third party tools to run custom
tests on files.

This plugin requires at least version 1.6.0 of beets and at least Python 3.8
This plugin requires at least version 1.6.1 of beets and at least Python 3.8

```
pip install --upgrade beets>=1.6.0
pip install --upgrade beets>=1.6.1
pip install git+git://github.com/geigerzaehler/beets-check.git@main
```

Expand All @@ -24,9 +24,7 @@ to manually install them on your system. Run `beet check --list-tools`
to see a list of programs the plugin can use or [add your
own](#third-party-tests).


Usage
-----
## Usage

Let’s get started and add some checksums to your library.

Expand All @@ -38,7 +36,7 @@ Adding unknown checksums: 1032/8337 [12%]

The `check` command looks for all files that don’t have a checksum yet.
It computes the checksum for each of these files and stores it in the
database. The command also prints a warning if one of the third-party
database. The command also prints a warning if one of the third-party
tools finds an error. (More on those [later](#third-party-tests).)

After some time (or maybe a system crash) you’ll probably want to go back to
Expand All @@ -50,7 +48,7 @@ FAILED: /music/Sgt. Pepper/13 A Day in the Life.mp3
Verifying checksums: 5102/8337 [53%]
```

For later inspection you might want to keep a log. To do that just
For later inspection you might want to keep a log. To do that just
redirect the error output with `beet check 2>check.log`. All `WARNING`
and `ERROR` lines are sent to stderr, so you will still see the
progressbar.
Expand All @@ -59,6 +57,7 @@ When you change your files through beets, using the `modfiy` command
for example, the plugin will [update the checksums
automatically](#automatic-update). However, if you change files
manually, you also need to update the checksums manually.

```
$ beet check -u 'album:Sgt. Pepper'
Updating checksums: 2/13 [15%]
Expand All @@ -72,25 +71,26 @@ the box, but you can also [configure your own](#third-party-tools).

Custom tests are run when on the following occasions.

* Before importing a file (see below)
* Before adding checksums with the `-a` flag
* When running `beet check --external`
- Before importing a file (see below)
- Before adding checksums with the `-a` flag
- When running `beet check --external`

The file checks are not run when updating files. The rationale is that
if the checksum of a file is correct, the file is assumed to be clean
and pass all the custom tests.

If some file fails a test the line
If some file fails a test the line

```
WARNING error description: /path/to/file
```
is printed.

is printed.

### Usage with `import`

Since it would be tedious to run `check -a` every time you import new music
into beets, *beets-check* will add checksum automatically. Before file
into beets, _beets-check_ will add checksum automatically. Before file
is imported the plugin will also check the file with the provided
third-party tools. If the check fails beets will ask you to confirm the
import.
Expand All @@ -109,18 +109,17 @@ Do you want to skip this album? (Y/n)

After a track has been added to the database and all modifications to the tags
have been written, beets-check adds the checksums. This is virtually the same as
running ``beets check -a `` after the import.
running `beets check -a ` after the import.

If you run `import` with the `--quiet` flag the importer will skip
files that do not pass third-party tests automatically and log an
error.


### Automatic Update

The [`write`][write] and [`modify`][modify] commands as well as some plugins will
change a file’s content and thus invalidate its checksum. To relieve you from
updating the checksum manually, *beets-check* will recalculate the checksums of
updating the checksum manually, _beets-check_ will recalculate the checksums of
all the files that were changed.

```
Expand All @@ -137,36 +136,30 @@ This is basically equivalent to running `beets check -u QUERY` after a modifying
command.

To make sure that a file hasn’t changed before beets changes it, the
plugin will verify the checksum before the file is written. If the
plugin will verify the checksum before the file is written. If the
check fails, beets will not write the file and issue a warning.


```
$ beet modify 'artist=The Beatles' 'title:A Day in the Life'
could not write /music/life.mp3: checksum did not match value in library
```


### Usage with `convert`

The [`convert`][convert] plugin can replace an audio file with a
transcoded version using the `--keep-new` flag. This will invalidate you
checksum, but *beets-check* knows about this and will update the
checksum, but _beets-check_ knows about this and will update the
checksum automatically. You can disable this behaviour in the plugin
configuration. Note that, at the moment we do not verify the checksum
prior to the conversion, so a corrupted file might go undetected. This
feature is also only available with the master branch of beets


[beets]: http://beets.readthedocs.org/en/latest
[write]: http://beets.readthedocs.org/en/latest/reference/cli.html#write
[modify]: http://beets.readthedocs.org/en/latest/reference/cli.html#modify
[convert]: http://beets.readthedocs.org/en/latest/plugins/convert.html



CLI Reference
-------------
## CLI Reference

```
beet check [--quiet]
Expand All @@ -182,7 +175,7 @@ beet check --list-tools
The plugin has subcommands for checking files, running integrity checks,
adding, updating and exporting checksums and listing third-party tools. All but
the last accepty a `QUERY` paramter that will restrict the operation to files
matching the query. Remember, if a query contains a slash beets will
matching the query. Remember, if a query contains a slash beets will
[interpret it as a path][path query] and match all files that are contained in
a subdirectory of that path.

Expand Down Expand Up @@ -225,22 +218,18 @@ In addition, the commands print a progress indicator to `stdout` if
confirm the fixes. This can be disabled with the `--force` flag.

- **`-l, --list-tools`** Outputs a list of third party programs that
*beets-check* uses to verify file integrity and shows whether they are
_beets-check_ uses to verify file integrity and shows whether they are
installed. The plugin comes with support for the
[`oggz-validate`][oggz-validate], [`mp3val`][mp3val] and [`flac`][flac] commands.


[path query]: http://beets.readthedocs.org/en/latest/reference/query.html#path-queries
[flac]: https://xiph.org/flac/documentation_tools_flac.html
[mp3val]: http://mp3val.sourceforge.net/
[oggz-validate]: https://www.xiph.org/oggz/

## Configuration


Configuration
-------------

By default *beets-check* uses the following configuration.
By default _beets-check_ uses the following configuration.

```yaml
check:
Expand All @@ -251,23 +240,23 @@ check:
threads: num_of_cpus
```
These option control at which point *beets-check* will be used automatically by
These option control at which point _beets-check_ will be used automatically by
other beets commands. You can disable each option by setting its value to `no`.

* `import: no` Don’t add checksums for new files during the import process.
- `import: no` Don’t add checksums for new files during the import process.
This also disables integrity checks on import and will not ask you to skip
the import of corrupted files.
* `write-check: no` Don’t verify checksums before writing files with
- `write-check: no` Don’t verify checksums before writing files with
`beet write` or `beet modify`.
* `write-update: no` Don’t update checksums after writing files with
- `write-update: no` Don’t update checksums after writing files with
`beet write` or `beet modify`.
* `convert-update: no` Don’t updated the checksum if a file has been
- `convert-update: no` Don’t updated the checksum if a file has been
converted with the `--keep-new` flag.
* `threads: 4` Use four threads to compute checksums.
- `threads: 4` Use four threads to compute checksums.

### Third-party Tools

*beets-check* allows you to configure custom tests for your files.
_beets-check_ allows you to configure custom tests for your files.

Custom tests are shell commands that are run on an audio file and
may produce an error.
Expand All @@ -276,10 +265,10 @@ may produce an error.
check:
tools:
mp3val:
cmd: 'mp3val {}'
cmd: "mp3val {}"
formats: MP3
error: '^WARNING: .* \(offset 0x[0-9a-f]+\): (.*)$'
fix: 'mp3val -f -nb {}'
fix: "mp3val -f -nb {}"
```

Each tool is a dictionary entry under `check.tools`, where the key is
Expand Down Expand Up @@ -308,12 +297,9 @@ following two cases.

- The shell command exits with a non-zero status code.

[python-format]: https://docs.python.org/2/library/string.html#format-string-syntax

[python-format]:https://docs.python.org/2/library/string.html#format-string-syntax


License
-------
## License

Copyright (c) 2014 Thomas Scholtes

Expand Down
9 changes: 4 additions & 5 deletions beetsplug/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def verify_integrity(item):


class ChecksumError(ReadError):
pass
def __str__(self):
return f"error reading {displayable_path(self.path)}: {self.reason}"


class CheckPlugin(BeetsPlugin):

def __init__(self):
super(CheckPlugin, self).__init__()
self.config.add(
Expand Down Expand Up @@ -160,7 +160,6 @@ def verify_import_integrity(self, session, task):


class CheckCommand(Subcommand):

def __init__(self, config):
self.threads = config["threads"].get(int)
self.check_integrity = config["integrity"].get(bool)
Expand Down Expand Up @@ -470,11 +469,11 @@ def execute_with_progress(self, func, args, msg=None):


class IntegrityError(ReadError):
pass
def __str__(self):
return f"error reading {displayable_path(self.path)}: {self.reason}"


class IntegrityChecker(object):

@classmethod
def all(cls):
if hasattr(cls, "_all"):
Expand Down
Loading

0 comments on commit 33e7190

Please sign in to comment.