def update(sender, instance, created, **kwargs):
    if not settings.UPLOAD_VIDEOS_TO_S3:
        return
    changed = True
    if created:
        if not instance.flv_file.name:
            instance.flv_file = make_flv_for(instance)
            instance.flv_file._committed = False
            changed = True
            
        try:
            
            from PIL import Image
            new_splash = take_snapshot_for(instance)
            instance.splash_image = new_splash
            changed = True
            upload_to_s3(instance.upload_file.name)
            upload_to_s3(instance.splash_image.name)
            image = Image.open(
                settings.VIDEOS_TEMP_DIR+instance.splash_image.name)
            for thumb in instance.splash_image.field.thumbs:
                thumb_name, thumb_options = thumb
                instance.splash_image.create_and_store_thumb(image,
                                                             thumb_name,
                                                             thumb_options)
    
        except WrongFfmpegFormat:
            from main.models import UserVideo
            UserVideo.objects.filter(video=instance).delete()
            return
            
        if changed:
            if settings.DEFAULT_FILE_STORAGE ==\
                    "django.core.files.storage.FileSystemStorage":
                return

            instance.save()
            upload_to_s3(instance.flv_file.name)
            import os
            os.remove(settings.VIDEOS_TEMP_DIR+instance.upload_file.name)
            os.remove(settings.VIDEOS_TEMP_DIR+instance.flv_file.name)
            os.remove(settings.VIDEOS_TEMP_DIR+instance.splash_image.name)

            if instance.splash_image == "":
                from main.models import UserVideo
                UserVideo.objects.filter(video=instance).delete()
                return
                raise WrongFfmpegFormat
Example #2
0
def update(sender, instance, **kwargs):
    changed = False

    if not instance.flv_file.name:
        instance.flv_file = make_flv_for(instance)
        instance.flv_file._committed = False
        changed = True

    if instance.auto_position:
        new_splash = take_snapshot_for(instance)
        if instance.splash_image != new_splash:
            instance.splash_image = new_splash
            changed = True

    if changed:
        instance.save()