beets icon indicating copy to clipboard operation
beets copied to clipboard

bug[fetchart]: Only one of the resize operation is executed.

Open Dr-Blank opened this issue 3 months ago • 1 comments

Consider a case where a coverart is of PNG format with size 15 MB. (happens sometimes with itunes coverart on musicbrainz).

Also consider the following fetchart config:

plugins: fetchart
fetchart:
  sources:
    - filesystem
    - coverart: release
    - itunes
    - amazon
    - albumart
    - coverart: releasegroup
    - "*"
  max_filesize: 3500000
  cover_format: JPEG

PIL is used as the image resizer

Problem

$ beet -vv fetchart
Candidate._validate(self, plugin)
# returns only CANDIDATE_DOWNSIZE
# and skips CANDIDATE_REFORMAT

the function can only perform one of the operations in the current scenario, and since downsizing is returned before reformatting, during .resize() only downsizing takes place. Which is its own separate bug since PIL can not downnsize PNG files.

Setup

  • OS: Windows
  • Python version: 3.11.0b1
  • beets version: https://github.com/beetbox/beets/commit/b09806e0df8f01b9155017d3693764ae7beedcd5
  • Turning off plugins made problem go away (yes/no): N/A

Dr-Blank avatar Mar 18 '24 11:03 Dr-Blank

proposed solution

  1. make validate return a list of operations to perform instead of just one of them with priority: CANDIDATE_REFORMAT > CANDIDATE_DOWNSCALE > CANDIDATE_DOWNSIZE not sure where CANDIDATE_DEINTERLACE would go during .resize() pop each operation from the list and perform. Note: however, before resizing a check should be placed since previous operation might have done the size reducing.

  2. option to, recurse until _validate returns CANDIDATE_EXACT with above the above operation priority. Note: can get stuck on resizing since PNG cannot be resized, so either validate or the function doing the recursion should move on to next operation of downsizing fails.

Dr-Blank avatar Mar 18 '24 12:03 Dr-Blank