/** * @param entry $entry * @return array<FileSyncKey> */ protected function getEntrySyncKeys(entry $entry, StorageProfile $externalStorage) { $exportFileSyncsKeys = array(); $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); $exportFileSyncsKeys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); $flavorAssets = array(); $flavorParamsIds = $externalStorage->getFlavorParamsIds(); KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIds}]"); if (is_null($flavorParamsIds) || !strlen(trim($flavorParamsIds))) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryId($entry->getId()); } else { $flavorParamsArr = explode(',', $flavorParamsIds); KalturaLog::log(__METHOD__ . " flavorParamsIds count [" . count($flavorParamsArr) . "]"); $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndFlavorParams($entry->getId(), $flavorParamsArr); } foreach ($flavorAssets as $flavorAsset) { $exportFileSyncsKeys[] = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); } return $exportFileSyncsKeys; }
/** * @param EntryDistribution $entryDistribution * @param int $action enum from DistributionAction * @return array<kDistributionValidationError> */ public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = array(); $requiredFlavorParamsIds = $this->getRequiredFlavorParamsIdsArray(); KalturaLog::log("Required Flavor Params Ids [" . print_r($requiredFlavorParamsIds, true) . "]"); $entryFlavorAssets = flavorAssetPeer::retreiveReadyByEntryId($entryDistribution->getEntryId()); $requiredFlavorParamsIdsKeys = array_flip($requiredFlavorParamsIds); foreach ($entryFlavorAssets as $entryFlavorAsset) { $flavorParamsId = $entryFlavorAsset->getFlavorParamsId(); if (isset($requiredFlavorParamsIdsKeys[$flavorParamsId])) { unset($requiredFlavorParamsIds[$requiredFlavorParamsIdsKeys[$flavorParamsId]]); } } foreach ($requiredFlavorParamsIds as $requiredFlavorParamsId) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_FLAVOR, $requiredFlavorParamsId); } $requiredThumbDimensions = $this->getRequiredThumbDimensionsObjects(); KalturaLog::log("Required Thumb Dimensions [" . print_r($requiredThumbDimensions, true) . "]"); $entryThumbAssets = thumbAssetPeer::retreiveReadyByEntryId($entryDistribution->getEntryId()); $requiredThumbDimensionsWithKeys = array(); foreach ($requiredThumbDimensions as $requiredThumbDimension) { $key = $requiredThumbDimension->getKey(); $requiredThumbDimensionsWithKeys[$key] = $requiredThumbDimension; } foreach ($entryThumbAssets as $entryThumbAsset) { $key = $entryThumbAsset->getWidth() . 'x' . $entryThumbAsset->getHeight(); if (isset($requiredThumbDimensionsWithKeys[$key])) { unset($requiredThumbDimensionsWithKeys[$key]); } } foreach ($requiredThumbDimensionsWithKeys as $key => $requiredThumbDimension) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_THUMBNAIL, $key); } return $validationErrors; }
private function buildFlavorsArray(&$duration, $oneOnly = false) { $flavorAssets = array(); if ($this->flavorId && ($flavorAsset = flavorAssetPeer::retrieveById($this->flavorId)) != null) { if ($this->format != StorageProfile::PLAY_FORMAT_SILVER_LIGHT && $flavorAsset->hasTag(flavorParams::TAG_WEB) && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAssets[] = $flavorAsset; } if ($this->format == StorageProfile::PLAY_FORMAT_SILVER_LIGHT && $flavorAsset->hasTag(flavorParams::TAG_SLWEB) && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAssets[] = $flavorAsset; } } elseif ($oneOnly) { $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($this->entryId); if (!$flavorAsset) { $tag = flavorParams::TAG_WEB; if ($this->format == StorageProfile::PLAY_FORMAT_SILVER_LIGHT) { $tag = flavorParams::TAG_SLWEB; } elseif ($this->format == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { $tag = flavorParams::TAG_APPLEMBR; } $webFlavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, $tag); if (count($webFlavorAssets)) { $flavorAsset = reset($webFlavorAssets); } } if ($flavorAsset) { $flavorAssets[] = $flavorAsset; } } else { if ($this->flavorIds) { $tmpFlavorAssets = flavorAssetPeer::retreiveReadyByEntryId($this->entryId); $flavorAssets = array(); foreach ($tmpFlavorAssets as $flavorAsset) { if (in_array($flavorAsset->getId(), $this->flavorIds)) { $flavorAssets[] = $flavorAsset; } } } else { $tag = flavorParams::TAG_MBR; if ($this->format == StorageProfile::PLAY_FORMAT_SILVER_LIGHT) { $tag = flavorParams::TAG_SLWEB; } elseif ($this->format == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { $tag = flavorParams::TAG_APPLEMBR; } $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, $tag); if (!count($flavorAssets) && $tag == flavorParams::TAG_MBR) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB); } // if format is APPLE HTTP and there aren't any segmented flavors use ipad and iphone with // akamai hd on the fly segmenter if (!count($flavorAssets) && $this->format == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { $tmpFlavorAssets = flavorAssetPeer::retreiveReadyByEntryId($this->entryId); $flavorAssets = array(); $tagVersions = array("new", ""); // try first the ipadnew and iphonenew, optimized for segmenting (with fixed GOP and IDR frames) // if no such flavors were found, use the ipad,iphone and pray foreach ($tagVersions as $tagVersion) { foreach ($tmpFlavorAssets as $flavorAsset) { if ($flavorAsset->hasTag("ipad{$tagVersion}") || $flavorAsset->hasTag("iphone{$tagVersion}")) { $flavorAssets[] = $flavorAsset; } } if (count($flavorAssets)) { break; } } } } } $flavors = array(); $durationSet = false; foreach ($flavorAssets as $flavorAsset) { if (!$durationSet) { $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; $durationSet = true; } } $flavors[] = array('url' => $this->getFlavorHttpUrl($flavorAsset), 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight()); } return $flavors; }
/** * @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; }
DbManager::setConfig($dbConf); DbManager::initialize(); $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$storageProfile) { echo "Invalid storage profile id [{$storageProfileId}].\n\n"; echo "Usage: php exportToNetStorage.php {partner id} {storage profile id}\n"; exit; } $c = new Criteria(); $c->add(entryPeer::PARTNER_ID, $partnerId); $entries = entryPeer::doSelect($c); foreach ($entries as $entry) { $keys = array(); $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); $flavors = flavorAssetPeer::retreiveReadyByEntryId($entry->getId()); foreach ($flavors as $flavor) { $keys[] = $flavor->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); } foreach ($keys as $index => $key) { if (!kFileSyncUtils::fileSync_exists($key)) { unset($keys[$index]); continue; } if (kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageProfileId)) { unset($keys[$index]); } } if (!count($keys)) { echo $entry->getId() . " - has no keys to export\n"; continue;