mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 01:23:09 +01:00
Update fetchart.py
This commit is contained in:
parent
2f0d416965
commit
456cfd7dae
1 changed files with 6 additions and 20 deletions
|
|
@ -836,31 +836,17 @@ class CoverArtUrl(RemoteArtSource):
|
||||||
NAME = "Cover Art URL"
|
NAME = "Cover Art URL"
|
||||||
|
|
||||||
def get(self, album, plugin, paths):
|
def get(self, album, plugin, paths):
|
||||||
|
image_url = None
|
||||||
try:
|
try:
|
||||||
url = album.items().get().cover_art_url
|
image_url = album.items().get().cover_art_url
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._log.debug('Cover art URL not found for {0}', album)
|
self._log.debug('Cover art URL not found for {0}', album)
|
||||||
return
|
return
|
||||||
try:
|
if image_url:
|
||||||
response = requests.get(url, timeout=5)
|
yield self._candidate(url=image_url, match=Candidate.MATCH_EXACT)
|
||||||
response.raise_for_status()
|
else:
|
||||||
except requests.RequestException as e:
|
self._log.debug('Cover art URL not found for {0}', album)
|
||||||
self._log.error("{}".format(e))
|
|
||||||
return
|
return
|
||||||
extension = guess_extension(response.headers
|
|
||||||
['Content-Type'])
|
|
||||||
if extension is None:
|
|
||||||
self._log.error('Invalid image file')
|
|
||||||
return
|
|
||||||
file = f'image{extension}'
|
|
||||||
tempimg = os.path.join(tempfile.gettempdir(), file)
|
|
||||||
try:
|
|
||||||
with open(tempimg, 'wb') as f:
|
|
||||||
f.write(response.content)
|
|
||||||
except Exception as e:
|
|
||||||
self._log.error("Unable to save image: {}".format(e))
|
|
||||||
return
|
|
||||||
yield self._candidate(path=tempimg, match=Candidate.MATCH_EXACT)
|
|
||||||
|
|
||||||
|
|
||||||
class LastFM(RemoteArtSource):
|
class LastFM(RemoteArtSource):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue