fetchart plugin - amazon blocks download (solution included)
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
## 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)
```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
- amazon
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 or call separately
2. Check log and audio files
```sh
$ 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
```py
--- 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:
```
Contributor guide
Research direction
Start in fetchart.py at the Amazon source and review the provided request override alongside the existing beet fetchart flow. Run `beet -vv fetchart -f` against an album with Amazon art, then verify that the source returns usable cover art instead of text/html and that the no-art result is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100