This commit is contained in:
Markos Gogoulos 2025-05-16 11:47:15 +03:00
parent 52fab13286
commit adc424dd01
2 changed files with 37 additions and 15 deletions

View File

@ -319,7 +319,7 @@ class Media(models.Model):
self.__original_uploaded_poster = self.uploaded_poster
def save(self, *args, **kwargs):
print(f"saomeone called save for {self.friendly_token} so will print {self.hls_file}")
print(f"SAVE called for {self.friendly_token}")
if not self.title:
self.title = self.media_file.path.split("/")[-1]
@ -1574,6 +1574,7 @@ def media_save(sender, instance, created, **kwargs):
# once model is saved
# SOS: do not put anything here, as if more logic is added,
# we have to disconnect signal to avoid infinite recursion
print(f'mpainei media_save gia {instance.friendly_token}')
if not instance.friendly_token:
return False
@ -1595,7 +1596,7 @@ def media_save(sender, instance, created, **kwargs):
tag.update_tag_media()
instance.update_search_vector()
print(f'kanei exit i media_save')
print(f'EXIT media_save gia {instance.friendly_token}')
@receiver(pre_delete, sender=Media)

View File

@ -855,6 +855,35 @@ def produce_video_chapters(chapter_id):
return True
@task(name="post_trim_action", queue="short_tasks", soft_time_limit=600)
def post_trim_action(friendly_token):
"""Perform post-processing actions after video trimming
Args:
friendly_token: The friendly token of the media
Returns:
bool: True if successful, False otherwise
"""
logger.info(f"Post trim action for {friendly_token}")
try:
media = Media.objects.get(friendly_token=friendly_token)
except Media.DoesNotExist:
logger.info(f"Media with friendly token {friendly_token} not found")
return False
media.set_media_type()
encodings = media.encodings.filter(status="success", profile__extension='mp4', chunk=False)
for encoding in encodings:
update_encoding_size(encoding.id)
media.produce_thumbnails_from_video()
produce_sprite_from_video.delay(friendly_token)
create_hls.delay(friendly_token)
return True
@task(name="video_trim_task", bind=True, queue="short_tasks", soft_time_limit=600)
def video_trim_task(self, trim_request_id):
# SOS: if at some point we move from ffmpeg copy, then this need be changed
@ -906,17 +935,13 @@ def video_trim_task(self, trim_request_id):
trim_result = trim_video_method(encoding.media_file.path, timestamps_encodings)
if not trim_result:
logger.info(f"Failed to trim encoding {encoding.id} for media {target_media.friendly_token}")
else:
update_encoding_size.delay(encoding.id)
original_trim_result = trim_video_method(target_media.media_file.path, timestamps_original)
if not original_trim_result:
logger.info(f"Failed to trim original file for media {target_media.friendly_token}")
target_media.set_media_type()
target_media.produce_thumbnails_from_video()
target_media.produce_sprite_from_video()
create_hls.delay(target_media.friendly_token)
# Schedule post-processing
post_trim_action.delay(target_media.friendly_token)
trim_request.status = "success"
trim_request.save(update_fields=["status"])
@ -930,13 +955,9 @@ def video_trim_task(self, trim_request_id):
encodings = new_media.encodings.filter(status="success", profile__extension='mp4', chunk=False)
for encoding in encodings:
trim_result = trim_video_method(encoding.media_file.path, [timestamp])
update_encoding_size.delay(encoding.id)
new_media.set_media_type()
new_media.produce_thumbnails_from_video()
new_media.produce_sprite_from_video()
create_hls.delay(new_media.friendly_token)
# Schedule post-processing
post_trim_action.delay(new_media.friendly_token)
trim_request.status = "success"
trim_request.save(update_fields=["status"])