Commit Graph

272 Commits

Author SHA1 Message Date
Šarūnas Nejus
0c227e9453 Define Library.path_formats property 2026-05-24 15:09:58 +01:00
Šarūnas Nejus
74021ee6b5 Define ConvertPlugin.get_item_destination to centralize the args 2026-05-24 15:09:58 +01:00
Sebastian Mohr
adfb73b66d Run ruff format 2026-05-20 16:53:06 +02:00
Šarūnas Nejus
30ab81eb5b Extract UserError from beets.ui to a new beets.exceptions module.
Update all references in core, plugins, and tests to import UserError
from the new location. This centralizes exception handling and improves
code organization.
2026-05-16 11:18:51 +01:00
Šarūnas Nejus
86813678d7 Use pipeline.mutator_stage instead of a Generator 2026-05-06 15:30:51 +01:00
Šarūnas Nejus
ec940e8b61 Remove redundant param provision to encode 2026-05-06 15:30:51 +01:00
Šarūnas Nejus
dd33fef52e Remove redundant param provision to should_transcode 2026-05-06 15:30:51 +01:00
Šarūnas Nejus
e574e86887 Replace get_format with command attribute 2026-05-06 15:30:51 +01:00
Šarūnas Nejus
34772d2684 Replace _get_opts_and_config with attributes 2026-05-06 15:30:50 +01:00
Šarūnas Nejus
ee895efd2d Handle opts using the config 2026-05-06 15:30:10 +01:00
Šarūnas Nejus
b15006ca11 Remove dependency on global config 2026-05-06 15:30:10 +01:00
Šarūnas Nejus
241eb6db09 Fix typing issues 2026-05-06 15:30:10 +01:00
Šarūnas Nejus
33efc2bd19 Add types 2026-05-06 15:30:10 +01:00
Šarūnas Nejus
a5a9775930 convert: generate playlist entries from effective output paths
Build playlist paths using the selected format (`--format`/config), and only
replace extensions when the destination file is actually transcoded.

Precompute playlist entries before conversion runs so `--keep-new` does not
pick up mutated item paths and produce mismatched extensions.

Add/expand convert CLI tests to cover:
- config format playlist extension
- `--format` override playlist extension
- no-transcode (`no_convert`) playlist extension
- `--keep-new` destination playlist path behavior
2026-03-04 15:38:33 +00:00
Šarūnas Nejus
c46f99a82b Merge branch 'master' into pr-fix-convert-ext 2026-03-04 15:22:40 +00:00
frigginbrownie
1ff254215a Update convert.py 2026-01-15 15:46:01 +00:00
Šarūnas Nejus
c52656fb0a Enable RUF rules 2026-01-13 20:55:40 +00:00
Guy Bloom
2bd77b9895 Fix convert --format with never_convert_lossy_files (#6171)
## Description

Fixes #5625 

When `convert.never_convert_lossy_files` is enabled, `beet convert` was
ignoring the explicit `--format` option and just copying the lossy files
without
transcoding them. For example:

- `beet convert format:mp3 --format opus`

would still produce MP3 files instead of OPUS.

Change:

- Allows to override options `never_convert_lossy_files`, `max_bitrate`
or `no_convert` for `beet convert` as well as trying to convert to the
same format as existing already with a new option `--force`. That way,
for example lossy files selected by the query are transcoded to the
requested format anyway.
- Keeps existing behavior for automatic conversion on import (no CLI
override there).
- Adds tests to cover checking whether `--force` correctly overrides
settings or CLI options.
- Documents the behavior in the convert plugin docs

Co-authored-by: J0J0 Todos <jojo@peek-a-boo.at>
2025-12-03 22:48:41 +01:00
Finn
61b632f2b4 Add option to not write metadata 2025-09-24 21:52:57 -04:00
Sebastian Mohr
a796d6d799 New import location for art.py 2025-09-20 14:01:38 +02:00
Šarūnas Nejus
b3d434f58f Delegate attribute access to logging 2025-08-30 23:10:21 +01:00
Šarūnas Nejus
e334e81d40 Use item.filepath instead of displayable_path in logging 2025-08-30 23:10:21 +01:00
Šarūnas Nejus
d93ddf8dd4 Do not use explicit indices for logging args when not needed 2025-08-30 23:10:21 +01:00
Šarūnas Nejus
2fccf64efe Do not use backslashes to deal with long strings 2025-08-30 23:10:20 +01:00
Šarūnas Nejus
1c16b2b308 Replace string concatenation (' + ')
- Join hardcoded strings
- Replace concatenated variables with f-strings
2025-08-30 23:10:15 +01:00
Šarūnas Nejus
4a361bd501 Replace format calls with f-strings 2025-08-30 18:42:26 +01:00
Šarūnas Nejus
7cada1c9f8 Remove no-op decargs 2025-07-08 11:37:33 +01:00
Pierre Ayoub
f0c2c8e649 chore(beetsplug/convert): ruff format 2025-05-14 10:12:38 +02:00
Pierre Ayoub
dad1b2e4e1 Revert "Add some assertion for input of replace_ext()"
This reverts commit 52b639b4ee95736bb128876a8e4bd6a7046b06a6.
2025-05-14 09:37:52 +02:00
Pierre Ayoub
ddddddfdb3 Add some assertion for input of replace_ext() 2025-05-14 09:36:36 +02:00
Pierre Ayoub
e3e47618f9 Fix extension substitution inside path of the exported playlist
Before this, the exported playlist contained relative paths pointing to the
converted files BUT the extension were not substituted comparing to before and
the after the conversion. Therefore, running the playlist will fail for files
which have been converted and where extension have changed.
2025-05-14 09:36:34 +02:00
Šarūnas Nejus
52951bf719 Fix legalize_path types
Background
  The `_legalize_stage` function was causing issues with Mypy due to
  inconsistent type usage between the `path` and `extension` parameters.
  This inconsistency stemmed from the `fragment` parameter influencing the
  types of these variables.

Key issues
  1. `path` was defined as `str`, while `extension` was `bytes`.
  2. Depending on `fragment`, `extension` could be either `str` or `bytes`.
  3. `path` was sometimes converted to `bytes` within `_legalize_stage`.

Item.destination` method
  - The `fragment` parameter determined the output format:
    - `False`: Returned absolute path as bytes (default)
    - `True`: Returned path relative to library directory as str

Thus
  - Rename `fragment` parameter to `relative_to_libdir` for clarity
  - Ensure `Item.destination` returns `bytes` in all cases
  - Code expecting strings now converts the output to `str`
  - Use only `str` type in `_legalize_stage` and `_legalize_path`
    functions
  - These functions are no longer dependent on `relative_to_libdir`
2025-05-04 12:23:22 +01:00
Šarūnas Nejus
9acfa3c175 Remove arg_encoding 2025-04-21 12:41:57 +01:00
Pierre Ayoub
5c8f1c1ee5 Fix convert plugin attempting to process a non-media file (#5261)
## Description

My library is managed using Beets for organization and
[git-annex](https://git-annex.branchable.com/) as storage backend.
Therefore when using this system, while my library files always exists
on my filesystem, some files may be empty (without content). In this
case, when I'm running the `convert` plugin, I don't wants it to process
files which are empty (same apply for any Beets plugin). Hence, I added
a check that the file is readable as a `MediaFile` before doing any
process.

Before this fix, trying to encode an empty file would have lead to an
error while leaving `convert` doing its side-effects **and** `convert`
would also copy empty files to destination for files that doesn't need
to be re-encoded.

In my case, this is empty files, but the problem can be anything else
(depending on the storage backend) and/or corrupted files. Conclusion, I
think **checking that the file is readable is always recommended before
proceeding to heavy operation** like this.
2025-02-20 16:23:14 +00:00
Šarūnas Nejus
69dbfd9868 Fix lints
These seem to have managed to escape the CI checks since the previously
merged PR was based on master commit which did not include the checks.
2024-10-30 12:13:30 +00:00
Joseph Bushell
4b78abd939 create seperate in_no_convert function, update tests 2024-10-26 19:09:56 +01:00
Joseph Bushell
d1c88bbd25 consider value of no_convert as one query rather than splitting 2024-10-26 18:17:00 +01:00
Šarūnas Nejus
f36bc497c8 Fix lint issues
- Fix imports
- Fix pytest issues
- Do not assign lambda as variable
- Use isinstance instead of type to check type
- Rename ambiguously named variables
- Name custom errors with Error suffix
2024-09-21 11:59:18 +01:00
Šarūnas Nejus
85a17ee503 Reformat the codebase 2024-09-21 11:57:48 +01:00
Šarūnas Nejus
19470f3d76 Use native os.cpu_count
os.cpu_count has only been available since Python 3.4
2024-06-16 00:52:38 +01:00
Šarūnas Nejus
f388ff6ec1 Replace py3_path with builtin os.fsdecode
`os.fsdecode` has only been available since Python 3.2.
2024-06-16 00:52:37 +01:00
Boris-Chengbiao Zhou
47ba590999 convert: Correctly identify WAVE format as lossless
Seems like this entry was added before mediafile gained support for WAVE
files in commit 832f3d. Adjust it to fix detection.
2024-03-01 17:58:26 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
wisp3rwind
29c21860a9 add missing syspath conversions (2/3, beetsplug) 2023-07-16 10:17:40 +02:00
J0J0 Todos
0d8f8a3cff Fix ValueError in convert plugin auto_convert_keep 2023-06-22 09:13:09 +02:00
J0J0 Todos
86929eb6a0 convert: playlist: Adapt code comments
- Remove initial comment around playlist entry condition (which is better
  suited for user docs anyway, and stated there already)
- Add explanation above the items_paths playlist contents creation list
  comprehension.
2023-04-02 19:34:13 +02:00
J0J0 Todos
16e361baf3 convert: playlist: item_paths relative to playlist
Ensure entries in items_paths are generated with a path relative to the
location of the playlist file.
2023-04-02 13:10:14 +02:00
J0J0 Todos
a4d03ef586 convert: playlist: M3U write + contents as bytes
Make sure we stay with the beets standard of handling everything internally as
bytes.

- M3UFile.write() method writes in wb mode.
- Playlist contents and EXTM3U header is handled as bytes.
  - item.destination() gives us unicode string paths, we tranlate to bytes
    using util.bytestring_path().
- Fix test_playlist*write* tests to encode UTF-8 assert strings as bytes using
  bytestring_path() before comparision.
2023-03-29 07:46:08 +02:00
J0J0 Todos
20a0012f79 convert: playlist: Use normpath for playlist file
Fixes FileNotFoundError when for example a tilde (~) characteris used for a
--dest path.
2023-03-29 07:46:08 +02:00
J0J0 T
d248063f96 convert: playlist: Improve --playlist help text 2023-03-29 07:46:08 +02:00