Skip to content

Commit

Permalink
Try to fix mulitple transcription with new receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
pampletousse authored and pampletousse committed Nov 24, 2023
1 parent 81790b3 commit 905f8f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
20 changes: 19 additions & 1 deletion pod/video/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@
)

if USE_TRANSCRIPTION:
from ..video_encode_transcript import transcript

TRANSCRIPT_VIDEO = getattr(settings, "TRANSCRIPT_VIDEO", "start_transcript")

transcript_help_text = OrderedDict(
[
(
Expand Down Expand Up @@ -540,6 +544,14 @@ def launch_encode(sender, instance, created, **kwargs):
encode_video(instance.id)


@receiver(post_save, sender=Video)
def launch_transcript(sender, instance, created, **kwargs):
if hasattr(instance, "launch_transcript") and instance.launch_transcript is True:
instance.launch_transcript = False
transcript_video = getattr(transcript, TRANSCRIPT_VIDEO)
transcript_video(instance.id)


class VideoForm(forms.ModelForm):
"""Form class for Video editing."""

Expand Down Expand Up @@ -705,6 +717,9 @@ def save(self, commit=True, *args, **kwargs):

if hasattr(self, "launch_encode"):
video.launch_encode = self.launch_encode

if hasattr(self, "launch_transcript"):
video.launch_transcript = self.launch_transcript
return video

def clean_date_delete(self):
Expand Down Expand Up @@ -755,7 +770,10 @@ def clean(self):
and hasattr(self.instance, "video")
and cleaned_data["video"] != self.instance.video
)

self.launch_transcript = (
"transcript" in cleaned_data.keys()
and hasattr(self.instance, "transcript")
)
self.change_user = (
self.launch_encode is False
and hasattr(self.instance, "encoding_in_progress")
Expand Down
2 changes: 1 addition & 1 deletion pod/video/static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function bulkUpdate() {

// Init vars
let formData = new FormData();
let updateAction = action === "delete" || action === "transcript" ? action : "fields" ;
let updateAction = action === "delete" ? action : "fields" ;
let updateFields = [];

// Set updated field(s)
Expand Down
28 changes: 0 additions & 28 deletions pod/video/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,6 @@ def bulk_update(request):
# Bulk delete
deleted_videos, status = bulk_update_delete(request, videos_list)
counter = len(deleted_videos)
elif update_action == "transcript":
# Bulk transcript
updated_videos, status = bulk_update_transcript(request, videos_list)
counter = len(updated_videos)
else:
pass

Expand Down Expand Up @@ -737,30 +733,6 @@ def bulk_update_delete(request, videos_list):
return deleted_videos, status


def bulk_update_transcript(request, videos_list):
"""
Perform bulk transcript for selected videos.
Args:
request (Request): current HTTP Request.
videos_list (List[Video]): list of videos to be transcript.
Returns:
updated_videos (List[string]): list of modified videos slugs.
status (number): HTTP status.
"""
status = 200
updated_videos = []

try:
for video in videos_list:
video_transcript(request, video.slug)
updated_videos.append(video.slug)
except Exception:
status = 400
return updated_videos, status


def get_bulk_update_result(request, status, update_action, counter, delta, result):
"""
Build and return result object with updated status and message for bulk update action.
Expand Down

0 comments on commit 905f8f1

Please sign in to comment.