diff --git a/server/djrandom/model/external.py b/server/djrandom/model/external.py index c09c4cf73973ee998d098abda865e5dc7233d4a1..7554582926e917acb4d0458e1d625ff92c8d2bf3 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."""