diff --git a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php index 1aeeb2554a..d6eb522fb7 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php @@ -558,7 +558,6 @@ public function autoSubtitleAction(Request $request) new RecordAutoSubtitleEvent( $record, $request->request->get("subtitle_language_source"), - $request->request->get("meta_struct_id_source"), json_decode($request->request->get("subtitle_destination"), true) ) ); @@ -618,7 +617,8 @@ public function videoEditorAction(Request $request) 'videoEditorConfig' => $conf->get(['video-editor']), 'metadatas' => $metadatas, 'JSonFields' => json_encode($JSFields), - 'videoTextTrackFields' => $videoTextTrackFields + 'videoTextTrackFields' => $videoTextTrackFields, + 'languages' => $this->languageList() ]); } @@ -633,4 +633,42 @@ private function isPhysicallyPresent(record_adapter $record, $subdefName) return false; } + + private function languageList() + { + return [ + 'af-ZA' => 'af-ZA Afrikaans (South Africa)', 'am-ET' => 'am-ET Amharic (Ethiopia)', + 'ar-DZ' => 'ar-DZ Arabic (Algeria)', 'ar-BH' => 'ar-BH Arabic (Bahrain)', + 'ar-EG' => 'ar-EG Arabic (Egypt)', 'ar-IQ' => 'ar-IQ Arabic (Iraq)', + 'ar-IL' => 'ar-IL Arabic (Israel)', 'ar-YE' => 'ar-YE Arabic (Yemen)', + 'eu-ES' => 'eu-ES Basque (Spain)', 'bn-BD' => 'bn-BD Bengali (Bangladesh)', + 'bn-IN' => 'bn-IN Bengali (India)', 'bg-BG' => 'bg-BG Bulgarian (Bulgaria)', + 'ca-ES' => 'ca-ES Catalan (Spain)', 'yue-Hant-HK' => 'yue-Hant-HK Chinese, Cantonese (Traditional, Hong Kong)', + 'cmn-Hans-CN' => 'cmn-Hans-CN Chinese, Mandarin (Simplified, China)', 'hr-HR' => 'hr-HR Croatian (Croatia)', + 'cs-CZ' => 'cs-CZ Czech (Czech Republic)', 'da-DK' => 'da-DK Danish (Denmark)', + 'nl-NL' => 'nl-NL Dutch (Netherlands)', 'nl-BE' => 'nl-BE Dutch (Belgium)', + 'en-AU' => 'en-AU English (Australia)', 'en-CA' => 'en-CA English (Canada)', + 'en-GB' => 'en-GB English (United Kingdom)', 'en-US' => 'en-US English (United States)', + 'fr-CA' => 'fr-CA French (Canada)', 'fr-FR' => 'fr-FR French (France)', + 'fr-BE' => 'fr-BE French (Belgium)', 'fr-CH' => 'fr-CH French (Switzerland)', + 'ka-GE' => 'ka-GE Georgian (Georgia)', 'de-DE' => 'de-DE German (Germany)', + 'el-GR' => 'el-GR Greek (Greece)', 'he-IL' => 'he-IL Hebrew (Israel)', + 'hi-IN' => 'hi-IN Hindi (India)', 'hu-HU' => 'hu-HU Hungarian (Hungary)', + 'is-IS' => 'is-IS Icelandic (Iceland)', 'id-ID' => 'id-ID Indonesian (Indonesia)', + 'it-IT' => 'it-IT Italian (Italy)', 'ja-JP' => 'ja-JP Japanese (Japan)', + 'ko-KR' => 'ko-KR Korean (South Korea)', 'lo-LA' => 'lo-LA Lao (Laos)', + 'lt-LT' => 'lt-LT Lithuanian (Lithuania)', 'ms-MY' => 'ms-MY Malay (Malaysia)', + 'ne-NP' => 'ne-NP Nepali (Nepal)', 'nb-NO' => 'nb-NO Norwegian Bokmål (Norway)', + 'pl-PL' => 'pl-PL Polish (Poland)', 'pt-BR' => 'pt-BR Portuguese (Brazil)', + 'pt-PT' => 'pt-PT Portuguese (Portugal)', 'ro-RO' => 'ro-RO Romanian (Romania)', + 'ru-RU' => 'ru-RU Russian (Russia)', 'sr-RS' => 'sr-RS Serbian (Serbia)', + 'sk-SK' => 'sk-SK Slovak (Slovakia)', 'sl-SI' => 'sl-SI Slovenian (Slovenia)', + 'es-ES' => 'es-ES Spanish (Spain)', 'sv-SE' => 'sv-SE Swedish (Sweden)', + 'th-TH' => 'th-TH Thai (Thailand)', 'tr-TR' => 'tr-TR Turkish (Turkey)', + 'uk-UA' => 'uk-UA Ukrainian (Ukraine)', 'vi-VN' => 'vi-VN Vietnamese (Vietnam)', + 'et-EE' => 'et-EE Estonian (Estonia)', 'mn-MN' => 'mn-MN Mongolian (Mongolia)', + 'uz-UZ' => 'uz-UZ Uzbek (Uzbekistan)' + + ]; + } } diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordAutoSubtitleEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/RecordAutoSubtitleEvent.php index 706ad8a3fb..37b12fb4e0 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordAutoSubtitleEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/RecordAutoSubtitleEvent.php @@ -14,14 +14,12 @@ class RecordAutoSubtitleEvent extends RecordEvent public function __construct( RecordInterface $record, $languageSource, - $metaStructureIdSource, $languageDestination ) { parent::__construct($record); $this->languageSource = $languageSource; - $this->metaStructureIdSource = $metaStructureIdSource; $this->languageDestination = $languageDestination; } @@ -30,11 +28,6 @@ public function getLanguageSource() return $this->languageSource; } - public function getMetaStructureIdSource() - { - return $this->metaStructureIdSource; - } - public function getLanguageDestination() { return $this->languageDestination; diff --git a/lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php b/lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php index 0465e52e24..b6ab7c4b28 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php @@ -32,7 +32,6 @@ public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event) "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 ]; diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php index 34e00b82fb..d170e6d694 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php @@ -96,8 +96,6 @@ public function process(array $payload) $this->extension = 'vtt'; } - $languageSource = $this->getLanguageFormat($payload['languageSource']); - $record = $this->getApplicationBox()->get_databox($payload['databoxId'])->get_record($payload['recordId']); // if subdef_source not set, by default use the preview permalink @@ -145,20 +143,28 @@ public function process(array $payload) // create a transcription - $responseTranscription = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/transcriptions', [ - 'headers' => [ - 'Authorization' => 'Bearer '. $this->happyscribeToken - ], - 'json' => [ - 'transcription' => [ - 'name' => $record->get_title(), - 'is_subtitle' => true, - 'language' => $languageSource, - 'organization_id' => $organizationId, - 'tmp_url' => $tmpUrl + try { + $responseTranscription = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/transcriptions', [ + 'headers' => [ + 'Authorization' => 'Bearer '. $this->happyscribeToken + ], + 'json' => [ + 'transcription' => [ + 'name' => $record->get_title(), + 'is_subtitle' => true, + 'language' => $payload['languageSource'], + 'organization_id' => $organizationId, + 'tmp_url' => $tmpUrl + ] ] - ] - ]); + ]); + + } catch (\Exception $e) { + $this->logger->error("error when creating transcript : " . $e->getMessage()); + $this->jobFinished(); + + return 0; + } if ($responseTranscription->getStatusCode() !== 200) { $this->logger->error("error when creating transcript,response status : ". $responseTranscription->getStatusCode()); @@ -212,7 +218,7 @@ public function process(array $payload) foreach ($payload['languageDestination'] as $language => $metaStructureIdDestination) { $languageDestination = strtolower($language); - if (strtolower($payload['languageSource']) == $languageDestination) { + if ($this->getTargetLanguageByCode($payload['languageSource']) == $languageDestination) { $metadatas[] = [ 'meta_struct_id' => (int)$metaStructureIdDestination, 'meta_id' => '', @@ -244,9 +250,9 @@ public function process(array $payload) // delete transcription - foreach ($this->transcriptionsId as $transcriptionId) { - $this->deleteTranscription($transcriptionId); - } +// foreach ($this->transcriptionsId as $transcriptionId) { +// $this->deleteTranscription($transcriptionId); +// } $this->jobFinished(); @@ -277,19 +283,6 @@ private function jobFinished() } } - private function getLanguageFormat($language) - { - switch ($language) { - case 'En': - return 'en-GB'; - case 'De': - return 'de-DE'; - case 'Fr': - default: - return 'fr-FR'; - } - } - private function isRemoteFileExist($fileUrl) { $client = new Client(); @@ -384,23 +377,29 @@ private function exportTranscription($transcriptionId) $transcriptContent = file_get_contents($subtitleTranscriptTemporaryFile); - $transcriptContent = preg_replace('/WEBVTT/', 'WEBVTT - with cue identifier', $transcriptContent, 1); - return $transcriptContent; } private function translate($sourceTranscriptionId, $targetLanguage) { // translate - $resTranslate = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/task/transcription_translation', [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $this->happyscribeToken - ], - 'json' => [ - 'source_transcription_id' => $sourceTranscriptionId, - 'target_language' => strtolower($targetLanguage) - ] - ]); + try { + $resTranslate = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/task/transcription_translation', [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->happyscribeToken + ], + 'json' => [ + 'source_transcription_id' => $sourceTranscriptionId, + 'target_language' => strtolower($targetLanguage) + ] + ]); + } catch (\Exception $e) { + $this->logger->error("error when translate : ". $e->getMessage()); + $this->jobFinished(); + + return 0; + } + if ($resTranslate->getStatusCode() !== 200) { $this->logger->error("error when translate, response status : ". $resTranslate->getStatusCode()); @@ -470,4 +469,11 @@ private function deleteTranscription($transcriptionId) ] ]); } + + private function getTargetLanguageByCode($code) + { + $t = explode('-', $code); + + return $t[0]; + } } diff --git a/templates/web/prod/actions/Tools/videoEditor.html.twig b/templates/web/prod/actions/Tools/videoEditor.html.twig index 57ffcf75af..f3fc5ee52c 100644 --- a/templates/web/prod/actions/Tools/videoEditor.html.twig +++ b/templates/web/prod/actions/Tools/videoEditor.html.twig @@ -229,7 +229,7 @@

@@ -241,8 +241,8 @@

@@ -373,8 +373,7 @@ data: { databox_id: {{ record.getDataboxId }}, record_id: {{ record.getRecordId }}, - subtitle_language_source: $('#subtitle_language_source option:selected').text(), - meta_struct_id_source: $('#subtitle_language_source').val(), + subtitle_language_source: $('#subtitle_language_source').val(), subtitle_destination: JSON.stringify(destination), }, success: function success(data) {