mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-21 13:57:57 -05:00
Bulk actions support (#1418)
This commit is contained in:
@@ -91,10 +91,10 @@ class Category(models.Model):
|
||||
if self.listings_thumbnail:
|
||||
return self.listings_thumbnail
|
||||
|
||||
if Media.objects.filter(category=self, state="public").exists():
|
||||
media = Media.objects.filter(category=self, state="public").order_by("-views").first()
|
||||
if media:
|
||||
return media.thumbnail_url
|
||||
# Optimize: Use first() directly instead of exists() + first() (saves one query)
|
||||
media = Media.objects.filter(category=self, state="public").order_by("-views").first()
|
||||
if media:
|
||||
return media.thumbnail_url
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -357,6 +357,10 @@ class Media(models.Model):
|
||||
a_tags,
|
||||
b_tags,
|
||||
]
|
||||
|
||||
for subtitle in self.subtitles.all():
|
||||
items.append(subtitle.subtitle_text)
|
||||
|
||||
items = [item for item in items if item]
|
||||
text = " ".join(items)
|
||||
text = " ".join([token for token in text.lower().split(" ") if token not in STOP_WORDS])
|
||||
@@ -406,11 +410,11 @@ class Media(models.Model):
|
||||
self.media_type = "image"
|
||||
elif kind == "pdf":
|
||||
self.media_type = "pdf"
|
||||
|
||||
if self.media_type in ["audio", "image", "pdf"]:
|
||||
if self.media_type in ["image", "pdf"]:
|
||||
self.encoding_status = "success"
|
||||
else:
|
||||
ret = helpers.media_file_info(self.media_file.path)
|
||||
|
||||
if ret.get("fail"):
|
||||
self.media_type = ""
|
||||
self.encoding_status = "fail"
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pysubs2
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
|
||||
from .. import helpers
|
||||
@@ -42,6 +45,8 @@ class Subtitle(models.Model):
|
||||
user = models.ForeignKey("users.User", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Caption"
|
||||
verbose_name_plural = "Captions"
|
||||
ordering = ["language__title"]
|
||||
|
||||
def __str__(self):
|
||||
@@ -71,6 +76,17 @@ class Subtitle(models.Model):
|
||||
raise Exception("Could not convert to srt")
|
||||
return True
|
||||
|
||||
@property
|
||||
def subtitle_text(self):
|
||||
sub = pysubs2.load(self.subtitle_file.path, encoding="utf-8")
|
||||
text = ' '.join([line.text for line in sub])
|
||||
text = text.replace("\\N", " ")
|
||||
text = text.replace("-", " ")
|
||||
text = text.replace(".", " ")
|
||||
text = text.replace(" ", " ")
|
||||
|
||||
return text
|
||||
|
||||
|
||||
class TranscriptionRequest(models.Model):
|
||||
# Whisper transcription request
|
||||
@@ -80,5 +96,19 @@ class TranscriptionRequest(models.Model):
|
||||
translate_to_english = models.BooleanField(default=False)
|
||||
logs = models.TextField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Caption Request"
|
||||
verbose_name_plural = "Caption Requests"
|
||||
|
||||
def __str__(self):
|
||||
return f"Transcription request for {self.media.title} - {self.status}"
|
||||
|
||||
|
||||
@receiver(post_save, sender=Subtitle)
|
||||
def subtitle_save(sender, instance, created, **kwargs):
|
||||
from .. import tasks
|
||||
|
||||
tasks.update_search_vector.apply_async(
|
||||
args=[instance.media.friendly_token],
|
||||
countdown=10,
|
||||
)
|
||||
|
||||
@@ -56,6 +56,10 @@ class VideoTrimRequest(models.Model):
|
||||
media_trim_style = models.CharField(max_length=20, choices=TRIM_STYLE_CHOICES, default="no_encoding")
|
||||
timestamps = models.JSONField(null=False, blank=False, help_text="Timestamps for trimming")
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Trim Request"
|
||||
verbose_name_plural = "Trim Requests"
|
||||
|
||||
def __str__(self):
|
||||
return f"Trim request for {self.media.title} ({self.status})"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user