Skip to content

Commit a4470ac

Browse files
committed
FetchArt plugin: Support grabbing album art from MB release group
1 parent bb191e7 commit a4470ac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

beetsplug/fetchart.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
import os
2121
import tempfile
22+
import requests
2223

2324
from beets.plugins import BeetsPlugin
2425
from beets.util.artresizer import ArtResizer
@@ -65,12 +66,20 @@ def _fetch_image(url):
6566
# Cover Art Archive.
6667

6768
CAA_URL = 'http://coverartarchive.org/release/{mbid}/front-500.jpg'
69+
CAA_GROUP_URL = 'http://coverartarchive.org/release-group/{mbid}/'
6870

6971
def caa_art(release_id):
7072
"""Return the Cover Art Archive URL given a MusicBrainz release ID.
7173
"""
7274
return CAA_URL.format(mbid=release_id)
7375

76+
def caa_group(release_group_id):
77+
"""Return the Cover Art Archive release group URL given a MusicBrainz
78+
release group ID.
79+
"""
80+
return CAA_GROUP_URL.format(mbid=release_group_id)
81+
82+
RELEASE_ID_PAT = r'^http://musicbrainz.org/release/([^/]+)'
7483

7584
# Art from Amazon.
7685

@@ -153,6 +162,19 @@ def _source_urls(album):
153162
if url:
154163
yield url
155164

165+
if album.mb_releasegroupid:
166+
group_url = caa_group(album.mb_releasegroupid)
167+
response = requests.get(group_url)
168+
if response.status_code == 200:
169+
json = response.json()
170+
if json.has_key('release'):
171+
# URL in the form of http://musicbrainz.org/release/{mbid}
172+
m = re.search(RELEASE_ID_PAT, json['release'])
173+
if m:
174+
url = caa_art(m.group(1))
175+
if url:
176+
yield url
177+
156178
# Amazon and AlbumArt.org.
157179
if album.asin:
158180
for url in art_for_asin(album.asin):

0 commit comments

Comments
 (0)