mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-06 23:48:54 -05:00
ref
This commit is contained in:
parent
adc424dd01
commit
e22fee0e0c
@ -469,17 +469,21 @@ def copy_video(original_media, copy_encodings=True, title_suffix="(Trimmed)"):
|
|||||||
for tag in original_media.tags.all():
|
for tag in original_media.tags.all():
|
||||||
new_media.tags.add(tag)
|
new_media.tags.add(tag)
|
||||||
|
|
||||||
# Copy thumbnails if they exist
|
update_fields = []
|
||||||
if original_media.thumbnail:
|
if original_media.thumbnail:
|
||||||
with open(original_media.thumbnail.path, 'rb') as f:
|
with open(original_media.thumbnail.path, 'rb') as f:
|
||||||
thumbnail_name = helpers.get_file_name(original_media.thumbnail.path)
|
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:
|
if original_media.poster:
|
||||||
with open(original_media.poster.path, 'rb') as f:
|
with open(original_media.poster.path, 'rb') as f:
|
||||||
poster_name = helpers.get_file_name(original_media.poster.path)
|
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
|
return new_media
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -527,8 +527,10 @@ class Media(models.Model):
|
|||||||
with open(self.media_file.path, "rb") as f:
|
with open(self.media_file.path, "rb") as f:
|
||||||
myfile = File(f)
|
myfile = File(f)
|
||||||
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
||||||
self.thumbnail.save(content=myfile, name=thumbnail_name)
|
self.thumbnail.save(content=myfile, name=thumbnail_name, save=False)
|
||||||
self.poster.save(content=myfile, name=thumbnail_name)
|
self.poster.save(content=myfile, name=thumbnail_name, save=False)
|
||||||
|
self.save(update_fields=["thumbnail", "poster"])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def produce_thumbnails_from_video(self):
|
def produce_thumbnails_from_video(self):
|
||||||
@ -562,8 +564,9 @@ class Media(models.Model):
|
|||||||
with open(tf, "rb") as f:
|
with open(tf, "rb") as f:
|
||||||
myfile = File(f)
|
myfile = File(f)
|
||||||
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
thumbnail_name = helpers.get_file_name(self.media_file.path) + ".jpg"
|
||||||
self.thumbnail.save(content=myfile, name=thumbnail_name)
|
self.thumbnail.save(content=myfile, name=thumbnail_name, save=False)
|
||||||
self.poster.save(content=myfile, name=thumbnail_name)
|
self.poster.save(content=myfile, name=thumbnail_name, save=False)
|
||||||
|
self.save(update_fields=["thumbnail", "poster"])
|
||||||
helpers.rm_file(tf)
|
helpers.rm_file(tf)
|
||||||
return True
|
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":
|
if os.path.exists(output_name) and get_file_type(output_name) == "image":
|
||||||
with open(output_name, "rb") as f:
|
with open(output_name, "rb") as f:
|
||||||
myfile = File(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(
|
media.sprites.save(
|
||||||
content=myfile,
|
content=myfile,
|
||||||
name=get_file_name(media.media_file.path) + "sprites.jpg",
|
name=get_file_name(media.media_file.path) + "sprites.jpg",
|
||||||
|
save=False
|
||||||
)
|
)
|
||||||
|
media.save(update_fields=["sprites"])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user