/**
  * @param entry $object
  * @return bool true if should continue to the next consumer
  */
 public function entryCreated(entry $object)
 {
     $mediaType = null;
     if ($object->getType() == entryType::AUTOMATIC) {
         KalturaLog::debug("entry id [" . $object->getId() . "] type [" . $object->getType() . "] source link [" . $object->getSourceLink() . "]");
         $mediaType = $object->getMediaType();
         if (isset(self::$fileExtensions[$mediaType])) {
             $object->setType(entryType::DOCUMENT);
         } elseif (is_null($mediaType) || $mediaType == entry::ENTRY_MEDIA_TYPE_ANY || $mediaType == entry::ENTRY_MEDIA_TYPE_AUTOMATIC) {
             $this->setDocumentType($object);
         }
     }
     if ($object->getType() != entryType::DOCUMENT) {
         KalturaLog::debug("entry id [" . $object->getId() . "] type [" . $object->getType() . "]");
         return true;
     }
     if (is_null($mediaType) || $mediaType == entry::ENTRY_MEDIA_TYPE_ANY || $mediaType == entry::ENTRY_MEDIA_TYPE_AUTOMATIC) {
         $this->setDocumentType($object);
     }
     if ($object instanceof DocumentEntry) {
         KalturaLog::debug("entry id [" . $object->getId() . "] already handled");
         return true;
     }
     KalturaLog::debug("Handling object [" . get_class($object) . "] type [" . $object->getType() . "] id [" . $object->getId() . "] status [" . $object->getStatus() . "]");
     if ($object->getConversionProfileId()) {
         $object->setStatus(entryStatus::PRECONVERT);
         $object->save();
     }
     return true;
 }
Esempio n. 2
0
 /**
  * This function checks if the entry type matches the filter, and return 'true' or 'false' accordingly.
  * @param entry $entry
  * @return boolean
  */
 public function matches(entry $entry)
 {
     // check if type equals
     if ($entry->getType() == $this->get('_eq_type')) {
         return true;
     }
     // check if type in
     if (in_array($entry->getType(), explode(',', $this->get('_in_type')))) {
         return true;
     }
     return false;
 }
 /**
  * @return kManifestRenderer
  */
 private function serveRtmp()
 {
     $baseUrl = null;
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             $flavors = $this->buildRtmpFlavorsArray($duration, $baseUrl);
             if (!count($flavors)) {
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             $renderer = new kF4MManifestRenderer();
             $renderer->entryId = $this->entryId;
             $renderer->tokenizer = $this->tokenizer;
             $renderer->flavors = $flavors;
             $renderer->baseUrl = $baseUrl;
             $renderer->duration = $duration;
             $renderer->mimeType = $this->getMimeType($flavors);
             return $renderer;
         case entryType::LIVE_STREAM:
             $flavors = $this->buildRtmpLiveStreamFlavorsArray($baseUrl);
             $renderer = new kF4MManifestRenderer();
             $renderer->entryId = $this->entryId;
             $renderer->tokenizer = $this->tokenizer;
             $renderer->flavors = $flavors;
             $renderer->baseUrl = $baseUrl;
             $renderer->streamType = kF4MManifestRenderer::PLAY_STREAM_TYPE_LIVE;
             $renderer->mimeType = $this->getMimeType($flavors);
             $renderer->deliveryCode = $this->deliveryCode;
             return $renderer;
     }
     KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
 }
Esempio n. 4
0
 protected static function generateMultiUrl(array $flavors, entry $entry)
 {
     $urls = array();
     foreach ($flavors as $flavor) {
         $urls[] = $flavor['url'];
     }
     $urls = array_unique($urls);
     if (count($urls) == 1) {
         $baseUrl = reset($urls);
         return '/' . ltrim($baseUrl, '/');
     }
     $prefix = kString::getCommonPrefix($urls);
     $postfix = kString::getCommonPostfix($urls);
     if ($entry->getType() == entryType::PLAYLIST) {
         // in case of a playlist, need to merge the flavor params of the urls
         // instead of using a urlset, since nginx-vod does not support urlsets of
         // non-trivial mapping responses.
         // so instead of building:
         //		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/100,1,2,3,/forceproxy/true/name/a.mp4.urlset
         // we build:
         //		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/1001,1002,1003/forceproxy/true/name/a.mp4.urlset
         $prefix = substr($prefix, 0, strrpos($prefix, '/') + 1);
         $postfix = substr($postfix, strpos($postfix, '/'));
     }
     $prefixLen = strlen($prefix);
     $postfixLen = strlen($postfix);
     $middlePart = ',';
     foreach ($urls as $url) {
         $middlePart .= substr($url, $prefixLen, strlen($url) - $prefixLen - $postfixLen) . ',';
     }
     if ($entry->getType() == entryType::PLAYLIST && strpos($middlePart, '/') === false) {
         $middlePart = rtrim(ltrim($middlePart, ','), ',');
         $result = $prefix . $middlePart . $postfix;
     } else {
         $result = $prefix . $middlePart . $postfix . '.urlset';
     }
     return '/' . ltrim($result, '/');
 }
 public function entryHandled(entry $dbEntry)
 {
     $srcEntry = entryPeer::retrieveByPK($this->entryId);
     if ($srcEntry->getType() == KalturaEntryType::MEDIA_CLIP && $dbEntry->getType() == KalturaEntryType::MEDIA_CLIP && $dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
         if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
             $dbEntry->setDimensions($srcEntry->getWidth(), $srcEntry->getHeight());
             $dbEntry->setMediaDate($srcEntry->getMediaDate(null));
             $dbEntry->save();
         } else {
             $srcFlavorAsset = null;
             if (is_null($this->flavorParamsId)) {
                 $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId);
             } else {
                 $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId);
             }
             if ($srcFlavorAsset) {
                 $dbEntry->setDimensions($srcFlavorAsset->getWidth(), $srcFlavorAsset->getHeight());
                 $dbEntry->save();
             }
         }
     }
     return parent::entryHandled($dbEntry);
 }
Esempio n. 6
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
         $flavorParamsStr = $entry->getFlavorParamsIds();
         $flavorParams = explode(',', $flavorParamsStr);
         $newFlavorParams = array();
         foreach ($flavorParams as $flavorParamsId) {
             $newFlavorParamsId = kObjectCopyHandler::getMappedId('flavorParams', $flavorParamsId);
             if (is_null($newFlavorParamsId)) {
                 $newFlavorParamsId = $flavorParamsId;
             }
             $newFlavorParams[] = $newFlavorParamsId;
         }
         $newEntry->setFlavorParamsIds(implode(',', $newFlavorParams));
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = $entry->getType() != entryType::MEDIA_CLIP;
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceFlavorAssets = flavorAssetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceFlavorAssets as $sourceFlavorAsset) {
         $sourceFlavorAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
 }
 /**
  * @param kResource $resource
  * @param entry $dbEntry
  * @param asset $asset
  */
 protected function attachResource(kResource $resource, entry $dbEntry, asset $asset = null)
 {
     $service = null;
     switch ($dbEntry->getType()) {
         case entryType::MEDIA_CLIP:
             $service = new MediaService();
             $service->initService('media', 'media', $this->actionName);
             break;
         case entryType::MIX:
             $service = new MixingService();
             $service->initService('mixing', 'mixing', $this->actionName);
             break;
         case entryType::PLAYLIST:
             $service = new PlaylistService();
             $service->initService('playlist', 'playlist', $this->actionName);
             break;
         case entryType::DATA:
             $service = new DataService();
             $service->initService('data', 'data', $this->actionName);
             break;
         case entryType::LIVE_STREAM:
             $service = new LiveStreamService();
             $service->initService('liveStream', 'liveStream', $this->actionName);
             break;
         default:
             throw new KalturaAPIException(KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED, $dbEntry->getType());
     }
     $service->attachResource($resource, $dbEntry, $asset);
 }
Esempio n. 8
0
 public function execute()
 {
     KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND);
     $this->deliveryAttributes = new DeliveryProfileDynamicAttributes();
     // Parse input parameters
     $this->deliveryAttributes->setSeekFromTime($this->getRequestParameter("seekFrom", -1));
     if ($this->deliveryAttributes->getSeekFromTime() <= 0) {
         $this->deliveryAttributes->setSeekFromTime(-1);
     }
     $this->deliveryAttributes->setClipTo($this->getRequestParameter("clipTo", 0));
     $this->deliveryAttributes->setPlaybackRate($this->getRequestParameter("playbackRate", 0));
     $deliveryCode = $this->getRequestParameter("deliveryCode", null);
     $playbackContext = $this->getRequestParameter("playbackContext", null);
     $this->deliveryAttributes->setMediaProtocol($this->getRequestParameter("protocol", null));
     if (!$this->deliveryAttributes->getMediaProtocol() || $this->deliveryAttributes->getMediaProtocol() === "null") {
         $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
     }
     $this->deliveryAttributes->setFormat($this->getRequestParameter("format"));
     if (!$this->deliveryAttributes->getFormat()) {
         $this->deliveryAttributes->setFormat(PlaybackProtocol::HTTP);
     }
     if ($this->deliveryAttributes->getFormat() == self::HDNETWORKSMIL) {
         $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
     }
     // Akamai HD doesn't support any other protocol
     if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::AKAMAI_HDS) {
         if (strpos($this->deliveryAttributes->getMediaProtocol(), "http") !== 0) {
             $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
         }
     }
     $tags = $this->getRequestParameter("tags", null);
     if (!$tags) {
         $this->deliveryAttributes->setTags(self::getDefaultTagsByFormat($this->deliveryAttributes->getFormat()));
     } else {
         $tagsArray = explode(',', $tags);
         $tags = array();
         foreach ($tagsArray as $tag) {
             $tags[] = array(trim($tag));
         }
         $this->deliveryAttributes->setTags($tags);
     }
     $this->deliveryAttributes->setpreferredBitrate($this->getRequestParameter("preferredBitrate", null));
     $this->maxBitrate = $this->getRequestParameter("maxBitrate", null);
     if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) {
         KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE);
     }
     $this->deliveryAttributes->setStorageId($this->getRequestParameter("storageId", null));
     $this->cdnHost = $this->getRequestParameter("cdnHost", null);
     $this->deliveryAttributes->setResponseFormat($this->getRequestParameter("responseFormat", null));
     // Initialize
     $this->initEntry();
     $this->deliveryAttributes->setEntryId($this->entryId);
     $this->deliveryAttributes->setUsePlayServer((bool) $this->getRequestParameter("usePlayServer") && PermissionPeer::isValidForPartner(PermissionName::FEATURE_PLAY_SERVER, $this->entry->getPartnerId()));
     if ($this->deliveryAttributes->getUsePlayServer()) {
         $this->deliveryAttributes->setPlayerConfig($this->getRequestParameter("playerConfig"));
         //In case request needs to be redirected to play-server we need to add the ui conf id to the manifest url as well
         $this->deliveryAttributes->setUiConfId($this->getRequestParameter("uiConfId"));
     }
     $this->secureEntryHelper->updateDeliveryAttributes($this->deliveryAttributes);
     $this->enforceEncryption();
     $renderer = null;
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             // VOD
             $renderer = $this->serveVodEntry();
             break;
         case entryType::LIVE_STREAM:
         case entryType::LIVE_CHANNEL:
             // Live stream
             $renderer = $this->serveLiveEntry();
             break;
         default:
             KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
     }
     if (!$renderer) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'This format is unsupported');
     }
     $renderer->contributors = array();
     $config = new kManifestContributorConfig();
     $config->format = $this->deliveryAttributes->getFormat();
     $config->deliveryCode = $deliveryCode;
     $config->storageId = $this->deliveryAttributes->getStorageId();
     $config->entryId = $this->entryId;
     $contributors = KalturaPluginManager::getPluginInstances('IKalturaPlayManifestContributor');
     foreach ($contributors as $contributor) {
         /* @var $contributor IKalturaPlayManifestContributor */
         $renderer->contributors = array_merge($renderer->contributors, $contributor->getManifestEditors($config));
     }
     $renderer->entryId = $this->entryId;
     $renderer->duration = $this->duration;
     if ($this->deliveryProfile) {
         $renderer->tokenizer = $this->deliveryProfile->getTokenizer();
     }
     $renderer->defaultDeliveryCode = $this->entry->getPartner()->getDefaultDeliveryCode();
     $renderer->lastModified = time();
     // Handle caching
     $canCacheAccessControl = false;
     if (kConf::hasParam("force_caching_headers") && in_array($this->entry->getPartnerId(), kConf::get("force_caching_headers"))) {
         $renderer->cachingHeadersAge = 60;
         $renderer->forceCachingHeaders = true;
     }
     if (!$this->secureEntryHelper) {
         $canCacheAccessControl = true;
         // TODO: reconsider this if/when expired ktokens will be used
     } else {
         if (!$this->secureEntryHelper->shouldDisableCache() && !$this->secureEntryHelper->isKsAdmin() && ($this->secureEntryHelper->isKsWidget() || !$this->secureEntryHelper->hasRules())) {
             $canCacheAccessControl = true;
         }
     }
     if (!$renderer->tokenizer && $canCacheAccessControl) {
         // Note: kApiCache::hasExtraFields is checked in kManifestRenderers
         $renderer->cachingHeadersAge = 60;
     }
     if (!$this->secureEntryHelper || !$this->secureEntryHelper->shouldDisableCache()) {
         $cache = kPlayManifestCacher::getInstance();
         $cache->storeRendererToCache($renderer);
     }
     // Output the response
     KExternalErrors::terminateDispatch();
     $renderer->output($deliveryCode, $playbackContext);
 }
 private function serveRtmp()
 {
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             $duration = $this->entry->getDurationInt();
             $flavorAssets = array();
             if ($this->flavorId) {
                 $flavorAsset = flavorAssetPeer::retrieveById($this->flavorId);
                 if (!$flavorAsset->hasTag(flavorParams::TAG_WEB)) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 if (!$flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 $flavorAssets[] = $flavorAsset;
             } else {
                 $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_MBR);
                 if (!count($flavorAssets)) {
                     $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB);
                 }
             }
             $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets);
             if (!$this->storageId) {
                 $partner = $this->entry->getPartner();
                 $finalFlavors = array();
                 if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
                     foreach ($flavorAssets as $flavorAsset) {
                         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                         if ($fileSync) {
                             $finalFlavors[] = $flavorAsset;
                         }
                     }
                 }
                 if (!count($finalFlavors) && $partner->getStorageServePriority() && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
                     $storages = StorageProfilePeer::retrieveExternalByPartnerId($partner->getId());
                     if (count($storages) == 1) {
                         $this->storageId = $storages[0]->getId();
                     } elseif (count($storages)) {
                         $storagesFlavors = array();
                         foreach ($storages as $storage) {
                             $storagesFlavors[$storage->getId()] = array();
                             foreach ($flavorAssets as $flavorAsset) {
                                 $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                                 $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storage->getId());
                                 if ($fileSync) {
                                     $storagesFlavors[$storage->getId()][] = $flavorAsset;
                                 }
                             }
                         }
                         $maxCount = 0;
                         foreach ($storagesFlavors as $storageId => $storageFlavors) {
                             $count = count($storageFlavors);
                             if ($count > $maxCount) {
                                 $maxCount = $count;
                                 $this->storageId = $storageId;
                                 $finalFlavors = $storageFlavors;
                             }
                         }
                         $flavorAssets = $finalFlavors;
                     } else {
                         foreach ($flavorAssets as $flavorAsset) {
                             $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                             if ($fileSync) {
                                 $finalFlavors[] = $flavorAsset;
                             }
                         }
                     }
                 }
             }
             foreach ($flavorAssets as $flavorAsset) {
                 $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
                 if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                     $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                     $duration /= 1000;
                     break;
                 }
             }
             $baseUrl = null;
             $flavors = array();
             if ($this->storageId) {
                 $storage = StorageProfilePeer::retrieveByPK($this->storageId);
                 if (!$storage) {
                     die;
                 }
                 $baseUrl = $storage->getDeliveryRmpBaseUrl();
                 // get all flavors with external urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId);
                     if (!$fileSync) {
                         continue;
                     }
                     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc());
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFileSyncUrl($fileSync);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             } else {
                 $partnerId = $this->entry->getPartnerId();
                 $subpId = $this->entry->getSubpId();
                 $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
                 $baseUrl = myPartnerUtils::getRtmpUrl($partnerId);
                 $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost);
                 // get all flavors with kaltura urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFlavorAssetUrl($flavorAsset);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             }
             if (!count($flavors)) {
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, $flavors, 'video/x-flv', $duration, $baseUrl);
         case entryType::LIVE_STREAM:
             $streamId = $this->entry->getStreamRemoteId();
             $streamUsername = $this->entry->getStreamUsername();
             $baseUrl = $this->entry->getStreamUrl();
             $baseUrl = rtrim($baseUrl, '/');
             $flavors = $this->entry->getStreamBitrates();
             if (count($flavors)) {
                 foreach ($flavors as $index => $flavor) {
                     $brIndex = $index + 1;
                     $flavors[$index]['url'] = str_replace('%i', $brIndex, $this->entry->getStreamName());
                 }
             } else {
                 $flavors[0]['url'] = str_replace('%i', '1', $this->entry->getStreamName());
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_LIVE, $flavors, 'video/x-flv', null, $baseUrl);
     }
     KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
 }
Esempio n. 10
0
 /**
  * @param array $flavors
  * @return string
  */
 protected function setMimeType(entry $entry)
 {
     if ($entry->getType() == entryType::MEDIA_CLIP && count($this->flavors)) {
         $isMp3 = true;
         foreach ($this->flavors as $flavor) {
             if (!isset($flavor['ext']) || strtolower($flavor['ext']) != 'mp3') {
                 $isMp3 = false;
             }
         }
         if ($isMp3) {
             $this->mimeType = 'audio/mpeg';
             return;
         }
     }
     $this->mimeType = 'video/x-flv';
 }
Esempio n. 11
0
 private function setContextDataStreamerTypeAndMediaProtocol(accessControlScope $scope, $flavorTags)
 {
     if ($this->streamerType && $this->streamerType != PlaybackProtocol::AUTO) {
         $this->mediaProtocol = $this->mediaProtocol ? $this->mediaProtocol : $this->streamerType;
     } elseif ($this->entry instanceof LiveEntry) {
         $protocols = array();
         if (!in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
             $protocols[] = PlaybackProtocol::AKAMAI_HDS;
         }
         $protocols[] = PlaybackProtocol::HDS;
         if ($this->entry->getStreamName()) {
             $this->streamerType = PlaybackProtocol::RTMP;
         }
         foreach ($protocols as $protocol) {
             $config = $this->entry->getLiveStreamConfigurationByProtocol($protocol, requestUtils::getProtocol());
             if ($config) {
                 $this->streamerType = $protocol;
                 break;
             }
         }
         if (in_array($this->entry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
             $this->streamerType = PlaybackProtocol::HDS;
         }
         if ($this->entry->getSource() == EntrySourceType::AKAMAI_LIVE) {
             $this->streamerType = PlaybackProtocol::RTMP;
         }
         if ($this->entry->getSource() == EntrySourceType::AKAMAI_UNIVERSAL_LIVE) {
             $this->streamerType = PlaybackProtocol::AKAMAI_HDS;
         }
     } elseif ($this->entry->getType() == entryType::PLAYLIST) {
         $this->streamerType = PlaybackProtocol::AKAMAI_HDS;
         $this->mediaProtocol = infraRequestUtils::getProtocol();
     } else {
         $this->isSecured = $this->isSecured || PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT_USED, $this->entry->getPartnerId());
         $forcedDeliveryTypeKey = kDeliveryUtils::getForcedDeliveryTypeKey($this->selectedTag);
         if ($forcedDeliveryTypeKey) {
             $defaultDeliveryTypeKey = $forcedDeliveryTypeKey;
         } else {
             $defaultDeliveryTypeKey = $this->partner->getDefaultDeliveryType();
         }
         if (!$defaultDeliveryTypeKey || $defaultDeliveryTypeKey == PlaybackProtocol::AUTO) {
             $deliveryType = $this->selectDeliveryTypeForAuto();
         } else {
             $deliveryType = kDeliveryUtils::getDeliveryTypeFromConfig($defaultDeliveryTypeKey);
         }
         if (!$deliveryType) {
             $deliveryType = array();
         }
         $this->streamerType = kDeliveryUtils::getStreamerType($deliveryType);
         $this->mediaProtocol = kDeliveryUtils::getMediaProtocol($deliveryType);
     }
     $httpStreamerTypes = array(PlaybackProtocol::HTTP, PlaybackProtocol::HDS, PlaybackProtocol::HLS, PlaybackProtocol::SILVER_LIGHT, PlaybackProtocol::MPEG_DASH);
     if (in_array($this->streamerType, $httpStreamerTypes)) {
         $this->mediaProtocol = infraRequestUtils::getProtocol();
     }
     if ($this->streamerType == PlaybackProtocol::AKAMAI_HD || $this->streamerType == PlaybackProtocol::AKAMAI_HDS) {
         $this->mediaProtocol = PlaybackProtocol::HTTP;
     }
     //If a plugin can determine the streamerType and mediaProtocol, prefer plugin result
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaContextDataHelper');
     foreach ($pluginInstances as $pluginInstance) {
         /* @var $pluginInstance IKalturaContextDataHelper */
         $this->streamerType = $pluginInstance->getContextDataStreamerType($scope, $flavorTags, $this->streamerType);
         $this->mediaProtocol = $pluginInstance->getContextDataMediaProtocol($scope, $flavorTags, $this->streamerType, $this->mediaProtocol);
     }
 }
Esempio n. 12
0
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     $newEntry->setCategories(null);
     $newEntry->setCategoriesIds(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         $newEntry->setCreatorKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = true;
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         $shouldCopyDataForNonClip = false;
     }
     if ($entry->getType() == entryType::PLAYLIST) {
         $shouldCopyDataForNonClip = false;
     }
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     //if entry is a static playlist, link between it and its new child entries
     if ($entry->getType() == entryType::PLAYLIST) {
         switch ($entry->getMediaType()) {
             case entry::ENTRY_MEDIA_TYPE_TEXT:
                 $from = $entry->getDataContent();
                 KalturaLog::debug("Entries to copy from source static playlist: [{$from}]");
                 $fromEntryIds = explode(",", $from);
                 $toEntryIds = array();
                 foreach ($fromEntryIds as $fromEntryId) {
                     $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId);
                 }
                 $newEntry->setDataContent(implode(",", $toEntryIds));
                 break;
             case entry::ENTRY_MEDIA_TYPE_XML:
                 list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent());
                 $toPlaylistXml = new SimpleXMLElement("<playlist/>");
                 $toPlaylistXml->addChild("total_results", $totalResults);
                 $toFiltersXml = $toPlaylistXml->addChild("filters");
                 foreach ($fromFiltersList as $filterXML) {
                     $entryFilter = new entryFilter();
                     $entryFilter->fillObjectFromXml($filterXML, "_");
                     if (isset($entryFilter->fields["_matchand_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_matchor_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_in_category_ancestor_id"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds);
                     }
                     $toEntryFilterXML = $toFiltersXml->addChild("filter");
                     $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML);
                 }
                 $newEntry->setDataContent($toPlaylistXml->asXML());
                 break;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceAssets = assetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceAssets as $sourceAsset) {
         $sourceAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
     // copy relationships to categories
     KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']');
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId());
     $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
     $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId());
     categoryEntryPeer::setUseCriteriaFilter(false);
     $categoryEntries = categoryEntryPeer::doSelect($c);
     categoryEntryPeer::setUseCriteriaFilter(true);
     // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids
     //
     // Build src category IDs set
     $srcCategoryIdSet = array();
     foreach ($categoryEntries as $categoryEntry) {
         $srcCategoryIdSet[] = $categoryEntry->getCategoryId();
     }
     $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED);
     // Get src category objects
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $srcCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     // Map the category names to their IDs
     $fullNamesToSrcCategoryIdMap = array();
     foreach ($srcCategories as $category) {
         $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId();
     }
     // Get dst. partner categories based on src. category full-names
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $dstCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     $srcCategoryIdToDstCategoryIdMap = array();
     foreach ($dstCategories as $dstCategory) {
         $fullName = $dstCategory->getFullName();
         if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) {
             $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName];
             $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId();
         }
     }
     foreach ($categoryEntries as $categoryEntry) {
         /* @var $categoryEntry categoryEntry */
         $newCategoryEntry = $categoryEntry->copy();
         $newCategoryEntry->setPartnerId($newEntry->getPartnerId());
         $newCategoryEntry->setEntryId($newEntry->getId());
         $srcCategoryId = $categoryEntry->getCategoryId();
         if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) {
             continue;
             // Skip the category_entry's creation
         }
         $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId];
         $newCategoryEntry->setCategoryId($dstCategoryId);
         categoryPeer::setUseCriteriaFilter(false);
         entryPeer::setUseCriteriaFilter(false);
         $newCategoryEntry->save();
         entryPeer::setUseCriteriaFilter(true);
         categoryPeer::setUseCriteriaFilter(true);
     }
     return $newEntry;
 }
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @param kMrssParameters $mrssParams
  * @return SimpleXMLElement
  */
 public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null)
 {
     if ($mrss === null) {
         $mrss = new SimpleXMLElement('<item/>');
     }
     $mrss->addChild('entryId', $entry->getId());
     if ($entry->getReferenceID()) {
         $mrss->addChild('referenceID', $entry->getReferenceID());
     }
     $mrss->addChild('createdAt', $entry->getCreatedAt(null));
     $mrss->addChild('updatedAt', $entry->getUpdatedAt(null));
     $mrss->addChild('title', self::stringToSafeXml($entry->getName()));
     if ($mrssParams && !is_null($mrssParams->getLink())) {
         $mrss->addChild('link', $mrssParams->getLink() . $entry->getId());
     }
     $mrss->addChild('type', $entry->getType());
     $mrss->addChild('licenseType', $entry->getLicenseType());
     $mrss->addChild('userId', $entry->getPuserId(true));
     $mrss->addChild('name', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('status', self::stringToSafeXml($entry->getStatus()));
     $mrss->addChild('description', self::stringToSafeXml($entry->getDescription()));
     $thumbnailUrl = $mrss->addChild('thumbnailUrl');
     $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl());
     if (trim($entry->getTags(), " \r\n\t")) {
         $tags = $mrss->addChild('tags');
         foreach (explode(',', $entry->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $categories = explode(',', $entry->getCategories());
     foreach ($categories as $category) {
         $category = trim($category);
         if ($category) {
             $categoryNode = $mrss->addChild('category', self::stringToSafeXml($category));
             if (strrpos($category, '>') > 0) {
                 $categoryNode->addAttribute('name', self::stringToSafeXml(substr($category, strrpos($category, '>') + 1)));
             } else {
                 $categoryNode->addAttribute('name', self::stringToSafeXml($category));
             }
         }
     }
     $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData()));
     if ($entry->getAccessControlId()) {
         $mrss->addChild('accessControlId', $entry->getAccessControlId());
     }
     if ($entry->getConversionProfileId()) {
         $mrss->addChild('conversionProfileId', $entry->getConversionProfileId());
     }
     if ($entry->getStartDate(null)) {
         $mrss->addChild('startDate', $entry->getStartDate(null));
     }
     if ($entry->getEndDate(null)) {
         $mrss->addChild('endDate', $entry->getEndDate(null));
     }
     switch ($entry->getType()) {
         case entryType::MEDIA_CLIP:
             self::appendMediaEntryMrss($entry, $mrss);
             break;
         case entryType::MIX:
             self::appendMixEntryMrss($entry, $mrss);
             break;
         case entryType::PLAYLIST:
             self::appendPlaylistEntryMrss($entry, $mrss);
             break;
         case entryType::DATA:
             self::appendDataEntryMrss($entry, $mrss);
             break;
         case entryType::LIVE_STREAM:
             self::appendLiveStreamEntryMrss($entry, $mrss);
             break;
         default:
             break;
     }
     $assets = assetPeer::retrieveReadyByEntryId($entry->getId());
     foreach ($assets as $asset) {
         if ($mrssParams && !is_null($mrssParams->getFilterByFlavorParams()) && $asset->getFlavorParamsId() != $mrssParams->getFilterByFlavorParams()) {
             continue;
         }
         if ($asset instanceof flavorAsset) {
             self::appendFlavorAssetMrss($asset, $mrss, $mrssParams);
         }
         if ($asset instanceof thumbAsset) {
             self::appendThumbAssetMrss($asset, $mrss);
         }
     }
     $mrssContributors = self::getMrssContributors();
     if (count($mrssContributors)) {
         foreach ($mrssContributors as $mrssContributor) {
             $mrssContributor->contribute($entry, $mrss, $mrssParams);
         }
     }
     if ($mrssParams && $mrssParams->getIncludePlayerTag()) {
         $uiconfId = !is_null($mrssParams->getPlayerUiconfId()) ? '/ui_conf_id/' . $mrssParams->getPlayerUiconfId() : '';
         $playerUrl = 'http://' . kConf::get('www_host') . '/kwidget/wid/_' . $entry->getPartnerId() . '/entry_id/' . $entry->getId() . '/ui_conf' . ($uiconfId ? "/{$uiconfId}" : '');
         $player = $mrss->addChild('player');
         $player->addAttribute('url', $playerUrl);
     }
     return $mrss;
 }
Esempio n. 14
0
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @param string $link
  * @param string $filterFlavors
  * @return SimpleXMLElement
  */
 public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, $link = null, $fitlerByFlovorParams = null)
 {
     if (!$mrss) {
         $mrss = new SimpleXMLElement('<item/>');
     }
     $mrss->addChild('entryId', $entry->getId());
     $mrss->addChild('createdAt', $entry->getCreatedAt(null));
     $mrss->addChild('title', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('link', $link . $entry->getId());
     $mrss->addChild('type', $entry->getType());
     $mrss->addChild('licenseType', $entry->getLicenseType());
     $mrss->addChild('userId', $entry->getPuserId(true));
     $mrss->addChild('name', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('description', self::stringToSafeXml($entry->getDescription()));
     $thumbnailUrl = $mrss->addChild('thumbnailUrl');
     $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl());
     $tags = $mrss->addChild('tags');
     foreach (explode(',', $entry->getTags()) as $tag) {
         $tags->addChild('tag', self::stringToSafeXml($tag));
     }
     $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData()));
     $mrss->addChild('accessControlId', $entry->getAccessControlId());
     $categories = explode(',', $entry->getCategories());
     foreach ($categories as $category) {
         if ($category) {
             $mrss->addChild('category', self::stringToSafeXml($category));
         }
     }
     if ($entry->getStartDate(null)) {
         $mrss->addChild('startDate', $entry->getStartDate(null));
     }
     if ($entry->getEndDate(null)) {
         $mrss->addChild('endDate', $entry->getEndDate(null));
     }
     switch ($entry->getType()) {
         case entryType::MEDIA_CLIP:
             self::appendMediaEntryMrss($entry, $mrss);
             break;
         case entryType::MIX:
             self::appendMixEntryMrss($entry, $mrss);
             break;
         case entryType::PLAYLIST:
             self::appendPlaylistEntryMrss($entry, $mrss);
             break;
         case entryType::DATA:
             self::appendDataEntryMrss($entry, $mrss);
             break;
         case entryType::LIVE_STREAM:
             self::appendLiveStreamEntryMrss($entry, $mrss);
             break;
         default:
             break;
     }
     $flavorAssets = flavorAssetPeer::retreiveReadyByEntryId($entry->getId());
     foreach ($flavorAssets as $flavorAsset) {
         if (!is_null($fitlerByFlovorParams) && $flavorAsset->getFlavorParamsId() != $fitlerByFlovorParams) {
             continue;
         }
         $content = $mrss->addChild('content');
         $content->addAttribute('url', self::getAssetUrl($flavorAsset));
         $content->addAttribute('flavorAssetId', $flavorAsset->getId());
         $content->addAttribute('isSource', $flavorAsset->getIsOriginal() ? 'true' : 'false');
         $content->addAttribute('containerFormat', $flavorAsset->getContainerFormat());
         $content->addAttribute('extension', $flavorAsset->getFileExt());
         if (!is_null($flavorAsset->getFlavorParamsId())) {
             $content->addAttribute('flavorParamsId', $flavorAsset->getFlavorParamsId());
             $flavorParams = flavorParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
             if ($flavorParams) {
                 $content->addAttribute('flavorParamsName', $flavorParams->getName());
                 $content->addAttribute('format', $flavorParams->getFormat());
                 $content->addAttribute('videoBitrate', $flavorParams->getVideoBitrate());
                 $content->addAttribute('videoCodec', $flavorParams->getVideoCodec());
                 $content->addAttribute('audioBitrate', $flavorParams->getAudioBitrate());
                 $content->addAttribute('audioCodec', $flavorParams->getAudioCodec());
                 $content->addAttribute('frameRate', $flavorParams->getFrameRate());
                 $content->addAttribute('height', $flavorParams->getHeight());
                 $content->addAttribute('width', $flavorParams->getWidth());
             }
         }
         $tags = $content->addChild('tags');
         foreach (explode(',', $flavorAsset->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $thumbAssets = thumbAssetPeer::retreiveReadyByEntryId($entry->getId());
     foreach ($thumbAssets as $thumbAsset) {
         $thumbnail = $mrss->addChild('thumbnail');
         $thumbnail->addAttribute('url', self::getAssetUrl($thumbAsset));
         $thumbnail->addAttribute('thumbAssetId', $thumbAsset->getId());
         $thumbnail->addAttribute('isDefault', $thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB) ? 'true' : 'false');
         $thumbnail->addAttribute('format', $thumbAsset->getContainerFormat());
         if ($thumbAsset->getFlavorParamsId()) {
             $thumbnail->addAttribute('thumbParamsId', $thumbAsset->getFlavorParamsId());
         }
         $tags = $thumbnail->addChild('tags');
         foreach (explode(',', $thumbAsset->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $mrssContributors = self::getMrssContributors();
     if (count($mrssContributors)) {
         foreach ($mrssContributors as $mrssContributor) {
             $mrssContributor->contribute($entry, $mrss);
         }
     }
     return $mrss;
 }
Esempio n. 15
0
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]");
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     $importingSources = false;
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) {
         KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist");
         $partner = $entry->getPartner();
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId());
         // load the asset params to the instance pool
         $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId());
         assetParamsPeer::retrieveByPKs($flavorIds);
         $conversionRequired = false;
         $sourceFileRequiredStorages = array();
         $sourceIncludedInProfile = false;
         $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId());
         KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]");
         foreach ($flavors as $flavor) {
             /* @var $flavor flavorParamsConversionProfile */
             if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source");
                 $sourceIncludedInProfile = true;
                 continue;
             }
             $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
             if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested");
                 continue;
             }
             if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
                 $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId());
                 if ($siblingFlavorAsset) {
                     KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested");
                     continue;
                 }
             }
             $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId();
             $conversionRequired = true;
             break;
         }
         if ($conversionRequired) {
             foreach ($sourceFileRequiredStorages as $storageId) {
                 if ($storageId == StorageProfile::STORAGE_KALTURA_DC) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false);
                     if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                         KalturaLog::debug("Creates import job for remote file sync");
                         $url = $syncFile->getExternalUrl($entry->getId());
                         kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true);
                         $importingSources = true;
                         continue;
                     }
                 } elseif ($flavorAsset->getExternalUrl($storageId)) {
                     continue;
                 }
                 kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING);
                 $flavorAsset = assetPeer::retrieveById($flavorAssetId);
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                 $flavorAsset->setDescription('Entry of size 0 should not be converted');
                 $flavorAsset->save();
                 KalturaLog::err('Entry of size 0 should not be converted');
                 return null;
             }
         } else {
             if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) {
                 if ($sourceIncludedInProfile) {
                     $flavorAsset->setStatusLocalReady();
                 } else {
                     $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED);
                     $flavorAsset->setDeletedAt(time());
                 }
                 $flavorAsset->save();
                 if ($sourceIncludedInProfile) {
                     kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset);
                 }
             }
             return null;
         }
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     $batchJob->setObjectId($entry->getId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     if ($importingSources) {
         $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
 private function getBestSyncKeyForEntry(entry $entry)
 {
     $entryType = $entry->getType();
     $entryMediaType = $entry->getMediaType();
     $syncKey = null;
     switch ($entryType) {
         case entryType::MEDIA_CLIP:
             switch ($entryMediaType) {
                 case entry::ENTRY_MEDIA_TYPE_IMAGE:
                     $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                     break;
             }
             break;
     }
     return $syncKey;
 }
Esempio n. 17
0
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @param kMrssParameters $mrssParams
  * @params string $features
  * @return SimpleXMLElement
  */
 public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null, $features = null)
 {
     $instanceKey = self::generateInstanceKey($entry->getId(), $mrssParams, $features);
     if (is_null($mrss)) {
         $mrss = self::getInstanceFromPool($instanceKey);
         if ($mrss) {
             return $mrss;
         }
         $encoding = 'UTF-8';
         if ($mrssParams && !is_null($mrssParams->getEncoding())) {
             $encoding = $mrssParams->getEncoding();
         }
         if ($encoding) {
             $mrss = new SimpleXMLElement('<?xml version="1.0" encoding="' . $encoding . '"?><item/>');
         } else {
             $mrss = new SimpleXMLElement('<item/>');
         }
     }
     $mrss->addChild('entryId', $entry->getId());
     if ($entry->getReferenceID()) {
         $mrss->addChild('referenceID', self::stringToSafeXml($entry->getReferenceID()));
     }
     $mrss->addChild('createdAt', $entry->getCreatedAt(null));
     $mrss->addChild('updatedAt', $entry->getUpdatedAt(null));
     $mrss->addChild('title', self::stringToSafeXml($entry->getName()));
     if ($mrssParams && !is_null($mrssParams->getLink())) {
         $mrss->addChild('link', $mrssParams->getLink() . $entry->getId());
     }
     $mrss->addChild('type', $entry->getType());
     $mrss->addChild('licenseType', $entry->getLicenseType());
     $mrss->addChild('userId', $entry->getPuserId());
     $mrss->addChild('name', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('status', self::stringToSafeXml($entry->getStatus()));
     $mrss->addChild('description', self::stringToSafeXml($entry->getDescription()));
     $thumbnailUrl = $mrss->addChild('thumbnailUrl');
     $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl());
     if (trim($entry->getTags(), " \r\n\t")) {
         $tags = $mrss->addChild('tags');
         foreach (explode(',', $entry->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $categories = explode(',', $entry->getCategories());
     if (count($features) && in_array(ObjectFeatureType::CATEGORY_ENTRIES, $features)) {
         $partner = PartnerPeer::retrieveByPK(kCurrentContext::getCurrentPartnerId());
         $partnerEntitlement = $partner->getDefaultEntitlementEnforcement();
         kEntitlementUtils::initEntitlementEnforcement($partner->getId(), false);
         $categories = array();
         $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId());
         $categoryIds = array();
         foreach ($categoryEntries as $categoryEntry) {
             $categoryIds[] = $categoryEntry->getCategoryId();
         }
         $entryCats = categoryPeer::retrieveByPKs($categoryIds);
         foreach ($entryCats as $entryCat) {
             $categories[] = $entryCat->getFullName();
         }
         if ($partnerEntitlement) {
             kEntitlementUtils::initEntitlementEnforcement($partner->getId(), true);
         }
         $keyToDelete = array_search(ObjectFeatureType::CATEGORY_ENTRIES, $features);
         unset($features[$keyToDelete]);
     }
     foreach ($categories as $category) {
         $category = trim($category);
         if ($category) {
             $categoryNode = $mrss->addChild('category', self::stringToSafeXml($category));
             if (strrpos($category, '>') > 0) {
                 $categoryNode->addAttribute('name', self::stringToSafeXml(substr($category, strrpos($category, '>') + 1)));
             } else {
                 $categoryNode->addAttribute('name', self::stringToSafeXml($category));
             }
         }
     }
     $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData()));
     if ($entry->getAccessControlId()) {
         $mrss->addChild('accessControlId', $entry->getAccessControlId());
     }
     if ($entry->getConversionProfileId()) {
         $mrss->addChild('conversionProfileId', $entry->getConversionProfileId());
     }
     if ($entry->getStartDate(null)) {
         $mrss->addChild('startDate', $entry->getStartDate(null));
     }
     if ($entry->getEndDate(null)) {
         $mrss->addChild('endDate', $entry->getEndDate(null));
     }
     switch ($entry->getType()) {
         case entryType::MEDIA_CLIP:
             self::appendMediaEntryMrss($entry, $mrss);
             break;
         case entryType::MIX:
             self::appendMixEntryMrss($entry, $mrss);
             break;
         case entryType::PLAYLIST:
             self::appendPlaylistEntryMrss($entry, $mrss);
             break;
         case entryType::DATA:
             self::appendDataEntryMrss($entry, $mrss);
             break;
         case entryType::LIVE_STREAM:
             self::appendLiveStreamEntryMrss($entry, $mrss);
             break;
         default:
             break;
     }
     $assetsStatuses = array(asset::ASSET_STATUS_READY);
     if ($mrssParams && $mrssParams->getStatuses()) {
         $assetsStatuses = $mrssParams->getStatuses();
     }
     $assets = assetPeer::retrieveReadyByEntryId($entry->getId(), null, $assetsStatuses);
     foreach ($assets as $asset) {
         if ($mrssParams && !is_null($mrssParams->getFilterByFlavorParams()) && $asset->getFlavorParamsId() != $mrssParams->getFilterByFlavorParams()) {
             continue;
         }
         if ($asset instanceof flavorAsset) {
             self::appendFlavorAssetMrss($asset, $mrss, $mrssParams);
         }
         if ($asset instanceof thumbAsset) {
             self::appendThumbAssetMrss($asset, $mrss);
         }
     }
     $mrssContributors = self::getMrssContributors();
     if (count($mrssContributors)) {
         foreach ($mrssContributors as $mrssContributor) {
             try {
                 if (!count($features) || in_array($mrssContributor->getObjectFeatureType(), $features)) {
                     $mrssContributor->contribute($entry, $mrss, $mrssParams);
                 }
             } catch (kCoreException $ex) {
                 KalturaLog::err("Unable to add MRSS element for contributor [" . get_class($mrssContributor) . "] message [" . $ex->getMessage() . "]");
             }
         }
     }
     if ($mrssParams && $mrssParams->getIncludePlayerTag()) {
         $uiconfId = !is_null($mrssParams->getPlayerUiconfId()) ? '/ui_conf_id/' . $mrssParams->getPlayerUiconfId() : '';
         $playerUrl = kConf::get('apphome_url') . '/kwidget/wid/_' . $entry->getPartnerId() . '/entry_id/' . $entry->getId() . '/ui_conf' . ($uiconfId ? "/{$uiconfId}" : '');
         $player = $mrss->addChild('player');
         $player->addAttribute('url', $playerUrl);
     }
     if ($mrssParams && $mrssParams->getItemXpathsToExtend()) {
         self::addExtendingItemsToMrss($mrss, $mrssParams);
     }
     self::addInstanceToPool($instanceKey, $mrss);
     return $mrss;
 }
 private function handleEntry($onlyExtractThumb, $prefix, $type, $entry_id, $name = null, $tags = null, $entry = null)
 {
     KalturaLog::debug("handleEntry({$type}, {$entry_id}, {$name})");
     $this->clear($prefix, $entry_id);
     $kuser_id = $this->kuser_id;
     $entry_data_prefix = $kuser_id . '_' . ($prefix == '' ? 'data' : rtrim($prefix, '_'));
     $uploads = myContentStorage::getFSUploadsPath();
     $content = myContentStorage::getFSContentRootPath();
     $media_source = $this->getParam('entry_media_source');
     $media_type = $this->getParam('entry_media_type');
     $entry_url = $this->getParam('entry_url');
     $entry_source_link = $this->getParam('entry_source_link');
     $entry_fileName = $this->getParam('entry_data');
     $entry_thumbNum = $this->getParam('entry_thumb_num', 0);
     $entry_thumbUrl = $this->getParam('entry_thumb_url', '');
     $should_copy = $this->getParam('should_copy', false);
     $skip_conversion = $this->getParam('skip_conversion', false);
     $webcam_suffix = $this->getParam('webcam_suffix', '');
     $duration = $this->getParam('duration', null);
     $entry_fullPath = "";
     $ext = null;
     $entry = null;
     if ($entry_id) {
         $entry = entryPeer::retrieveByPK($entry_id);
     } else {
         $entry = new entry();
     }
     $this->entry = $entry;
     $entry_status = $entry->getStatus();
     if (is_null($entry_status)) {
         $entry_status = entryStatus::READY;
     }
     // by the end of this block of code $entry_fullPath will point to the location of the entry
     // the entry status will be set (IMPORT / PRECONVERT / READY)
     // a background image is always previewed by the user no matter what source he used
     // so the entry is already in the /uploads directory
     // continue tracking the file upload
     $te = new TrackEntry();
     $te->setEntryId($entry_id);
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
     KalturaLog::debug("handleEntry: media_source: {$media_source}, prefix: {$prefix}");
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE || $prefix == 'bg_') {
         $full_path = $this->getParam('entry_full_path');
         if ($full_path) {
             $entry_fullPath = $full_path;
         } else {
             $entry_fullPath = $uploads . $entry_data_prefix . strrchr($entry_fileName, '.');
         }
         if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $entry_status = entryStatus::PRECONVERT;
         }
         $te->setParam3Str($entry_fullPath);
         $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
     } else {
         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             // set $entry_fileName to webcam output file and flag that conversion is not needed
             $webcam_basePath = $content . '/content/webcam/' . ($webcam_suffix ? $webcam_suffix : 'my_recorded_stream_' . $kuser_id);
             $entry_fullPath = $webcam_basePath . '.' . kWAMSWebcam::OUTPUT_FILE_EXT;
             $ext = kWAMSWebcam::OUTPUT_FILE_EXT;
             if (file_exists($entry_fullPath)) {
                 // continue tracking the webcam
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_WEBCAM");
             } else {
                 KalturaLog::err("File [{$entry_fullPath}] does not exist");
                 $entry_status = entryStatus::ERROR_IMPORTING;
             }
         } else {
             // if the url ends with .ext, we'll extract it this way
             $urlext = strrchr($entry_url, '.');
             // TODO: fix this patch
             if (strlen($urlext) > 4) {
                 $urlext = '.jpg';
             }
             // if we got something wierd, assume we're downloading a jpg
             $entry_fileName = $entry_data_prefix . $urlext;
             KalturaLog::debug("handleEntry: media_type: {$media_type}");
             if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 $duration = 0;
                 $entry_fullPath = $uploads . $entry_fileName;
                 if (!kFile::downloadUrlToFile($entry_url, $entry_fullPath)) {
                     KalturaLog::debug("Failed downloading file[{$entry_url}]");
                     $entry_status = entryStatus::ERROR_IMPORTING;
                 }
                 // track images
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_IMAGE");
             } else {
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                     //fixme - we can extract during import
                     $ext = "flv";
                 } else {
                     $ext = "mp3";
                 }
                 $entry_status = entryStatus::IMPORT;
                 // track images
                 $te->setParam3Str($ext);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_VIDEO");
             }
         }
     }
     if ($ext == null) {
         $entry_fullPathTmp = $entry_fullPath;
         $qpos = strpos($entry_fullPathTmp, "?");
         if ($qpos !== false) {
             $entry_fullPathTmp = substr($entry_fullPathTmp, 0, $qpos);
         }
         $ext = strtolower(pathinfo($entry_fullPathTmp, PATHINFO_EXTENSION));
     }
     // save the Trackentry
     TrackEntry::addTrackEntry($te);
     KalturaLog::debug("handleEntry: ext: {$ext}");
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		if ($entry_status == entryStatus::PRECONVERT && !myContentStorage::fileExtNeedConversion($ext))
     //		{
     //
     //			$this->errorMsg = "insertEntryAction Error - PRECONVERT file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     $media_date = null;
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		// if entry is ready, validate file type (webcam is an exception since we control the file type - flv)
     //		if ($entry_status == entryStatus::READY &&
     //			$media_source != entry::ENTRY_MEDIA_SOURCE_WEBCAM && !myContentStorage::fileExtAccepted($ext))
     //		{
     //			$this->errorMsg = "insertEntryAction Error - READY file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     if ($entry_status == entryStatus::ERROR_IMPORTING) {
         $need_thumb = false;
         // we wont be needing a thumb for an errornous entry
         KalturaLog::debug("handleEntry: error importing, thumb not needed");
     } else {
         // thumbs are created by one of the following ways:
         // 1. Image - images are already on disk for every selection method, so we can just create a thumb
         // 2. Audio - no thumb is needed
         // 3. Video -
         //		a. uploaded (file / webcam) - file is on disk and the user already selected a thumb
         //		b. imported - the source site had a thumbnail and we'll use it
         $thumbTempPrefix = $uploads . $entry_data_prefix . '_thumbnail_';
         $thumbBigFullPath = null;
         $need_thumb = $type == entryType::MEDIA_CLIP;
         KalturaLog::debug("handleEntry: handling media {$media_type}");
         if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             // fetch media creation date
             $exif_image_type = @exif_imagetype($entry_fullPath);
             if ($exif_image_type == IMAGETYPE_JPEG || $exif_image_type == IMAGETYPE_TIFF_II || $exif_image_type == IMAGETYPE_TIFF_MM || $exif_image_type == IMAGETYPE_IFF || $exif_image_type == IMAGETYPE_PNG) {
                 $exif_data = @exif_read_data($entry_fullPath);
                 if ($exif_data && isset($exif_data["DateTimeOriginal"]) && $exif_data["DateTimeOriginal"]) {
                     $media_date = $exif_data["DateTimeOriginal"];
                     $ts = strtotime($media_date);
                     // handle invalid dates either due to bad format or out of range
                     if ($ts === -1 || $ts === false || $ts < strtotime('2000-01-01') || $ts > strtotime('2015-01-01')) {
                         $media_date = null;
                     }
                 }
             }
             // create thumb
             $thumbFullPath = $thumbTempPrefix . '1.jpg';
             $entry_thumbNum = 1;
             $need_thumb = true;
             //copy($entry_fullPath, $thumbFullPath);
             myFileConverter::createImageThumbnail($entry_fullPath, $thumbFullPath, "image2");
             //$thumbBigFullPath = $thumbFullPath; // no filesync for thumbnail of image
         } else {
             if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                 if ($entry_status == entryStatus::IMPORT || $media_source == entry::ENTRY_MEDIA_SOURCE_URL) {
                     // import thumb and convert to our size
                     $thumbFullPath = $thumbTempPrefix . '1.jpg';
                     $entry_thumbNum = 1;
                     $importedThumbPath = $uploads . $entry_data_prefix . '_temp_thumb' . strrchr($entry_thumbUrl, '.');
                     if (kFile::downloadUrlToFile($entry_thumbUrl, $importedThumbPath)) {
                         myFileConverter::createImageThumbnail($importedThumbPath, $thumbFullPath, "image2");
                         // set thumb as big thumb so fileSync will be created.
                         $thumbBigFullPath = $thumbFullPath;
                     } else {
                         $need_thumb = false;
                     }
                 } else {
                     if ($entry_thumbNum == 0) {
                         $entry_thumbNum = 1;
                         $thumbTime = 3;
                         if ($duration && $duration < $thumbTime * 1000) {
                             $thumbTime = floor($duration / 1000);
                         }
                         // for videos - thumbail should be created in post convert
                         // otherwise this code will fail if the thumbanil wasn't created successfully (roman)
                         //myFileConverter::autoCaptureFrame($entry_fullPath, $thumbTempPrefix."big_", $thumbTime, -1, -1);
                         $need_thumb = false;
                         $thumbBigFullPath = $thumbTempPrefix . "big_" . $entry_thumbNum . '.jpg';
                     }
                 }
                 //else select existing thumb ($entry_thumbNum already points to the right thumbnail)
             }
         }
         $thumbFullPath = $thumbTempPrefix . $entry_thumbNum . '.jpg';
         // if we arrived here both entry and thumbnail are valid we can now update the db
         // in order to have the final entry_id and move its data to its final destination
         if ($onlyExtractThumb) {
             return $thumbFullPath;
         }
     }
     $entry->setkshowId($this->kshow_id);
     $entry->setKuserId($kuser_id);
     $entry->setCreatorKuserId($kuser_id);
     if ($this->partner_id != null) {
         $entry->setPartnerId($this->partner_id);
         $entry->setSubpId($this->subp_id);
     }
     $entry->setName($name ? $name : $this->getParam('entry_name'));
     //		$entry->setDescription('');//$this->getParam('entry_description'));
     $entry->setType($type);
     $entry->setMediaType($media_type);
     $entry->setTags($tags ? $tags : $this->getParam('entry_tags'));
     $entry->setSource($media_source);
     $entry->setSourceId($this->getParam('entry_media_id'));
     if ($media_date) {
         $entry->setMediaDate($media_date);
     }
     // if source_link wasnt given use the entry_url HOWEVER, use it only if id doesnt contain @ which suggests the use of a password
     $entry->setSourceLink($entry_source_link ? $entry_source_link : (strstr($entry_url, '@') ? "" : $entry_url));
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE) {
         $entry->setSourceLink("file:{$entry_fullPath}");
     }
     $entry->setLicenseType($this->getParam('entry_license'));
     $entry->setCredit($this->getParam('entry_credit'));
     $entry->setStatus($entry_status);
     if ($duration !== null) {
         $entry->setLengthInMsecs($duration);
     }
     if ($this->entry_id == 0) {
         $entry->save();
         $this->entry_id = $entry->getId();
     }
     // move thumb to final destination and set db entry
     if ($media_type != entry::ENTRY_MEDIA_TYPE_AUDIO && $entry_thumbNum && $need_thumb) {
         KalturaLog::debug("handleEntry: saving none audio thumb [{$thumbBigFullPath}]");
         $entry->setThumbnail('.jpg');
         if ($thumbBigFullPath) {
             if ($media_type != entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 myFileConverter::convertImage($thumbBigFullPath, $thumbFullPath);
             }
             /*$thumbBigFinalPath = $content.$entry->getBigThumbnailPath();
             		myContentStorage::moveFile($thumbBigFullPath, $thumbBigFinalPath, true , $should_copy );
             		*/
             $entryThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             try {
                 if (!$should_copy) {
                     kFileSyncUtils::moveFromFile($thumbBigFullPath, $entryThumbKey);
                 } else {
                     kFileSyncUtils::copyFromFile($thumbBigFullPath, $entryThumbKey);
                 }
             } catch (Exception $e) {
                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 $entry->save();
                 throw $e;
             }
         }
     }
     // after extracting the thumb we can move the entry to its next destination
     KalturaLog::debug("handleEntry: current status [" . $entry->getStatus() . "]");
     // if needed a job will be submitted for importing external media sources
     if ($entry->getStatus() == entryStatus::IMPORT) {
         KalturaLog::debug("handleEntry: creating import job");
         // changed by Tan-Tan, Nov 09 to support the new batch mechanism
         kJobsManager::addImportJob(null, $this->entry_id, $this->partner_id, $entry_url);
         // remarked by Tan-Tan
         //			$entry_fullPath = $content.'/content/imports/data/'.$this->entry_id.".".$ext;
         //			myContentStorage::fullMkdir($entry_fullPath);
         //
         //			$batchClient = new myBatchUrlImportClient();
         // 			$batchClient->addJob($this->entry_id, $entry_url, $entry_fullPath);
     } else {
         if ($entry->getStatus() == entryStatus::PRECONVERT) {
             if (!$skip_conversion) {
                 // changed by Tan-Tan, Dec 09 to support the new batch mechanism
                 KalturaLog::debug("handleEntry: creating original flavor asset for pre convert");
                 $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                 if ($flavorAsset) {
                     $flavorAsset->setFileExt($ext);
                     $flavorAsset->save();
                     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     try {
                         kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                     } catch (Exception $e) {
                         $entry->setStatus(entryStatus::ERROR_CONVERTING);
                         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                         $entry->save();
                         $flavorAsset->save();
                         throw $e;
                     }
                     kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                 } else {
                     $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 }
                 //				Remarked by Tan-Tan
                 //				$targetFileName = $this->entry_id.".".$ext;
                 //				if ( false /* old conversion */)
                 //				{
                 //								// if we need to convert move entry to conversion directory
                 //								$preConvPath = $content.'/content/preconvert/';
                 //								myContentStorage::moveFile($entry_fullPath, $preConvPath."data/".$targetFileName, true , $should_copy );
                 //
                 //								$signalFilePath = $preConvPath."files/".$targetFileName;
                 //								myContentStorage::fullMkdir($signalFilePath);
                 //								touch($signalFilePath);
                 //				}
                 //				else
                 //				{
                 //								$preConvPath = myContentStorage::getFSContentRootPath (). "/content/new_preconvert";
                 //								$to_data = $preConvPath . "/$targetFileName" ;
                 //								myContentStorage::moveFile($entry_fullPath, $to_data , true);
                 //								touch ( $to_data . ".indicator" );
                 //				}
             }
         } else {
             if ($entry->getStatus() == entryStatus::PENDING || $media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                 $entry->setData($entry_fullPath);
                 $entry->save();
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
                     KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                     $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                     if ($flavorAsset) {
                         $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                         $flavorAsset->setFileExt($ext);
                         $flavorAsset->save();
                         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         try {
                             if (!$should_copy) {
                                 kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                             } else {
                                 // copy & create file sync from $entry_fullPath
                                 kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                             }
                         } catch (Exception $e) {
                             $entry->setStatus(entryStatus::ERROR_CONVERTING);
                             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                             $entry->save();
                             $flavorAsset->save();
                             throw $e;
                         }
                         //					// bypass to conversion
                         //					kBusinessPreConvertDL::bypassConversion($flavorAsset, $entry);
                         /**
                          * if this is webcam entry, create mediaInfo for the source flavor asset synchronously
                          * since entry is ready right at the beginning
                          */
                         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                             require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "api_v3" . DIRECTORY_SEPARATOR . "bootstrap.php";
                             // extract file path
                             $sourceFileKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($sourceFileKey);
                             // call mediaInfo for file
                             $mediaInfo = new mediaInfo();
                             try {
                                 $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
                                 $KalturaMediaInfo = new KalturaMediaInfo();
                                 $KalturaMediaInfo = $mediaInfoParser->getMediaInfo();
                                 $mediaInfo = $KalturaMediaInfo->toInsertableObject($mediaInfo);
                                 $mediaInfo->setFlavorAssetId($flavorAsset->getId());
                                 $mediaInfo->save();
                             } catch (Exception $e) {
                                 KalturaLog::err("Getting media info: " . $e->getMessage());
                                 $mediaInfo = null;
                             }
                             // fix flavor asset according to mediainfo
                             if ($mediaInfo) {
                                 KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfo, $flavorAsset);
                                 $flavorTags = KDLWrap::CDLMediaInfo2Tags($mediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
                                 $flavorAsset->setTags(implode(',', $flavorTags));
                             }
                             $flavorAsset->save();
                         }
                         kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         $flavorAsset->setStatusLocalReady();
                         $flavorAsset->save();
                     } else {
                         $entry->setStatus(entryStatus::ERROR_IMPORTING);
                     }
                 } else {
                     if ($entry->getType() == entryType::DOCUMENT) {
                         //TODO: document should be handled by the plugin manager)
                         KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                         $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                         if ($flavorAsset) {
                             $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                             $flavorAsset->setFileExt($ext);
                             $flavorAsset->save();
                             $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                                 $entry->save();
                                 $flavorAsset->save();
                                 throw $e;
                             }
                             kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         }
                     } else {
                         KalturaLog::debug("handleEntry: creating data file sync for file [{$entry_fullPath}]");
                         $entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                         if (!kFileSyncUtils::file_exists($entryDataKey)) {
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $entry->save();
                                 throw $e;
                             }
                         }
                         $entry->setStatus(entryStatus::READY);
                         $entry->save();
                     }
                 }
                 //			Remarked by Tan-Tan, the flavor asset should be synced instead of the entry
                 //
                 //			$entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                 //			if(!$should_copy)
                 //			{
                 //				kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                 //			}
                 //			else
                 //			{
                 //				// copy & create file sync from $entry_fullPath
                 //				kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                 //			}
             }
         }
     }
     if ($entry->getStatus() == entryStatus::READY) {
         $entry->updateDimensions();
     }
     $entry->save();
     return true;
 }
Esempio n. 19
0
 private static function handleOperatorsProcessingFinished(flavorAsset $flavorAsset, flavorParamsOutput $flavorParamsOutput, entry $entry, BatchJob $dbBatchJob, kConvertJobData $data, $rootBatchJob = null)
 {
     $offset = $entry->getThumbOffset();
     // entry getThumbOffset now takes the partner DefThumbOffset into consideration
     $createThumb = $entry->getCreateThumb();
     $extractMedia = true;
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         // e.g. document
         $extractMedia = false;
     }
     if (!kFileSyncUtils::fileSync_exists($flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET))) {
         $extractMedia = false;
         $createThumb = false;
     }
     $rootBatchJob = $dbBatchJob->getRootJob();
     if ($extractMedia && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
         $rootBatchJobData = $rootBatchJob->getData();
         if ($rootBatchJobData instanceof kConvertProfileJobData) {
             $extractMedia = $rootBatchJobData->getExtractMedia();
         }
     }
     // For apple http flavors do not attempt to get thumbs and media info,
     // It is up to the operator to provide that kind of data, rather than hardcoded check
     // To-fix
     if ($flavorParamsOutput->getFormat() == assetParams::CONTAINER_FORMAT_APPLEHTTP) {
         $createThumb = false;
         $extractMedia = false;
     }
     if ($flavorParamsOutput->getFormat() == assetParams::CONTAINER_FORMAT_WIDEVINE) {
         $createThumb = false;
     }
     if ($createThumb && in_array($flavorParamsOutput->getVideoCodec(), self::$thumbUnSupportVideoCodecs)) {
         $createThumb = false;
     }
     if ($createThumb || $extractMedia) {
         $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
         if ($flavorAsset->getIsOriginal()) {
             $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE;
         }
         kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $data->getDestFileSyncLocalPath(), $data->getFlavorAssetId(), $flavorParamsOutput->getId(), $createThumb, $offset);
     } else {
         $flavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId());
         if ($flavorAsset) {
             if ($flavorAsset->hasTag(flavorParams::TAG_SOURCE)) {
                 kBusinessPreConvertDL::continueProfileConvert($dbBatchJob);
             }
             if ($flavorAsset->getType() == assetType::FLAVOR) {
                 $flavorAsset->setBitrate($flavorParamsOutput->getVideoBitrate() + $flavorParamsOutput->getAudioBitrate());
                 $flavorAsset->setWidth($flavorParamsOutput->getWidth());
                 $flavorAsset->setHeight($flavorParamsOutput->getHeight());
                 $flavorAsset->setFrameRate($flavorParamsOutput->getFrameRate());
                 $flavorAsset->setIsOriginal(0);
                 $flavorAsset->save();
             }
             kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $flavorAsset);
         }
     }
 }
Esempio n. 20
0
 protected function addEntryFromFlavorAsset(KalturaBaseEntry $newEntry, entry $srcEntry, flavorAsset $srcFlavorAsset)
 {
     $newEntry->type = $srcEntry->getType();
     if ($newEntry->name === null) {
         $newEntry->name = $srcEntry->getName();
     }
     if ($newEntry->description === null) {
         $newEntry->description = $srcEntry->getDescription();
     }
     if ($newEntry->creditUrl === null) {
         $newEntry->creditUrl = $srcEntry->getSourceLink();
     }
     if ($newEntry->creditUserName === null) {
         $newEntry->creditUserName = $srcEntry->getCredit();
     }
     if ($newEntry->tags === null) {
         $newEntry->tags = $srcEntry->getTags();
     }
     $newEntry->sourceType = KalturaSourceType::SEARCH_PROVIDER;
     $newEntry->searchProviderType = KalturaSearchProviderType::KALTURA;
     $dbEntry = $this->prepareEntryForInsert($newEntry);
     $dbEntry->setSourceId($srcEntry->getId());
     $kshow = $this->createDummyKShow();
     $kshowId = $kshow->getId();
     $msg = null;
     $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId(), $msg);
     if (!$flavorAsset) {
         KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "] reason [{$msg}]");
         if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
             $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
             $dbEntry->save();
         }
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED, $msg);
     }
     $srcSyncKey = $srcFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::createSyncFileLinkForKey($newSyncKey, $srcSyncKey);
     kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
     $newEntry->fromObject($dbEntry, $this->getResponseProfile());
     return $newEntry;
 }
Esempio n. 21
0
 public static function copyEntryData(entry $entry, entry $targetEntry)
 {
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = true;
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         $shouldCopyDataForNonClip = false;
     }
     if ($entry->getType() == entryType::PLAYLIST) {
         $shouldCopyDataForNonClip = false;
     }
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceAssets = assetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceAssets as $sourceAsset) {
         $sourceAsset->copyToEntry($targetEntry->getId(), $targetEntry->getPartnerId());
     }
 }
 public function typeMatches(entry $entry)
 {
     if ($this->get('_eq_type') && $entry->getType() != $this->get('_eq_type')) {
         return false;
     }
     if ($this->get('_in_type') && !in_array($entry->getType(), explode(',', $this->get('_in_type')))) {
         return false;
     }
     return true;
 }
Esempio n. 23
0
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (filesize($inputFileSyncLocalPath) == 0) {
         $entry->setStatus(entryStatus::ERROR_CONVERTING);
         $entry->save();
         $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId);
         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
         $flavorAsset->setDescription('Entry of size 0 should not be converted');
         $flavorAsset->save();
         KalturaLog::err('Entry of size 0 should not be converted');
         return null;
     }
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
         $entry->save();
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $jobData->setCreateThumb(false);
     }
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild();
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }