Skip to content

Commit

Permalink
happyscribe autosubtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix committed Nov 2, 2023
1 parent cbabbb2 commit f8c5adb
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 229 deletions.
13 changes: 1 addition & 12 deletions lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,25 +552,14 @@ public function autoSubtitleAction(Request $request)
(int)$request->request->get("record_id")
);

$permalinkUrl = '';
$conf = $this->getConf();

// if subdef_source not set, by default use the preview permalink
$subdefSource = $conf->get(['externalservice', 'ginger', 'AutoSubtitling', 'subdef_source']) ?: 'preview';

if ($this->isPhysicallyPresent($record, $subdefSource) && ($previewLink = $record->get_subdef($subdefSource)->get_permalink()) != null) {
$permalinkUrl = $previewLink->get_url()->__toString();
}

$this->dispatch(
PhraseaEvents::RECORD_AUTO_SUBTITLE,
new RecordAutoSubtitleEvent(
$record,
$permalinkUrl,
$request->request->get("subtitle_language_source"),
$request->request->get("meta_struct_id_source"),
$request->request->get("subtitle_language_destination"),
$request->request->get("meta_struct_id_destination")
json_decode($request->request->get("subtitle_destination"), true)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ class RecordAutoSubtitleEvent extends RecordEvent
private $metaStructureIdSource;
private $languageDestination;
private $metaStructureIdDestination;
private $permalinkUrl;

public function __construct(
RecordInterface $record,
$permalinkUrl,
$languageSource,
$metaStructureIdSource,
$languageDestination,
$metaStructureIdDestination
$languageDestination
)
{
parent::__construct($record);

$this->languageSource = $languageSource;
$this->metaStructureIdSource = $metaStructureIdSource;
$this->languageDestination = $languageDestination;
$this->metaStructureIdDestination = $metaStructureIdDestination;
$this->permalinkUrl = $permalinkUrl;
}

public function getLanguageSource()
Expand All @@ -49,9 +44,4 @@ public function getMetaStructureIdDestination()
{
return $this->metaStructureIdDestination;
}

public function getPermalinkUrl()
{
return $this->permalinkUrl;
}
}
33 changes: 18 additions & 15 deletions lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ public function __construct(callable $repoWorkerJobLocator, MessagePublisher $me

public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event)
{
$data = [
"databoxId" => $event->getRecord()->getDataboxId(),
"recordId" => $event->getRecord()->getRecordId(),
"permalinkUrl" => $event->getPermalinkUrl(),
"languageSource" => $event->getLanguageSource(),
"metaStructureIdSource" => $event->getMetaStructureIdSource(),
"languageDestination" => $event->getLanguageDestination(),
"metaStructureIdDestination" => $event->getMetaStructureIdDestination(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];
if (!empty($event->getLanguageDestination())) {
$data = [
"databoxId" => $event->getRecord()->getDataboxId(),
"recordId" => $event->getRecord()->getRecordId(),
"languageSource" => $event->getLanguageSource(),
"metaStructureIdSource" => $event->getMetaStructureIdSource(),
"languageDestination" => $event->getLanguageDestination(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];

$payload = [
'message_type' => MessagePublisher::MAIN_QUEUE_TYPE,
'payload' => $data
];
$payload = [
'message_type' => MessagePublisher::MAIN_QUEUE_TYPE,
'payload' => $data
];

$this->messagePublisher->publishMessage($payload, MessagePublisher::MAIN_QUEUE_TYPE);
} else {
$this->messagePublisher->pushLog("There is no language destination selected when trying do do autosubtitle!");
}

$this->messagePublisher->publishMessage($payload, MessagePublisher::MAIN_QUEUE_TYPE);
}

public static function getSubscribedEvents()
Expand Down
Loading

0 comments on commit f8c5adb

Please sign in to comment.