protected function submitCaption(Google_Service_YouTube $youtube, KalturaYouTubeApiCaptionDistributionInfo $captionInfo, $remoteId)
 {
     if (!file_exists($captionInfo->filePath)) {
         throw new KalturaDistributionException("The caption file [{$captionInfo->filePath}] was not found (probably not synced yet), the job will retry");
     }
     $captionSnippet = new Google_Service_YouTube_CaptionSnippet();
     $captionSnippet->setVideoId($remoteId);
     $captionSnippet->setLanguage($captionInfo->language);
     $captionSnippet->setName($captionInfo->label);
     $caption = new Google_Service_YouTube_Caption();
     $caption->setSnippet($captionSnippet);
     $chunkSizeBytes = 1 * 1024 * 1024;
     $youtube->getClient()->setDefer(true);
     $insertRequest = $youtube->captions->insert('snippet', $caption);
     $media = new Google_Http_MediaFileUpload($youtube->getClient(), $insertRequest, '*/*', null, true, $chunkSizeBytes);
     $media->setFileSize(filesize($captionInfo->filePath));
     $ingestedCaption = false;
     $handle = fopen($captionInfo->filePath, "rb");
     while (!$ingestedCaption && !feof($handle)) {
         $chunk = fread($handle, $chunkSizeBytes);
         $ingestedCaption = $media->nextChunk($chunk);
     }
     fclose($handle);
     $youtube->getClient()->setDefer(false);
     $remoteMediaFile = new KalturaDistributionRemoteMediaFile();
     $remoteMediaFile->remoteId = $ingestedCaption['id'];
     $remoteMediaFile->version = $captionInfo->version;
     $remoteMediaFile->assetId = $captionInfo->assetId;
     return $remoteMediaFile;
 }
Exemple #2
0
 /**
  * Constructor
  * @param GoogleClient $client
  */
 public function __construct(GoogleClient $client)
 {
     $this->client = $client;
     parent::__construct($client->getGoogleClient());
 }