Skip to content

Commit 6c2c460

Browse files
authored
Respect no_convert and never_convert_lossy_files in convert plugin (#6286)
Given that @frigginbrownie's #5556 PR received some thumb ups but they haven't responded since a while ago, I'm creating this PR to merge their fix (I could not commit in the PR branch since I have no permissions to push to their fork). Supersedes: #5556 Copying @frigginbrownie description from #5556: According to the docs, the auto_keep function will "Convert your files automatically on import to dest but import the non transcoded version." This is true but not 100% accurate. In cases where no conversion is required (say, importing lossy files where there's no need to convert), auto_keep will copy the files to dest. This behavior results in duplicate files being created on import when the auto_keep function is set to yes - a lossy file will be imported into the default directory (say /music) and then copied to the dest location (say /transcodes). This is ideal if you wish to have all music formats in your default directory (lossy and lossless) and all lossy files (original imports and transcodes) in a secondary directory (say /lossy). But what if you want a separate directory of all music you've transcoded? auto_keep won't provide that, as it copies lossy files to the dest location. In addition, if the dest is set to the same location as default directory, auto_keep will copy lossy files into the same directory that beets previously imported files into, resulting in the directory having two files for each file in an album. If you use paths (say to have singletons imported into /music/singles), auto_keep will import the file into the path location, then copy the file to the dest, creating directories to match the path. Unlike with the auto option or using "beet convert", auto_keep does not follow the never_convert_lossy_files or no_convert options and will not validate whether files need to be converted or copied on import to dest - it transcodes or it copies, no questions asked. This change updates the auto_convert_keep function to filter items using should_transcode. This way, if the user sets never_convert_lossy_files to no or no_convert: 'format:mp3', lossy files will not be copied to the dest, while lossless files will be converted to the dest (perfect for a seperate /transcodes directory). If the user sets never_convert_lossy_files to yes, lossy files will to be copied to the dest and lossless files will be converted to the dest (perfect for a /lossy directory). In turn, this change makes behavior consistent with "beet convert" and the auto option.
2 parents 679cfc9 + bfb24da commit 6c2c460

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

beetsplug/convert.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ def auto_convert_keep(self, config, task):
279279
) = self._get_opts_and_config(empty_opts)
280280

281281
items = task.imported_items()
282+
283+
# Filter items based on should_transcode function
284+
items = [item for item in items if should_transcode(item, fmt)]
285+
282286
self._parallel_convert(
283287
dest,
284288
False,

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Bug fixes:
9292
preventing incorrect splits when both are present.
9393
- :doc:`reference/cli`: Fix 'from_scratch' option for singleton imports: delete
9494
all (old) metadata when new metadata is applied. :bug:`3706`
95+
- :doc:`/plugins/convert`: ``auto_keep`` now respects ``no_convert`` and
96+
``never_convert_lossy_files`` when deciding whether to copy/transcode items,
97+
avoiding extra lossy duplicates.
9598

9699
For plugin developers:
97100

0 commit comments

Comments
 (0)