mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-07-25 15:03:31 +00:00
ref
This commit is contained in:
@ -469,17 +469,21 @@ def copy_video(original_media, copy_encodings=True, title_suffix="(Trimmed)"):
|
||||
for tag in original_media.tags.all():
|
||||
new_media.tags.add(tag)
|
||||
|
||||
# Copy thumbnails if they exist
|
||||
update_fields = []
|
||||
if original_media.thumbnail:
|
||||
with open(original_media.thumbnail.path, 'rb') as f:
|
||||
thumbnail_name = helpers.get_file_name(original_media.thumbnail.path)
|
||||
new_media.thumbnail.save(thumbnail_name, File(f))
|
||||
new_media.thumbnail.save(thumbnail_name, File(f), save=False)
|
||||
update_fields.append("thumbnail")
|
||||
|
||||
if original_media.poster:
|
||||
with open(original_media.poster.path, 'rb') as f:
|
||||
poster_name = helpers.get_file_name(original_media.poster.path)
|
||||
new_media.poster.save(poster_name, File(f))
|
||||
new_media.poster.save(poster_name, File(f), save=False)
|
||||
update_fields.append("poster")
|
||||
|
||||
if update_fields:
|
||||
new_media.save(update_fields=update_fields)
|
||||
return new_media
|
||||
|
||||
|
||||
|
@ -527,8 +527,10 @@ class Media(models.Model):
|
||||
with open(self.media_file.path, "rb") as f:
|
||||
myfile = File(f)
|
||||
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
||||
self.thumbnail.save(content=myfile, name=thumbnail_name)
|
||||
self.poster.save(content=myfile, name=thumbnail_name)
|
||||
self.thumbnail.save(content=myfile, name=thumbnail_name, save=False)
|
||||
self.poster.save(content=myfile, name=thumbnail_name, save=False)
|
||||
self.save(update_fields=["thumbnail", "poster"])
|
||||
|
||||
return True
|
||||
|
||||
def produce_thumbnails_from_video(self):
|
||||
@ -562,8 +564,9 @@ class Media(models.Model):
|
||||
with open(tf, "rb") as f:
|
||||
myfile = File(f)
|
||||
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
||||
self.thumbnail.save(content=myfile, name=thumbnail_name)
|
||||
self.poster.save(content=myfile, name=thumbnail_name)
|
||||
self.thumbnail.save(content=myfile, name=thumbnail_name, save=False)
|
||||
self.poster.save(content=myfile, name=thumbnail_name, save=False)
|
||||
self.save(update_fields=["thumbnail", "poster"])
|
||||
helpers.rm_file(tf)
|
||||
return True
|
||||
|
||||
|
@ -410,10 +410,14 @@ def produce_sprite_from_video(friendly_token):
|
||||
if os.path.exists(output_name) and get_file_type(output_name) == "image":
|
||||
with open(output_name, "rb") as f:
|
||||
myfile = File(f)
|
||||
# SOS: avoid race condition, since this runs for a long time and will replace any other media changes on the meanwhile!!!
|
||||
media.sprites.save(
|
||||
content=myfile,
|
||||
name=get_file_name(media.media_file.path) + "sprites.jpg",
|
||||
save=False
|
||||
)
|
||||
media.save(update_fields=["sprites"])
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return True
|
||||
|
Reference in New Issue
Block a user