Esempio n. 1
0
 public function getLocalThumbFilePath($version, $width, $height, $type, $bgcolor = "ffffff", $crop_provider = null, $quality = 0, $src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $density = 0, $stripProfiles = false, $flavorId = null, $fileName = null)
 {
     if ($this->getStatus() == entryStatus::DELETED || $this->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK) {
         KalturaLog::log("rejected live stream entry - not serving thumbnail");
         KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
     }
     $contentPath = myContentStorage::getFSContentRootPath();
     $liveEntryExist = false;
     $liveThumbEntry = null;
     $liveThumbEntryId = null;
     $partner = $this->getPartner();
     if ($partner) {
         $liveThumbEntryId = $partner->getLiveThumbEntryId();
     }
     if ($liveThumbEntryId) {
         $liveThumbEntry = entryPeer::retrieveByPK($liveThumbEntryId);
     }
     if ($liveThumbEntry && $liveThumbEntry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $fileSyncVersion = $partner->getLiveThumbEntryVersion();
         $liveEntryKey = $liveThumbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $fileSyncVersion);
         $contentPath = kFileSyncUtils::getLocalFilePathForKey($liveEntryKey);
         if ($contentPath) {
             $msgPath = $contentPath;
             $liveEntryExist = true;
         } else {
             KalturaLog::err('no local file sync for audio entry id');
         }
     }
     if (!$liveEntryExist) {
         $msgPath = $contentPath . "content/templates/entry/thumbnail/live_thumb.jpg";
     }
     return myEntryUtils::resizeEntryImage($this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $msgPath, $density, $stripProfiles);
 }
 private function addEcSeek($url, $syncKey)
 {
     $seekTime = $this->params->getSeekFromTime();
     if (!empty($seekTime)) {
         // remove default seekFrom parameter
         $url = preg_replace('/seekFrom\\/-?[0-9]*\\/?/', '', $url);
         $url = rtrim($url, '/');
         // check if seekFromTime is set to something significant
         if ($seekTime > 0) {
             // check if flv or not
             $extension = $this->params->getFileExtension();
             $containerFormat = $this->params->getContainerFormat();
             $notFlvFormat = $extension && strtolower($extension) != 'flv' || $containerFormat && strtolower($containerFormat) != 'flash video';
             if ($notFlvFormat) {
                 // not flv - add ec_seek value in seconds
                 $url .= '?ec_seek=' . $seekTime / 1000;
                 // convert milliseconds to seconds
             } else {
                 // flv - add ec_seek value in bytes
                 $url .= '?ec_seek=' . $this->getSeekFromBytes(kFileSyncUtils::getLocalFilePathForKey($syncKey));
             }
         }
     }
     return $url;
 }
Esempio n. 3
0
 /**
  * @param flavorAsset $flavorAsset
  * @return string
  */
 public function getFlavorAssetUrl(flavorAsset $flavorAsset)
 {
     $entry = $flavorAsset->getentry();
     $partnerId = $entry->getPartnerId();
     $subpId = $entry->getSubpId();
     $flavorAssetId = $flavorAsset->getId();
     $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
     $this->setFileExtension($flavorAsset->getFileExt());
     $url = "/s{$partnerPath}/serveFlavor/flavorId/{$flavorAssetId}";
     if ($this->clipTo) {
         $url .= "/clipTo/{$this->clipTo}";
     }
     if ($this->extention) {
         $url .= "/name/{$flavorAssetId}.{$this->extention}";
     }
     $url = str_replace('\\', '/', $url);
     if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) {
         $url .= '?novar=0';
         $url .= '&e=' . (time() + 120);
         $secret = $this->getMediaVault();
         $fullUrl = $this->protocol . '://' . $this->domain . $url;
         $url .= '&h=' . md5($secret . $fullUrl);
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $seekFromBytes = $this->getSeekFromBytes(kFileSyncUtils::getLocalFilePathForKey($syncKey));
         if ($seekFromBytes) {
             $url .= '&fs=' . $seekFromBytes;
         }
     } else {
         $url .= '/forceproxy/true';
     }
     return $url;
 }
 /**
  * @action sync
  * @param int $fileSyncId
  * @param file $fileData
  * @return KalturaFileSync
  */
 function syncAction($fileSyncId, $fileData)
 {
     $dbFileSync = FileSyncPeer::retrieveByPK($fileSyncId);
     if (!$dbFileSync) {
         throw new APIException(APIErrors::INVALID_FILE_SYNC_ID, $fileSyncId);
     }
     $key = kFileSyncUtils::getKeyForFileSync($dbFileSync);
     kFileSyncUtils::moveFromFile($fileData['tmp_name'], $key, false);
     list($file_root, $real_path) = kPathManager::getFilePathArr($key);
     $full_path = $file_root . $real_path;
     chmod($full_path, 0644);
     if (file_exists($full_path)) {
         $dbFileSync->setFileRoot($file_root);
         $dbFileSync->setFilePath($real_path);
         $dbFileSync->setFileSizeFromPath($full_path);
         $dbFileSync->setStatus(FileSync::FILE_SYNC_STATUS_READY);
     } else {
         $dbFileSync->setFileSize(-1);
         $dbFileSync->setStatus(FileSync::FILE_SYNC_STATUS_ERROR);
     }
     $dbFileSync->save();
     $fileSync = new KalturaFileSync();
     $fileSync->fromObject($dbFileSync);
     return $fileSync;
 }
 public function execute()
 {
     $this->forceSystemAuthentication();
     myDbHelper::$use_alternative_con = null;
     //myDbHelper::DB_HELPER_CONN_PROPEL2
     $uiConfId = $this->getRequestParameter("id");
     $uiConf = uiConfPeer::retrieveByPK($uiConfId);
     $subTypes = array(uiconf::FILE_SYNC_UICONF_SUB_TYPE_DATA, uiconf::FILE_SYNC_UICONF_SUB_TYPE_FEATURES);
     foreach ($subTypes as $subType) {
         if ($subType == uiconf::FILE_SYNC_UICONF_SUB_TYPE_DATA) {
             echo "Data:" . PHP_EOL;
         } else {
             if ($subType == uiconf::FILE_SYNC_UICONF_SUB_TYPE_FEATURES) {
                 echo "Features:" . PHP_EOL;
             }
         }
         $syncKey = $uiConf->getSyncKey($subType);
         if (kFileSyncUtils::file_exists($syncKey)) {
             echo "File sync already exists." . PHP_EOL;
         } else {
             list($rootPath, $filePath) = $uiConf->generateFilePathArr($subType);
             $fullPath = $rootPath . $filePath;
             if (file_exists($fullPath)) {
                 kFileSyncUtils::createSyncFileForKey($syncKey);
                 echo "Created successfully." . PHP_EOL;
             } else {
                 echo "File not found:" . PHP_EOL;
                 echo $fullPath . PHP_EOL;
                 echo "Not creating file sync." . PHP_EOL;
             }
         }
         echo PHP_EOL;
     }
     die;
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaDailymotionDistributionProfile) {
         return;
     }
     $flavorAssets = flavorAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         // if we have specific flavor assets for this distribution, grab the first one
         $flavorAsset = reset($flavorAssets);
     } else {
         // take the source asset
         $flavorAsset = flavorAssetPeer::retrieveOriginalReadyByEntryId($distributionJobData->entryDistribution->entryId);
     }
     if ($flavorAsset) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true);
     }
     $thumbAssets = thumbAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $syncKey = reset($thumbAssets)->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true);
     }
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($dbEntry->getId());
     $syncKey = $originalFlavorAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     // call mediaInfo for file
     $dbMediaInfo = new mediaInfo();
     try {
         $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
         $mediaInfo = $mediaInfoParser->getMediaInfo();
         $dbMediaInfo = $mediaInfo->toInsertableObject($dbMediaInfo);
         $dbMediaInfo->setFlavorAssetId($originalFlavorAsset->getId());
         $dbMediaInfo->save();
     } catch (Exception $e) {
         KalturaLog::err("Getting media info: " . $e->getMessage());
         $dbMediaInfo = null;
     }
     // fix flavor asset according to mediainfo
     if ($dbMediaInfo) {
         KDLWrap::ConvertMediainfoCdl2FlavorAsset($dbMediaInfo, $originalFlavorAsset);
         $flavorTags = KDLWrap::CDLMediaInfo2Tags($dbMediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
         $originalFlavorAsset->setTags(implode(',', array_unique($flavorTags)));
     }
     $originalFlavorAsset->setStatusLocalReady();
     $originalFlavorAsset->save();
     $dbEntry->setStatus(entryStatus::READY);
     $dbEntry->save();
 }
 /**
  * @param flavorAsset $flavorAsset
  * @return string
  */
 protected function doGetFlavorAssetUrl(flavorAsset $flavorAsset)
 {
     $entry = $flavorAsset->getentry();
     $partnerId = $entry->getPartnerId();
     $subpId = $entry->getSubpId();
     $flavorAssetId = $flavorAsset->getId();
     $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
     $this->setFileExtension($flavorAsset->getFileExt());
     $versionString = $this->getFlavorVersionString($flavorAsset);
     $url = "/s{$partnerPath}/serveFlavor/entryId/" . $flavorAsset->getEntryId() . "{$versionString}/flavorId/{$flavorAssetId}";
     if ($this->clipTo) {
         $url .= "/clipTo/{$this->clipTo}";
     }
     if ($this->extention) {
         $url .= "/name/a.{$this->extention}";
     }
     $url = str_replace('\\', '/', $url);
     if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) {
         $url .= '?novar=0';
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $seekFromBytes = $this->getSeekFromBytes(kFileSyncUtils::getLocalFilePathForKey($syncKey));
         if ($seekFromBytes) {
             $url .= '&fs=' . $seekFromBytes;
         }
     } else {
         if ($this->extention && strtolower($this->extention) != 'flv' || $this->containerFormat && strtolower($this->containerFormat) != 'flash video') {
             $url = "mp4:{$url}";
         }
     }
     return $url;
 }
 /**
  * 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();
     }
 }
 /**
  * @param CaptionAsset $captionAsset
  * @param BatchJob $parentJob
  * @throws kCoreException FILE_NOT_FOUND
  * @return BatchJob
  */
 public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null)
 {
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     if (!$fileSync) {
         if (!PermissionPeer::isValidForPartner(CaptionPermissionName::IMPORT_REMOTE_CAPTION_FOR_INDEXING, $captionAsset->getPartnerId())) {
             throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
         }
         $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
         if (!$fileSync) {
             throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
         }
         $fullPath = myContentStorage::getFSUploadsPath() . '/' . $captionAsset->getId() . '.tmp';
         if (!kFile::downloadUrlToFile($fileSync->getExternalUrl($captionAsset->getEntryId()), $fullPath)) {
             throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
         }
         kFileSyncUtils::moveFromFile($fullPath, $syncKey, true, false, true);
     }
     $jobData = new kParseCaptionAssetJobData();
     $jobData->setCaptionAssetId($captionAsset->getId());
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild();
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($captionAsset->getEntryId());
         $batchJob->setPartnerId($captionAsset->getPartnerId());
     }
     return kJobsManager::addJob($batchJob, $jobData, CaptionSearchPlugin::getBatchJobTypeCoreValue(CaptionSearchBatchJobType::PARSE_CAPTION_ASSET));
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaQuickPlayDistributionProfile) {
         return;
     }
     $this->videoFilePaths = new KalturaStringArray();
     $this->thumbnailFilePaths = new KalturaStringArray();
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     $entry = entryPeer::retrieveByPK($distributionJobData->entryDistribution->entryId);
     foreach ($flavorAssets as $asset) {
         $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $str = new KalturaString();
             $str->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $this->videoFilePaths[] = $str;
         }
     }
     foreach ($thumbAssets as $asset) {
         $syncKey = $asset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $str = new KalturaString();
             $str->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $this->thumbnailFilePaths[] = $str;
         }
     }
     $feed = new QuickPlayFeed($distributionJobData, $this, $flavorAssets, $thumbAssets, $entry);
     $this->xml = $feed->getXml();
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaFreewheelGenericDistributionProfile) {
         return;
     }
     $this->videoAssetFilePaths = new KalturaStringArray();
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     foreach ($flavorAssets as $flavorAsset) {
         $videoAssetFilePath = new KalturaString();
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $videoAssetFilePath->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         $this->videoAssetFilePaths[] = $videoAssetFilePath;
     }
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbAsset = reset($thumbAssets);
         $syncKey = $thumbAssets->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     // entry cue points
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $distributionJobData->entryDistribution->partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $distributionJobData->entryDistribution->entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $cuePointsDb = CuePointPeer::doSelect($c);
     $this->cuePoints = KalturaCuePointArray::fromDbArray($cuePointsDb);
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaUverseDistributionProfile) {
         return;
     }
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         // if we have specific flavor assets for this distribution, grab the first one
         $flavorAsset = reset($flavorAssets);
     } else {
         // take the source asset
         $flavorAsset = assetPeer::retrieveOriginalReadyByEntryId($distributionJobData->entryDistribution->entryId);
     }
     if ($flavorAsset) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->localAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
     }
     $entryDistributionDb = EntryDistributionPeer::retrieveByPK($distributionJobData->entryDistributionId);
     if ($entryDistributionDb) {
         $this->remoteAssetUrl = $entryDistributionDb->getFromCustomData(UverseEntryDistributionCustomDataField::REMOTE_ASSET_URL);
         $this->remoteAssetFileName = $entryDistributionDb->getFromCustomData(UverseEntryDistributionCustomDataField::REMOTE_ASSET_FILE_NAME);
     } else {
         KalturaLog::err('Entry distribution [' . $distributionJobData->entryDistributionId . '] not found');
     }
 }
 public function validateEntry(entry $dbEntry)
 {
     parent::validateEntry($dbEntry);
     $this->validatePropertyNotNull('entryId');
     $srcEntry = entryPeer::retrieveByPK($this->entryId);
     if (!$srcEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryId);
     }
     if ($srcEntry->getMediaType() == KalturaMediaType::IMAGE) {
         return parent::validateEntry($dbEntry);
     }
     $srcFlavorAsset = null;
     if (is_null($this->flavorParamsId)) {
         $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
         }
     } else {
         $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $this->assetId);
         }
     }
     $key = $srcFlavorAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     $c->addAnd(FileSyncPeer::FILE_TYPE, array(FileSync::FILE_SYNC_FILE_TYPE_FILE, FileSync::FILE_SYNC_FILE_TYPE_LINK), Criteria::IN);
     $fileSyncs = FileSyncPeer::doSelect($c);
     foreach ($fileSyncs as $fileSync) {
         $fileSync = kFileSyncUtils::resolve($fileSync);
         if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_FILE) {
             return;
         }
     }
     throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
 }
 protected function copyLiveMetadata(baseEntry $object, $liveEntryId)
 {
     $recordedEntryId = $object->getId();
     $partnerId = $object->getPartnerId();
     $metadataProfiles = MetadataProfilePeer::retrieveAllActiveByPartnerId($partnerId, MetadataObjectType::ENTRY);
     foreach ($metadataProfiles as $metadataProfile) {
         $originMetadataObj = MetadataPeer::retrieveByObject($metadataProfile->getId(), MetadataObjectType::ENTRY, $liveEntryId);
         if ($originMetadataObj) {
             $metadataProfileId = $metadataProfile->getId();
             $metadataProfileVersion = $metadataProfile->getVersion();
             $destMetadataObj = new Metadata();
             $destMetadataObj->setPartnerId($partnerId);
             $destMetadataObj->setMetadataProfileId($metadataProfileId);
             $destMetadataObj->setMetadataProfileVersion($metadataProfileVersion);
             $destMetadataObj->setObjectType(MetadataObjectType::ENTRY);
             $destMetadataObj->setObjectId($recordedEntryId);
             $destMetadataObj->setStatus(KalturaMetadataStatus::VALID);
             $originMetadataKey = $originMetadataObj->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
             $originXml = kFileSyncUtils::file_get_contents($originMetadataKey, true, false);
             // validate object exists
             $object = kMetadataManager::getObjectFromPeer($destMetadataObj);
             if ($object) {
                 $destMetadataObj->save();
             } else {
                 KalturaLog::err('invalid object type');
                 continue;
             }
             $destMetadataKey = $destMetadataObj->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
             kFileSyncUtils::file_put_contents($destMetadataKey, $originXml);
         }
     }
 }
 public static function fromThumbAsset($thumbAsset)
 {
     $fileSyncKey = $thumbAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     $thumbPath = kFileSyncUtils::getReadyLocalFilePathForKey($fileSyncKey);
     $thumbWidth = $thumbAsset->getWidth();
     $thumbHeight = $thumbAsset->getHeight();
     return self::fromParams($thumbWidth, $thumbHeight, $thumbPath, false);
 }
 protected function doGetFlavorAssetUrl(flavorAsset $flavorAsset)
 {
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     $url = $this->getFileSyncUrl($fileSync);
     $url = $this->formatByExtension($url, false);
     return $url;
 }
 public function execute()
 {
     $jobId = $this->getRequestParameter("id");
     $partnerId = $this->getRequestParameter("pid");
     $type = $this->getRequestParameter("type");
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $jobId);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId);
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         die("File not found");
     }
     header("Content-Type: text/plain; charset=UTF-8");
     if ($type == "log") {
         $bulkUploadResults = BulkUploadResultPeer::retrieveByBulkUploadId($jobId);
         if (!count($bulkUploadResults)) {
             $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADLOG);
             if (kFileSyncUtils::file_exists($syncKey, true)) {
                 $content = kFileSyncUtils::file_get_contents($syncKey, true);
                 echo $content;
                 die;
             }
             die("Log file is not ready");
         }
         $STDOUT = fopen('php://output', 'w');
         $data = $batchJob->getData();
         foreach ($bulkUploadResults as $bulkUploadResult) {
             $values = array($bulkUploadResult->getTitle(), $bulkUploadResult->getDescription(), $bulkUploadResult->getTags(), $bulkUploadResult->getUrl(), $bulkUploadResult->getContentType());
             if ($data instanceof kBulkUploadJobData && $data->getCsvVersion() > kBulkUploadJobData::BULK_UPLOAD_CSV_VERSION_V1) {
                 $values[] = $bulkUploadResult->getConversionProfileId();
                 $values[] = $bulkUploadResult->getAccessControlProfileId();
                 $values[] = $bulkUploadResult->getCategory();
                 $values[] = $bulkUploadResult->getScheduleStartDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getScheduleEndDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getThumbnailUrl();
                 $values[] = $bulkUploadResult->getPartnerData();
             }
             $values[] = $bulkUploadResult->getEntryId();
             $values[] = $bulkUploadResult->getEntryStatus();
             $values[] = $bulkUploadResult->getErrorDescription();
             fputcsv($STDOUT, $values);
         }
         fclose($STDOUT);
     } else {
         $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV);
         if (kFileSyncUtils::file_exists($syncKey, true)) {
             $content = kFileSyncUtils::file_get_contents($syncKey, true);
             echo $content;
             die;
         } else {
             die("File not found");
         }
     }
     die;
     //  no template needed
 }
Esempio n. 19
0
 public function incLiveSegmentVersion($index)
 {
     $subType = self::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY;
     if ($index == MediaServerIndex::SECONDARY) {
         $subType = self::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY;
     }
     $newVersion = kFileSyncUtils::calcObjectNewVersion($this->getId(), $this->getLiveSegmentVersion($index), FileSyncObjectType::ASSET, $subType);
     $this->putInCustomData("liveSegmentVersion-{$index}", $newVersion);
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData || !$distributionJobData->distributionProfile instanceof KalturaTvinciDistributionProfile || !$distributionJobData->entryDistribution) {
         return;
     }
     $entry = null;
     if ($distributionJobData->entryDistribution->entryId) {
         $entry = entryPeer::retrieveByPK($distributionJobData->entryDistribution->entryId);
     }
     if (!$entry) {
         KalturaLog::err("Can't find entry with id: {$distributionJobData->entryDistribution->entryId}");
         return;
     }
     $feedHelper = new TvinciDistributionFeedHelper($distributionJobData->distributionProfile);
     $feedHelper->setEntryId($entry->getId());
     $feedHelper->setReferenceId($entry->getReferenceID());
     $feedHelper->setDescription($entry->getDescription());
     $feedHelper->setTitleName($entry->getName());
     $feedHelper->setSunrise($distributionJobData->entryDistribution->sunrise);
     $feedHelper->setSunset($distributionJobData->entryDistribution->sunset);
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     $picRatios = array();
     $defaultThumbUrl = null;
     foreach ($thumbAssets as $thumbAsset) {
         $thumbDownloadUrl = $this->getAssetDownloadUrl($thumbAsset);
         $ratio = KDLVideoAspectRatio::ConvertFrameSize($thumbAsset->getWidth(), $thumbAsset->getHeight());
         $picRatios[] = array('url' => $thumbDownloadUrl, 'ratio' => $ratio);
         if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             $defaultThumbUrl = $thumbDownloadUrl;
         }
     }
     $feedHelper->setPicRatiosArray($picRatios);
     if (!$defaultThumbUrl && count($picRatios)) {
         // Choose the URL of the first resource in the array
         $defaultThumbUrl = $picRatios[0]['url'];
     }
     $feedHelper->setDefaultThumbnailUrl($defaultThumbUrl);
     $this->createPlayManifestURLs($distributionJobData->entryDistribution, $entry, $feedHelper);
     $metadatas = MetadataPeer::retrieveAllByObject(MetadataObjectType::ENTRY, $distributionJobData->entryDistribution->entryId);
     $fullMetadataXML = '';
     foreach ($metadatas as $metadataField) {
         $syncKey = $metadataField->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         $currMetaXML = kFileSyncUtils::file_get_contents($syncKey, true, false);
         $fullMetadataXML .= $currMetaXML;
     }
     $feedHelper->setMetasXML($fullMetadataXML);
     if ($distributionJobData instanceof KalturaDistributionSubmitJobData) {
         $this->xml = $feedHelper->buildSubmitFeed();
     } elseif ($distributionJobData instanceof KalturaDistributionUpdateJobData) {
         $this->xml = $feedHelper->buildUpdateFeed();
     } elseif ($distributionJobData instanceof KalturaDistributionDeleteJobData) {
         $this->xml = $feedHelper->buildDeleteFeed();
     }
     KalturaLog::debug("XML Constructed by the Tvinci feed helper :{$this->xml}");
 }
 /**
  * @param FileSync $fileSync
  * @return string
  */
 protected function doGetFileSyncUrl(FileSync $fileSync)
 {
     $fileSync = kFileSyncUtils::resolve($fileSync);
     $url = parent::doGetFileSyncUrl($fileSync);
     $url = ltrim($url, '/');
     if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP) {
         return "/hls-vod/{$url}.m3u8";
     }
     return "/hds-vod/{$url}.f4m";
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaHuluDistributionProfile) {
         return;
     }
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $flavorAsset = reset($flavorAssets);
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbAsset = reset($thumbAssets);
         $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $additionalAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->assetIds));
     $this->captionLocalPaths = new KalturaStringArray();
     if (count($additionalAssets)) {
         $captionAssetFilePathArray = array();
         foreach ($additionalAssets as $additionalAsset) {
             $assetType = $additionalAsset->getType();
             $syncKey = $additionalAsset->getSyncKey(CaptionAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 if ($assetType == CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION) || $assetType == AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT)) {
                     $string = new KalturaString();
                     $string->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $this->captionLocalPaths[] = $string;
                 }
             }
         }
     }
     $tempFieldValues = unserialize($this->fieldValues);
     $pattern = '/[^A-Za-z0-9_\\-]/';
     $seriesTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SERIES_TITLE]);
     $seasonNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SEASON_NUMBER]);
     $videoEpisodeNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_EPISODE_NUMBER]);
     $videoTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_TITLE]);
     $this->fileBaseName = $seriesTitle . '-' . $seasonNumber . '-' . $videoEpisodeNumber . '-' . $videoTitle;
     // entry cue points
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $distributionJobData->entryDistribution->partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $distributionJobData->entryDistribution->entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $cuePointsDb = CuePointPeer::doSelect($c);
     $this->cuePoints = KalturaCuePointArray::fromDbArray($cuePointsDb);
 }
 /**
  * Serves multiple files for synchronization between datacenters 
  */
 public function execute()
 {
     $fileSyncIds = $this->getRequestParameter("ids");
     $hash = $this->getRequestParameter("hash");
     // validate hash
     $currentDc = kDataCenterMgr::getCurrentDc();
     $currentDcId = $currentDc["id"];
     $expectedHash = md5($currentDc["secret"] . $fileSyncIds);
     if ($hash !== $expectedHash) {
         $error = "Invalid hash - ids [{$fileSyncIds}] got [{$hash}] expected [{$expectedHash}]";
         KalturaLog::err($error);
         KExternalErrors::dieError(KExternalErrors::INVALID_TOKEN);
     }
     // load file syncs
     $fileSyncs = FileSyncPeer::retrieveByPks(explode(',', $fileSyncIds));
     if ($fileSyncs) {
         KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveMultiFile', $fileSyncs[0]->getPartnerId());
     }
     // resolve file syncs
     $filePaths = array();
     foreach ($fileSyncs as $fileSync) {
         if ($fileSync->getDc() != $currentDcId) {
             $error = "FileSync id [" . $fileSync->getId() . "] does not belong to this DC";
             KalturaLog::err($error);
             KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
         }
         // resolve if file_sync is link
         $fileSyncResolved = kFileSyncUtils::resolve($fileSync);
         // check if file sync path leads to a file or a directory
         $resolvedPath = $fileSyncResolved->getFullPath();
         if (is_dir($resolvedPath)) {
             $error = "FileSync id [" . $fileSync->getId() . "] is a directory";
             KalturaLog::err($error);
             KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
         }
         if (!file_exists($resolvedPath)) {
             $error = "Path [{$resolvedPath}] for fileSync id [" . $fileSync->getId() . "] does not exist";
             KalturaLog::err($error);
             continue;
         }
         $filePaths[$fileSync->getId()] = $resolvedPath;
     }
     $boundary = md5(uniqid('', true));
     header('Content-Type: multipart/form-data; boundary=' . $boundary);
     foreach ($filePaths as $id => $filePath) {
         echo "--{$boundary}\n";
         echo "Content-Type: application/octet-stream\n";
         echo "Content-Disposition: form-data; name=\"{$id}\"\n\n";
         readfile($filePath);
         echo "\n";
     }
     echo "--{$boundary}--\n";
     KExternalErrors::dieGracefully();
 }
Esempio n. 24
0
 /**
  * will return a pair of file_root and file_path
  *
  * @param ISyncableFile $object
  * @param int $subType
  * @param int $storageProfileId
  * @param $version
  */
 public static function getFilePathArr(FileSyncKey $key, $storageProfileId = null)
 {
     KalturaLog::log(__METHOD__ . " - key [{$key}], storageProfileId [{$storageProfileId}]");
     $storageProfile = self::getStorageProfile($storageProfileId);
     if (is_null($storageProfile)) {
         throw new Exception("Storage Profile [{$storageProfileId}] not found");
     }
     $pathManager = $storageProfile->getPathManager();
     $object = kFileSyncUtils::retrieveObjectForSyncKey($key);
     return $pathManager->generateFilePathArr($object, $key->object_sub_type, $key->version);
 }
 /**
  * @param string $id
  * @param int $type
  */
 protected function syncableDeleted($id, $type)
 {
     $c = new Criteria();
     $c->add(FileSyncPeer::OBJECT_ID, $id);
     $c->add(FileSyncPeer::OBJECT_TYPE, $type);
     $c->add(FileSyncPeer::STATUS, array(FileSync::FILE_SYNC_STATUS_PURGED, FileSync::FILE_SYNC_STATUS_DELETED), Criteria::NOT_IN);
     $fileSyncs = FileSyncPeer::doSelect($c);
     foreach ($fileSyncs as $fileSync) {
         $key = kFileSyncUtils::getKeyForFileSync($fileSync);
         kFileSyncUtils::deleteSyncFileForKey($key);
     }
 }
Esempio n. 26
0
 /**
  * @param Metadata $metadata
  * @param SimpleXMLElement $mrss
  * @return SimpleXMLElement
  */
 public function contributeMetadata(Metadata $metadata, SimpleXMLElement $mrss)
 {
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xml = kFileSyncUtils::file_get_contents($key, true, false);
     $metadataXml = new SimpleXMLElement($xml);
     $customData = $mrss->addChild('customData');
     $customData->addAttribute('metadataId', $metadata->getId());
     $customData->addAttribute('metadataVersion', $metadata->getVersion());
     $customData->addAttribute('metadataProfileId', $metadata->getMetadataProfileId());
     $customData->addAttribute('metadataProfileVersion', $metadata->getMetadataProfileVersion());
     $this->contributeMetadataObject($customData, $metadataXml);
 }
 /**
  * @param int $fromPartnerId
  * @param int $toPartnerId
  */
 protected function copyDistributionProfiles($fromPartnerId, $toPartnerId)
 {
     $c = new Criteria();
     $c->add(DistributionProfilePeer::PARTNER_ID, $fromPartnerId);
     $distributionProfiles = DistributionProfilePeer::doSelect($c);
     foreach ($distributionProfiles as $distributionProfile) {
         $newDistributionProfile = $distributionProfile->copy();
         $newDistributionProfile->setPartnerId($toPartnerId);
         $newDistributionProfile->save();
         kFileSyncUtils::createSyncFileLinkForKey($newDistributionProfile->getSyncKey(DistributionProfile::FILE_SYNC_DISTRIBUTION_PROFILE_CONFIG), $distributionProfile->getSyncKey(DistributionProfile::FILE_SYNC_DISTRIBUTION_PROFILE_CONFIG));
     }
 }
 public function fromObject($source_object)
 {
     parent::fromObject($source_object);
     $key = $source_object->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
     $this->xslt = kFileSyncUtils::file_get_contents($key, true, false);
     $mrssParams = $source_object->getMrssParameters();
     if ($mrssParams) {
         $this->itemXpathsToExtend = KalturaStringArray::fromStringArray($mrssParams->getItemXpathsToExtend());
     } else {
         $this->itemXpathsToExtend = new KalturaStringArray();
     }
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaYahooDistributionProfile) {
         return;
     }
     //Flavor Assets
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $videoAssetFilePathArray = array();
         foreach ($flavorAssets as $flavorAsset) {
             if ($flavorAsset) {
                 /* @var $flavorAsset flavorAsset */
                 $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
                 if (kFileSyncUtils::fileSync_exists($syncKey)) {
                     $id = $flavorAsset->getId();
                     //$this->videoAssetFilePath[$id] = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $videoAssetFilePathArray[$id] = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                 }
             }
         }
         $this->videoAssetFilePath = serialize($videoAssetFilePathArray);
     }
     //Thumbnails
     $c = new Criteria();
     $c->addAnd(assetPeer::ID, explode(',', $distributionJobData->entryDistribution->thumbAssetIds), Criteria::IN);
     $c->addAscendingOrderByColumn(assetPeer::ID);
     $thumbAssets = assetPeer::doSelect($c);
     //$thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets) >= 2) {
         if ($thumbAssets[0]->getWidth() <= $thumbAssets[1]->getWidth()) {
             $smallThumbAsset = $thumbAssets[0];
             $largeThumbAsset = $thumbAssets[1];
         } else {
             $smallThumbAsset = $thumbAssets[1];
             $largeThumbAsset = $thumbAssets[0];
         }
         $syncKey = $smallThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->smallThumbPath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
         $syncKey = $largeThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $this->largeThumbPath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         }
     }
 }
 /**
  * Returns the url for the given flavor. in case of rtmp, return the file path in order ot use a local streaming server
  * 
  * @param flavorAsset $flavorAsset
  * @return string
  */
 protected function doGetFlavorAssetUrl(flavorAsset $flavorAsset)
 {
     if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) {
         return parent::doGetFlavorAssetUrl($flavorAsset);
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     $url = $this->doGetFileSyncUrl($fileSync);
     if ($this->extention && strtolower($this->extention) != 'flv' || $this->containerFormat && strtolower($this->containerFormat) != 'flash video') {
         $url = "mp4:{$url}";
     }
     $url = str_replace('\\', '/', $url);
     return $url;
 }