fetchart plugin - amazon blocks download (solution included)
Problem
Amazon returns 403 html for requests but cover art can be downloaded
Environment
OS: Windows 10 Python version: 3.13.6 beets version: 2.3.1
Config (part)
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
- amazon
lastfm_key: '...'
cautious: yes
minwidth: 300
maxwidth: 1200
quality: 90
enforce_ratio: 10%
embedart:
auto: yes
maxwidth: 600
quality: 90
Steps to reproduce
- Import with enabled fetchart plugin any album or call separately
- Check log and audio files
$ beet -vv fetchart -f
fetchart: trying source amazon for album Eeriness - A Life Beyond the Shades of Time
fetchart: downloading image: https://images.amazon.com/images/P/B0000A01LI.01.LZZZZZZZ.jpg
fetchart: not a supported image: text/html
fetchart: downloading image: https://images.amazon.com/images/P/B0000A01LI.02.LZZZZZZZ.jpg
fetchart: not a supported image: text/html
fetchart: Eeriness - A Life Beyond the Shades of Time: no art found
Patch
--- fetchart.py.orig 2024-01-01 00:00:00.000000000 +0000
+++ fetchart.py 2024-01-01 00:00:01.000000000 +0000
@@ -512,6 +512,19 @@
URL = "https://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg"
INDICES = (1, 2)
+ def request(self, *args, **kwargs):
+ """Override request method to add browser-like headers for Amazon."""
+ # Add browser-like headers to avoid blocking
+ headers = kwargs.get('headers', {})
+ headers.update({
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
+ 'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8',
+ 'Accept-Language': 'en-US,en;q=0.9',
+ 'Accept-Encoding': 'gzip, deflate, br',
+ 'DNT': '1',
+ 'Connection': 'keep-alive',
+ 'Upgrade-Insecure-Requests': '1',
+ })
+ kwargs['headers'] = headers
+ return super().request(*args, **kwargs)
+
def get(self, album, plugin, paths):
"""Generate URLs using Amazon ID (ASIN) string."""
if album.asin:
I'm not sure how far we want to go with working around measures put in place to prevent scraping as it's essentially a game of cat and mouse. We currently don't do any UA spoofing as it feels a bit dishonest (see #4585). We may be best just disabling or removing the Amazon artwork source.
Still happening today: https://images.amazon.com/images/P/B0000A01LI.01.LZZZZZZZ.jpg returns 403 with text/html. Since amazon is in fetchart's default sources, every user hits this on each fetch.
Following @jackwilsdon's suggestion, I'd like to open a PR for this. Which do you prefer?
- Remove
amazonfrom the defaultsourcesand log a deprecation warning when it's configured, then remove it in a later release. - Remove the
Amazonsource outright, with a changelog note.
I'd go with option 1 so existing configs don't break, plus a test and a changelog entry.