Commit graph

249 commits

Author SHA1 Message Date
Sebastian Mohr
34114fe915 New import location for art.py 2025-09-21 08:01:48 -07: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
Š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
J0J0 T
cb630c45f6 convert: playlist: Also use syspath() for contents
of playlist. We want to have processed every entry in the media list we
pass to the M3UFile instance.
2023-03-29 07:46:08 +02:00
J0J0 T
7d121c390b convert: playlist: Move M3UFile class to separate
module in util package.
2023-03-29 07:46:08 +02:00
J0J0 T
55b386375a convert: playlist: Move m3u creation after conversions
- Move the creation of the playlist file to the very end, right after
  self._parallel_convert, in the convert plugin's main function.
- In the test code, the destination directory is created when the
  conversion happens, thus this fixes test_playlist and doesn't hurt the
  feature - The playlist creation can as well be the very last step in
  the process.
2023-03-29 07:21:27 +02:00
J0J0 T
5dfff50005 convert: playlist: Refactor m3u writing to class
and also implement a currently untested load() method.
2023-03-29 07:21:27 +02:00
J0J0 T
c251ed19c4 convert: playlist: Generate m3u file in one batch
to avoid any possible interference with the threaded file conversion
mechanism.
2023-03-29 07:21:27 +02:00
J0J0 T
d589e77ade convert: playlist: Fix redundant join path
It's done in _get_opts_and_config already.
2023-03-29 07:21:27 +02:00
J0J0 T
c0b1bc9867 convert: playlist feature: Better relative path gen
Use Item.destination method for generation of relative paths to media
files in playlist. The fragment keyword enables returning the path as
unicode instead of bytes, let's keep that in mind.
2023-03-29 07:21:27 +02:00
J0J0 T
16e25bb61b convert: playlist feature: Fix relative paths
pointing to media files in playlist. Also refine code comment and move
to a better fitting place.
2023-03-29 07:21:27 +02:00
J0J0 T
fd8fe69738 convert: Playlist feature linting fixes 2023-03-29 07:21:27 +02:00
J0J0 T
d448e0c4de convert: Refine and fix playlist feature
- Improve --help text
- Use unicode instead of bytes when adding media file paths to the
  playlist file.
- The "standard" (?) of m3u8 defines that unicode should ensure support
  of special characters in media file names. util.displayable_path() is
  used to do the conversion from bytes. We save everything in bytes in
  the config since it seemes to be the way this plugin or beets in
  general likes to save paths.
- Join dest and playlist in the config reader method already to have it
  ready in both methods that require the full path to the playlist file.
2023-03-29 07:21:27 +02:00
J0J0 T
861bc69df5 convert: Add a quick & dirty m3u playlist feature 2023-03-29 07:21:27 +02:00
Aidan Epstein
c906e55ba9 Fix recent bug that would not transcode when format was wrong
Bug introduced in c6d623241b, should_transcode would return False even when the format was different.

Also fix up tests and documentation.
2022-10-19 08:55:51 -07:00
Adrian Sampson
1ebcbf6944
Merge branch 'master' into fix_max_bitrate_default 2022-10-03 11:02:07 -07:00
Adrian Sampson
82d41446a2
Use fsdecode for template substitution
The idea in this PR is to converge on Python's `fsdecode` and `fsencode`
for argument manipulation. This seems to match up with the Python
standard library's assumptions: namely, on Windows, we use `fsdecode` to
get back to Unicode strings:
54bbb5e336/Lib/subprocess.py (L561)

So let's start by dropping this utility and going straight for
`fsdecode` here to match.
2022-10-01 16:37:47 -07:00
Jordi
c6d623241b Fix beets#4472 - set 'max_bitrate' default param to none 2022-10-01 01:20:30 +02:00
Aidan Epstein
ac5634d592
Fix old alias
It looks like the convert option for wma used to be called windows media.  We could just remove this alias, but might be good to keep for backwards compatibility.
2022-07-30 16:10:58 +00:00
Duc Nguyen
c4281ddacc add some documentation 2022-03-09 18:34:31 +01:00
Duc Nguyen
a2325e72ad refactoring 2022-03-04 10:42:18 +01:00
Duc Nguyen
af5858d200 doc + linter + changelog 2022-03-04 10:42:17 +01:00
Duc Nguyen
18e8b73c33 add option to convert items after import
convert items after imports but also keep original files intact
2022-03-04 10:40:59 +01:00
Adam Fontenot
07eb26f276 Resize album art when embedding (convert plugin)
Fixes #2116
2022-02-09 23:52:21 -08:00
Adrian Sampson
088cdfe995
Revert some of #4226
Rectify a couple of things in that PR, pointed out here:
https://github.com/beetbox/beets/pull/4226#issuecomment-1011499620

- Undo the `pretend` sensitivity in the import path, because it's not
  clear how this setting could ever be true.
- Preserve the log message in debug mode, even when quiet.
2022-01-29 18:31:48 -05:00
mousecloak
438262844a
Fixed style violation 2022-01-07 21:39:19 -08:00