fetchart plugin - lastfm ignores maxwidth option (solution included)
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
## Problem
The Last.fm art source in the fetchart plugin has two significant issues that limit its functionality.
First, there's a critical bug in the API key handling where self.key is incorrectly initialized as a tuple (api_key,) instead of a string, which may cause API request failures or unexpected behavior. BTW, it's working for me in both cases.
Second, the source is artificially limited to 300x300 pixel images despite Last.fm servers hosting full-resolution artwork - the API only returns URLs with fixed dimensions, but these can be modified by replacing the size component (e.g., "300x300") with an underscore "_" to access the original high-resolution images, potentially providing significantly larger and higher quality album art.
## Environment
OS: Windows 10
Python version: 3.13.6
beets version: 2.3.1
### Config (part)
```yaml
import:
write: yes # write metadata to music files
move: no # move/copy imported files from source to the music directory
copy: yes
delete: no
incremental: yes
duplicate_action: merge
duplicate_verbose_prompt: yes
from_scratch: yes
log: ~\Music\musiclibrary.log
plugins: inline lastgenre discogs fetchart embedart chroma lyrics autobpm
fetchart:
auto: yes
cover_names: cover front folder album
sources:
- filesystem
- lastfm
lastfm_key: '...'
cautious: yes
minwidth: 300
maxwidth: 1200
quality: 90
enforce_ratio: 10%
embedart:
auto: yes
maxwidth: 600
quality: 90
```
## Steps to reproduce
1. Import with enabled fetchart plugin any album with last.fm art better then 300x300 e.g. "Eagleheart - Reverse (2017)"
2. Check log or re-use fetchart separately
```sh
$ beet -vv fetchart -f
fetchart: trying source lastfm for album Eagleheart - Reverse
fetchart: downloading image: https://lastfm.freetls.fastly.net/i/u/300x300/99c3468d26f73ff57a735e2d52770125.jpg
fetchart: downloaded art to: C:\Users\ALEXAN~1\AppData\Local\Temp\beets\beetsplug_fetchart\4z9n0u80.jpg
fetchart: image size: (300, 300)
```
## Patch
```py
--- fetchart.py.orig 2024-01-01 00:00:00.000000000 +0000
+++ fetchart.py 2024-01-01 00:00:01.000000000 +0000
@@ -1008,7 +1008,7 @@
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.key = (self._config["lastfm_key"].get(),)
+ self.key = self._config["lastfm_key"].get()
@staticmethod
def add_default_config(config):
@@ -1064,10 +1064,20 @@
}
# Provide candidates in order of size.
for size in self.SIZES.keys():
if size in images:
- yield self._candidate(
- url=images[size], size=self.SIZES[size]
- )
+ url = images[size]
+
+ # Try to get full-size image by replacing size with '_'
+ full_size_url = re.sub(r'/\d+x\d+/', '/_/', url)
+
+ if full_size_url != url:
+ # Provide full-size version first (higher priority)
+ yield self._candidate(
+ url=full_size_url, size=None
+ )
+
+ # Also provide the original sized version as fallback
+ yield self._candidate(
+ url=url, size=self.SIZES[size]
+ )
except ValueError:
self._log.debug(
"lastfm: error loading response: {}".format(response.text)
```
Contributor guide
Assessment
This issue has not been assessed yet.