def __init__(self, image_data): self.image_data = image_data img = Image.new(image_data, u'', 0) Image.__init__(self, data=image_data, mime_type=img.mime_type, width=img.width, height=img.height, color_depth=img.color_depth, color_count=img.color_count, description=img.description, type=img.type)
def perform_lookup(mbid, coverartarchive_server="coverartarchive.org", coverartarchive_port=80): """given a MusicBrainz ID as a plain string, and optional coverartarchive server/port, returns a list of Image objects for each cover may return an empty list if no covers are found or raise an exception if a problem occurs querying the server""" from audiotools import Image from audiotools import FRONT_COVER from audiotools import BACK_COVER try: from urllib.request import urlopen from urllib.request import URLError except ImportError: from urllib2 import urlopen from urllib2 import URLError from json import loads # query server for JSON data about MBID release try: j = urlopen("http://{server}:{port}/release/{release}/".format( server=coverartarchive_server, port=coverartarchive_port, release=mbid)) except URLError: return [] json_data = loads(j.read().decode("utf-8", "replace")) j.close() images = [] # get URLs of all front and back cover art in list try: for image in json_data[u"images"]: if image[u"front"] or image[u"back"]: try: data = urlopen(image[u"image"]) images.append( Image.new( data.read(), u"", FRONT_COVER if image[u"front"] else BACK_COVER)) data.close() except URLError: # skip images that aren't found pass except KeyError: pass # return list of all fetched cover art return images
def __parse_image__(self, key, type): data = cStringIO.StringIO(self[key].data) description = [] c = data.read(1) while (c != '\x00'): description.append(c) c = data.read(1) return Image.new(data.read(), "".join(description).decode('utf-8', 'replace'), type)
def __parse_image__(self, key, type): from audiotools import Image from io import BytesIO data = BytesIO(self[key].data) description = [] c = data.read(1) while (c != '\x00'): description.append(c) c = data.read(1) return Image.new(data.read(), "".join(description).decode('utf-8', 'replace'), type)
def __parse_image__(self, key, type): data = cStringIO.StringIO(str(self[key])) description = Con.CString(None).parse_stream(data).decode('utf-8', 'replace') data = data.read() return Image.new(data, description, type)
def __parse_image__(self, key, type): data = cStringIO.StringIO(str(self[key])) description = construct.CString(None).parse_stream(data).decode( 'utf-8', 'replace') data = data.read() return Image.new(data, description, type)