mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 10:23:17 +00:00
set ginga config
This commit is contained in:
@@ -328,6 +328,12 @@ workers:
|
|||||||
password: guest
|
password: guest
|
||||||
vhost: /
|
vhost: /
|
||||||
|
|
||||||
|
externalservice:
|
||||||
|
ginga:
|
||||||
|
service_base_url: https://base.uri
|
||||||
|
token: 39c6011d
|
||||||
|
transcript_format: text/vtt
|
||||||
|
|
||||||
user_account:
|
user_account:
|
||||||
deleting_policies:
|
deleting_policies:
|
||||||
email_confirmation: true
|
email_confirmation: true
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class AlchemyWorkerServiceProvider implements PluginProviderInterface
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
$app['alchemy_worker.type_based_worker_resolver']->addFactory(MessagePublisher::SUBTITLE_TYPE, new CallableWorkerFactory(function () use ($app) {
|
$app['alchemy_worker.type_based_worker_resolver']->addFactory(MessagePublisher::SUBTITLE_TYPE, new CallableWorkerFactory(function () use ($app) {
|
||||||
return new SubtitleWorker($app['repo.worker-job'], new LazyLocator($app, 'phraseanet.appbox'), $app['alchemy_worker.logger']);
|
return new SubtitleWorker($app['repo.worker-job'], $app['conf'], new LazyLocator($app, 'phraseanet.appbox'), $app['alchemy_worker.logger']);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$app['alchemy_worker.type_based_worker_resolver']->addFactory(MessagePublisher::MAIN_QUEUE_TYPE, new CallableWorkerFactory(function () use ($app) {
|
$app['alchemy_worker.type_based_worker_resolver']->addFactory(MessagePublisher::MAIN_QUEUE_TYPE, new CallableWorkerFactory(function () use ($app) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\WorkerManager\Worker;
|
namespace Alchemy\Phrasea\WorkerManager\Worker;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
||||||
use Alchemy\Phrasea\Model\Entities\WorkerJob;
|
use Alchemy\Phrasea\Model\Entities\WorkerJob;
|
||||||
use Alchemy\Phrasea\Model\Repositories\WorkerJobRepository;
|
use Alchemy\Phrasea\Model\Repositories\WorkerJobRepository;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
@@ -9,29 +10,37 @@ use Psr\Log\LoggerInterface;
|
|||||||
|
|
||||||
class SubtitleWorker implements WorkerInterface
|
class SubtitleWorker implements WorkerInterface
|
||||||
{
|
{
|
||||||
const GINGER_BASE_URL = "https://test.api.ginger.studio/recognition/speech";
|
|
||||||
const GINGER_TOKEN = "39c6011d-3bbe-4f39-95d0-a327d320ded4";
|
|
||||||
const GINGER_TRANSCRIPT_FORMAT = "text/vtt";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var callable
|
* @var callable
|
||||||
*/
|
*/
|
||||||
private $appboxLocator;
|
private $appboxLocator;
|
||||||
|
|
||||||
private $logger;
|
private $logger;
|
||||||
|
private $conf;
|
||||||
|
|
||||||
/** @var WorkerJobRepository $repoWorkerJob*/
|
/** @var WorkerJobRepository $repoWorkerJob*/
|
||||||
private $repoWorkerJob;
|
private $repoWorkerJob;
|
||||||
|
|
||||||
public function __construct(WorkerJobRepository $repoWorkerJob, callable $appboxLocator, LoggerInterface $logger)
|
public function __construct(WorkerJobRepository $repoWorkerJob, PropertyAccess $conf, callable $appboxLocator, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->repoWorkerJob = $repoWorkerJob;
|
$this->repoWorkerJob = $repoWorkerJob;
|
||||||
|
$this->conf = $conf;
|
||||||
$this->appboxLocator = $appboxLocator;
|
$this->appboxLocator = $appboxLocator;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(array $payload)
|
public function process(array $payload)
|
||||||
{
|
{
|
||||||
|
$gingaBaseurl = $this->conf->get(['externalservice', 'ginga', 'service_base_url']);
|
||||||
|
$gingaToken = $this->conf->get(['externalservice', 'ginga', 'token']);
|
||||||
|
$gingaTranscriptFormat = $this->conf->get(['externalservice', 'ginga', 'transcript_format']);
|
||||||
|
|
||||||
|
if (!$gingaBaseurl || !$gingaToken || !$gingaTranscriptFormat) {
|
||||||
|
$this->logger->error("External service Ginga not set correctly in configuration.yml");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var WorkerJob $workerJob */
|
/** @var WorkerJob $workerJob */
|
||||||
$workerJob = $this->repoWorkerJob->find($payload['workerId']);
|
$workerJob = $this->repoWorkerJob->find($payload['workerId']);
|
||||||
if ($workerJob == null) {
|
if ($workerJob == null) {
|
||||||
@@ -67,9 +76,9 @@ class SubtitleWorker implements WorkerInterface
|
|||||||
$gingerClient = new Client();
|
$gingerClient = new Client();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $gingerClient->post(self::GINGER_BASE_URL.'/media/', [
|
$response = $gingerClient->post($gingaBaseurl.'/media/', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'token '.self::GINGER_TOKEN
|
'Authorization' => 'token '.$gingaToken
|
||||||
],
|
],
|
||||||
'json' => [
|
'json' => [
|
||||||
'url' => $payload['permalinkUrl'],
|
'url' => $payload['permalinkUrl'],
|
||||||
@@ -99,9 +108,9 @@ class SubtitleWorker implements WorkerInterface
|
|||||||
sleep(5);
|
sleep(5);
|
||||||
$this->logger->info("bigin to check status");
|
$this->logger->info("bigin to check status");
|
||||||
try {
|
try {
|
||||||
$response = $gingerClient->get(self::GINGER_BASE_URL.'/task/'.$responseMediaBody['task_id'].'/', [
|
$response = $gingerClient->get($gingaBaseurl.'/task/'.$responseMediaBody['task_id'].'/', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'token '.self::GINGER_TOKEN
|
'Authorization' => 'token '.$gingaToken
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -129,10 +138,10 @@ class SubtitleWorker implements WorkerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $gingerClient->get(self::GINGER_BASE_URL.'/media/'.$responseMediaBody['media']['uuid'].'/', [
|
$response = $gingerClient->get($gingaBaseurl.'/media/'.$responseMediaBody['media']['uuid'].'/', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'token '.self::GINGER_TOKEN,
|
'Authorization' => 'token '.$gingaToken,
|
||||||
'ACCEPT' => self::GINGER_TRANSCRIPT_FORMAT
|
'ACCEPT' => $gingaTranscriptFormat
|
||||||
],
|
],
|
||||||
'query' => [
|
'query' => [
|
||||||
'language' => $language
|
'language' => $language
|
||||||
|
|||||||
Reference in New Issue
Block a user