Skip to content

Commit 5a559c5

Browse files
committed
http -> https for album art with small refactor
1 parent 095cee9 commit 5a559c5

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

headphones/albumart.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def getAlbumArt(albumid):
2828

2929
# CAA
3030
logger.info("Searching for artwork at CAA")
31-
artwork_path = 'http://coverartarchive.org/release-group/%s/front' % albumid
31+
artwork_path = 'https://coverartarchive.org/release-group/%s/front' % albumid
3232
artwork = getartwork(artwork_path)
3333
if artwork:
3434
logger.info("Artwork found at CAA")
@@ -41,7 +41,7 @@ def getAlbumArt(albumid):
4141
'SELECT ArtistName, AlbumTitle, ReleaseID, AlbumASIN FROM albums WHERE AlbumID=?',
4242
[albumid]).fetchone()
4343
if dbalbum['AlbumASIN']:
44-
artwork_path = 'http://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % dbalbum['AlbumASIN']
44+
artwork_path = 'https://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % dbalbum['AlbumASIN']
4545
artwork = getartwork(artwork_path)
4646
if artwork:
4747
logger.info("Artwork found at Amazon")
@@ -156,12 +156,19 @@ def getartwork(artwork_path):
156156
break
157157
elif maxwidth and img_width > maxwidth:
158158
# Downsize using proxy service to max width
159-
artwork_path = '{0}?{1}'.format('http://images.weserv.nl/', urlencode({
160-
'url': artwork_path.replace('http://', ''),
161-
'w': maxwidth,
162-
}))
163159
artwork = bytes()
164-
r = request.request_response(artwork_path, timeout=20, stream=True, whitelist_status_code=404)
160+
url = "https://images.weserv.nl"
161+
params = {
162+
"url": artwork_path,
163+
"w": maxwidth
164+
}
165+
r = request.request_response(
166+
url,
167+
params=params,
168+
timeout=20,
169+
stream=True,
170+
whitelist_status_code=404
171+
)
165172
if r:
166173
for chunk in r.iter_content(chunk_size=1024):
167174
artwork += chunk
@@ -182,7 +189,7 @@ def getCachedArt(albumid):
182189
if not artwork_path:
183190
return
184191

185-
if artwork_path.startswith('http://'):
192+
if artwork_path.startswith("http"):
186193
artwork = request.request_content(artwork_path, timeout=20)
187194

188195
if not artwork:

headphones/cache.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,17 @@ def _update_cache(self):
540540
artwork_thumb = None
541541
if 'fanart' in thumb_url:
542542
# Create thumb using image resizing service
543-
artwork_path = '{0}?{1}'.format('http://images.weserv.nl/', urlencode({
544-
'url': thumb_url.replace('http://', ''),
545-
'w': 300,
546-
}))
547-
artwork_thumb = request.request_content(artwork_path, timeout=20, whitelist_status_code=404)
548-
543+
url = "https://images.weserv.nl"
544+
params = {
545+
"url": thumb_url,
546+
"w": 300
547+
}
548+
artwork_thumb = request.request_content(
549+
url,
550+
params=params,
551+
timeout=20,
552+
whitelist_status_code=404
553+
)
549554
if artwork_thumb:
550555
with open(thumb_path, 'wb') as f:
551556
f.write(artwork_thumb)

0 commit comments

Comments
 (0)