Skip to content

Commit

Permalink
fix(27178): check if same caption with name and language was uploaded…
Browse files Browse the repository at this point in the history
… and remove it and then upload the newest
  • Loading branch information
Yurujai committed Aug 20, 2024
1 parent 2b88483 commit 7859861
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Services/CaptionsInsertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ class CaptionsInsertService extends GoogleCaptionService
{
private $documentManager;
private $googleAccountService;

private $captionsDeleteService;
private $captionsListService;
private $logger;

public function __construct(
DocumentManager $documentManager,
GoogleAccountService $googleAccountService,
CaptionsDeleteService $captionsDeleteService,
CaptionsListService $captionsListService,
LoggerInterface $logger
) {
$this->documentManager = $documentManager;
$this->googleAccountService = $googleAccountService;
$this->captionsDeleteService = $captionsDeleteService;
$this->captionsListService = $captionsListService;
$this->logger = $logger;
}

Expand All @@ -50,6 +55,15 @@ public function uploadCaption(Youtube $youtube, MultimediaObject $multimediaObje
'properties.login' => $youtube->getYoutubeAccount(),
]);

if (!empty($youtube->getCaptionUpdateError()) && $youtube->getCaptionUpdateError()->id() === 'captionExists') {
$captionsUploaded = $this->captionsListService->findAll($account, $videoId);
foreach ($captionsUploaded->getItems() as $caption) {
if($caption->getSnippet()->getName() === $material->getName() && $caption->getSnippet()->getLanguage() === $material->getLanguage()) {
$this->captionsDeleteService->deleteCaption($account, $youtube, [$caption->getId()]);
}
}
}

$result = $this->insert($account, $material, $youtube->getYoutubeId());

$caption = $this->createCaptionDocument($material, $result);
Expand Down

0 comments on commit 7859861

Please sign in to comment.