Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def video_saved(sender, instance, **kwargs):
if not ffmpeg.installed():
return
if hasattr(instance, '_from_signal'):
return
has_changed = instance._initial_file is not instance.file
filled_out = instance.thumbnail is not None and instance.duration is not None
if has_changed or not filled_out:
with get_local_file(instance.file) as file_path:
if has_changed or instance.thumbnail is None:
instance.thumbnail = ffmpeg.get_thumbnail(file_path)
if has_changed or instance.duration is None:
instance.duration = ffmpeg.get_duration(file_path)
instance.file_size = instance.file.size
instance._from_signal = True
instance.save()
del instance._from_signal