Example #1
0
def import_release_image(release, directories=[]):
    if release.image:
        print "Image for release %s exists, skipping" % release.mbid
        return

    i = image.get_coverart_from_caa(release.mbid)
    caa = True
    if not i:
        caa = False
        print "No image on CAA for %s, looking in directory" % release.mbid
        i = image.get_coverart_from_directories(directories)
    if i:
        im = data.models.Image()
        if caa:
            uri = "http://archive.org/details/mbid-%s" % release.mbid
            sn = data.models.SourceName.objects.get(name="Cover Art Archive")
            source, created = data.models.Source.objects.get_or_create(
                source_name=sn, uri=uri, defaults={"title": release.title}
            )
            im.source = source
        im.image.save("release-%s.jpg" % release.mbid, ContentFile(i))

        # If the image is a different size from one that already exists, then
        # replace it. Also remove if we have an item, but can't find the image
        # for it.
        if release.image:
            existingimg = release.image
            haveimage = True
            if not os.path.exists(existingimg.image.path):
                existingimg.delete()
            elif existingimg.image.size != len(i):
                # If the imagesize has changed, remove it
                os.unlink(existingimg.image.path)
                existingimg.delete()
        else:
            haveimage = False

        # If we have an image, don't add it
        if not haveimage:
            release.image = im
            release.save()
    else:
        print "Can't find an image for %s" % release.mbid
def import_release_image(release, directories=[]):
    if release.image:
        print("Image for release %s exists, skipping" % release.mbid)
        return

    i = image.get_coverart_from_caa(release.mbid)
    caa = True
    if not i:
        caa = False
        print("No image on CAA for %s, looking in directory" % release.mbid)
        i = image.get_coverart_from_directories(directories)
    if i:
        im = data.models.Image()
        if caa:
            uri = "http://archive.org/details/mbid-%s" % release.mbid
            sn = data.models.SourceName.objects.get(name="Cover Art Archive")
            source, created = data.models.Source.objects.get_or_create(
                source_name=sn, uri=uri, defaults={"title": release.title})
            im.source = source
        im.image.save("release-%s.jpg" % release.mbid, ContentFile(i))

        # If the image is a different size from one that already exists, then
        # replace it. Also remove if we have an item, but can't find the image
        # for it.
        if release.image:
            existingimg = release.image
            haveimage = True
            if not os.path.exists(existingimg.image.path):
                existingimg.delete()
            elif existingimg.image.size != len(i):
                # If the imagesize has changed, remove it
                os.unlink(existingimg.image.path)
                existingimg.delete()
        else:
            haveimage = False

        # If we have an image, don't add it
        if not haveimage:
            release.image = im
            release.save()
    else:
        print("Can't find an image for %s" % release.mbid)
Example #3
0
def import_release_image(release, directories=[], overwrite=False):
    for existing in release.images.all():
        name = os.path.splitext(os.path.basename(existing.image.name))
        if name == release.mbid:
            print "Image for release %s exists, skipping" % release.mbid
            return

    i = image.get_coverart_from_caa(release.mbid)
    caa = True
    if not i:
        caa = False
        print "No image on CAA for %s, looking in directory" % release.mbid
        i = image.get_coverart_from_directories(directories)
    if i:
        im = data.models.Image()
        if caa:
            uri = "http://archive.org/details/mbid-%s" % release.mbid
            sn = data.models.SourceName.objects.get(name="Cover Art Archive")
            source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=uri, defaults={"title": release.title})
            im.source = source
        im.image.save("release-%s.jpg" % release.mbid, ContentFile(i))

        # If the image is a different size from one that already exists, then
        # replace it. Also remove if we have an item, but can't find the image
        # for it.
        try:
            existingimg = release.images.get(image__contains="%s" % release.mbid)
            if not os.path.exists(existingimg.image.path):
                existingimg.delete()
            elif existingimg.image.size != len(i) or overwrite:
                # If the imagesize has changed, or overwrite is set, remove the image
                os.unlink(existingimg.image.path)
                existingimg.delete()
        except data.models.Image.DoesNotExist:
            pass

        release.images.add(im)
        release.save()
    else:
        print "Can't find an image for %s" % release.mbid
Example #4
0
def import_concert_image(concert, directories=[], overwrite=False):
    for existing in concert.images.all():
        name = os.path.splitext(os.path.basename(existing.image.name))
        if name == concert.mbid:
            print "Image for concert %s exists, skipping" % concert.mbid
            return

    i = image.get_coverart_from_caa(concert.mbid)
    caa = True
    if not i:
        caa = False
        print "No image on CAA for %s, looking in directory" % concert.mbid
        i = image.get_coverart_from_directories(directories)
    if i:
        im = data.models.Image()
        if caa:
            uri = "http://archive.org/details/mbid-%s" % concert.mbid
            sn = data.models.SourceName.objects.get(name="Cover Art Archive")
            source, created = data.models.Source.objects.get_or_create(
                source_name=sn, uri=uri, defaults={"title": concert.title})
            im.source = source
        im.image.save("concert-%s.jpg" % concert.mbid, ContentFile(i))

        # If the image is a different size from one that already exists, then
        # replace it
        try:
            existingimg = concert.images.get(image__contains="%s" %
                                             concert.mbid)
            if existingimg.image.size != len(i) or overwrite:
                # If the imagesize has changed, or overwrite is set, remove the image
                existingimg.delete()
        except data.models.Image.DoesNotExist:
            pass

        concert.images.add(im)
        concert.save()
    else:
        print "Can't find an image for %s" % concert.mbid