add subdef_source in config

This commit is contained in:
aynsix
2020-07-06 18:23:42 +03:00
parent 22302982a4
commit 8f3f3845c0
3 changed files with 26 additions and 8 deletions

View File

@@ -329,10 +329,12 @@ workers:
vhost: / vhost: /
externalservice: externalservice:
ginga: ginger:
service_base_url: https://base.uri AutoSubtitling:
token: 39c6011d service_base_url: https://base.uri
transcript_format: text/vtt token: 39c6011d
transcript_format: text/vtt
subdef_source: preview
user_account: user_account:
deleting_policies: deleting_policies:

View File

@@ -457,7 +457,12 @@ class ToolsController extends Controller
); );
$permalinkUrl = ''; $permalinkUrl = '';
if ($record->has_preview() && ($previewLink = $record->get_preview()->get_permalink()) != null) { $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(); $permalinkUrl = $previewLink->get_url()->__toString();
} }
@@ -524,4 +529,15 @@ class ToolsController extends Controller
'videoTextTrackFields' => $videoTextTrackFields 'videoTextTrackFields' => $videoTextTrackFields
]); ]);
} }
private function isPhysicallyPresent(\record_adapter $record, $subdefName)
{
try {
return $record->get_subdef($subdefName)->is_physically_present();
} catch (\Exception $e) {
unset($e);
}
return false;
}
} }

View File

@@ -31,9 +31,9 @@ class SubtitleWorker implements WorkerInterface
public function process(array $payload) public function process(array $payload)
{ {
$gingaBaseurl = $this->conf->get(['externalservice', 'ginga', 'service_base_url']); $gingaBaseurl = $this->conf->get(['externalservice', 'ginger', 'AutoSubtitling', 'service_base_url']);
$gingaToken = $this->conf->get(['externalservice', 'ginga', 'token']); $gingaToken = $this->conf->get(['externalservice', 'ginger', 'AutoSubtitling', 'token']);
$gingaTranscriptFormat = $this->conf->get(['externalservice', 'ginga', 'transcript_format']); $gingaTranscriptFormat = $this->conf->get(['externalservice', 'ginger', 'AutoSubtitling', 'transcript_format']);
if (!$gingaBaseurl || !$gingaToken || !$gingaTranscriptFormat) { if (!$gingaBaseurl || !$gingaToken || !$gingaTranscriptFormat) {
$this->logger->error("External service Ginga not set correctly in configuration.yml"); $this->logger->error("External service Ginga not set correctly in configuration.yml");