From a6439c0b4c1cb4c85628708b7f64b3c3f415f290 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Fri, 20 Jan 2012 22:49:48 +0000 Subject: [PATCH] serve an empty (transparent) jpeg when no album art is found --- server/djrandom/model/external.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/djrandom/model/external.py b/server/djrandom/model/external.py index c09c4cf..7554582 100644 --- a/server/djrandom/model/external.py +++ b/server/djrandom/model/external.py @@ -8,6 +8,10 @@ from lxml import etree from djrandom import utils +# A transparent 1x1 JPEG image, used when no album art is found. +NULL_JPEG = '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xff\xdb\x00C\x00\x03\x02\x02\x02\x02\x02\x03\x02\x02\x02\x03\x03\x03\x03\x04\x06\x04\x04\x04\x04\x04\x08\x06\x06\x05\x06\t\x08\n\n\t\x08\t\t\n\x0c\x0f\x0c\n\x0b\x0e\x0b\t\t\r\x11\r\x0e\x0f\x10\x10\x11\x10\n\x0c\x12\x13\x12\x10\x13\x0f\x10\x10\x10\xff\xc0\x00\x0b\x08\x00\x01\x00\x01\x01\x01\x11\x00\xff\xc4\x00\x14\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\xff\xc4\x00\x14\x10\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xda\x00\x08\x01\x01\x00\x00?\x00T\xdf\xff\xd9' + + class AlbumImageDiskCache(object): """Cache album art on disk. @@ -38,7 +42,8 @@ class AlbumImageDiskCache(object): return path def set_negative_match(self, artist, album): - open(self._path(artist, album), 'w').close() + with open(self._path(artist, album), 'w') as fd: + fd.write(NULL_JPEG) def download(self, artist, album, url): """Download url and convert to JPEG.""" -- GitLab