/**
  * Parse content of caption asset and index it
  *
  * @action parse
  * @param string $captionAssetId
  * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND
  */
 function parseAction($captionAssetId)
 {
     $captionAsset = assetPeer::retrieveById($captionAssetId);
     if (!$captionAsset) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     $captionAssetItems = CaptionAssetItemPeer::retrieveByAssetId($captionAssetId);
     foreach ($captionAssetItems as $captionAssetItem) {
         /* @var $captionAssetItem CaptionAssetItem */
         $captionAssetItem->delete();
     }
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $content = kFileSyncUtils::file_get_contents($syncKey, true, false);
     if (!$content) {
         return;
     }
     $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
     $itemsData = $captionsContentManager->parse($content);
     foreach ($itemsData as $itemData) {
         $item = new CaptionAssetItem();
         $item->setCaptionAssetId($captionAsset->getId());
         $item->setEntryId($captionAsset->getEntryId());
         $item->setPartnerId($captionAsset->getPartnerId());
         $item->setStartTime($itemData['startTime']);
         $item->setEndTime($itemData['endTime']);
         $item->setContent(utf8_encode($itemData['content']));
         $item->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Parse content of caption asset and index it
  *
  * @action parse
  * @param string $captionAssetId
  * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND
  */
 function parseAction($captionAssetId)
 {
     $captionAsset = assetPeer::retrieveById($captionAssetId);
     if (!$captionAsset) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     $captionAssetItems = CaptionAssetItemPeer::retrieveByAssetId($captionAssetId);
     foreach ($captionAssetItems as $captionAssetItem) {
         /* @var $captionAssetItem CaptionAssetItem */
         $captionAssetItem->delete();
     }
     // make sure that all old items are deleted from the sphinx before creating the new ones
     kEventsManager::flushEvents();
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $content = kFileSyncUtils::file_get_contents($syncKey, true, false);
     if (!$content) {
         return;
     }
     $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
     if (!$captionsContentManager) {
         return;
     }
     $itemsData = $captionsContentManager->parse($content);
     foreach ($itemsData as $itemData) {
         $item = new CaptionAssetItem();
         $item->setCaptionAssetId($captionAsset->getId());
         $item->setEntryId($captionAsset->getEntryId());
         $item->setPartnerId($captionAsset->getPartnerId());
         $item->setStartTime($itemData['startTime']);
         $item->setEndTime($itemData['endTime']);
         $content = '';
         foreach ($itemData['content'] as $curChunk) {
             $content .= $curChunk['text'];
         }
         //Make sure there are no invalid chars in the caption asset items to avoid braking the search request by providing invalid XML
         $content = kString::stripUtf8InvalidChars($content);
         $content = kXml::stripXMLInvalidChars($content);
         $item->setContent($content);
         $item->save();
     }
 }
Ejemplo n.º 3
0
 /**
  * Serves caption by its id converting it to segmented WebVTT
  *
  * @action serveWebVTT
  * @param string $captionAssetId
  * @param int $segmentDuration
  * @param int $segmentIndex
  * @param int $localTimestamp
  * @return file
  *
  * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND
  */
 public function serveWebVTTAction($captionAssetId, $segmentDuration = 30, $segmentIndex = null, $localTimestamp = 10000)
 {
     $captionAsset = $this->validateForDownload($captionAssetId);
     if (!$segmentIndex) {
         entryPeer::setUseCriteriaFilter(false);
         $entry = entryPeer::retrieveByPK($captionAsset->getEntryId());
         if (!$entry) {
             throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ENTRY_ID_NOT_FOUND, $captionAsset->getEntryId());
         }
         entryPeer::setUseCriteriaFilter(true);
         return new kRendererString(kWebVTTGenerator::buildWebVTTM3U8File($segmentDuration, (int) $entry->getDuration()), 'application/x-mpegurl');
     }
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $content = kFileSyncUtils::file_get_contents($syncKey, true, false, self::MAX_SERVE_WEBVTT_FILE_SIZE);
     if (!$content) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_FILE_NOT_FOUND, $captionAssetId);
     }
     $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
     if (!$captionsContentManager) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_INVALID_FORMAT, $captionAssetId);
     }
     $parsedCaption = $captionsContentManager->parse($content);
     if (!$parsedCaption) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_PARSING_FAILED, $captionAssetId);
     }
     return new kRendererString(kWebVTTGenerator::buildWebVTTSegment($parsedCaption, $segmentIndex, $segmentDuration, $localTimestamp), 'text/vtt');
 }
Ejemplo n.º 4
0
 public static function getCaptionSearchData(entry $entry)
 {
     $captionAssets = assetPeer::retrieveByEntryId($entry->getId(), array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)));
     if (!$captionAssets || !count($captionAssets)) {
         return null;
     }
     $data = array();
     foreach ($captionAssets as $captionAsset) {
         /* @var $captionAsset CaptionAsset */
         $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $content = kFileSyncUtils::file_get_contents($syncKey, true, false);
         if (!$content) {
             continue;
         }
         $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
         if (!$captionsContentManager) {
             KalturaLog::err("Captions content manager not found for format [" . $captionAsset->getContainerFormat() . "]");
             continue;
         }
         $content = $captionsContentManager->getContent($content);
         if (!$content) {
             continue;
         }
         $data[] = $captionAsset->getId() . " ca_prefix {$content} ca_sufix";
     }
     $dataField = CaptionSearchPlugin::getSearchFieldName(CaptionSearchPlugin::SEARCH_FIELD_DATA);
     $searchValues = array($dataField => CaptionSearchPlugin::PLUGIN_NAME . ' ' . implode(' ', $data) . ' ' . CaptionSearchPlugin::SEARCH_TEXT_SUFFIX);
     return $searchValues;
 }