File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 19
19
import logging
20
20
import os
21
21
import tempfile
22
+ import requests
22
23
23
24
from beets .plugins import BeetsPlugin
24
25
from beets .util .artresizer import ArtResizer
@@ -65,12 +66,20 @@ def _fetch_image(url):
65
66
# Cover Art Archive.
66
67
67
68
CAA_URL = 'http://coverartarchive.org/release/{mbid}/front-500.jpg'
69
+ CAA_GROUP_URL = 'http://coverartarchive.org/release-group/{mbid}/'
68
70
69
71
def caa_art (release_id ):
70
72
"""Return the Cover Art Archive URL given a MusicBrainz release ID.
71
73
"""
72
74
return CAA_URL .format (mbid = release_id )
73
75
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/([^/]+)'
74
83
75
84
# Art from Amazon.
76
85
@@ -153,6 +162,19 @@ def _source_urls(album):
153
162
if url :
154
163
yield url
155
164
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
+
156
178
# Amazon and AlbumArt.org.
157
179
if album .asin :
158
180
for url in art_for_asin (album .asin ):
You can’t perform that action at this time.
0 commit comments