public function __construct(KalturaDistributionJobData $distributionJobData = null) { if (!$distributionJobData) { return; } if (!$distributionJobData->distributionProfile instanceof KalturaDailymotionDistributionProfile) { return; } $flavorAssets = flavorAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds)); if (count($flavorAssets)) { // if we have specific flavor assets for this distribution, grab the first one $flavorAsset = reset($flavorAssets); } else { // take the source asset $flavorAsset = flavorAssetPeer::retrieveOriginalReadyByEntryId($distributionJobData->entryDistribution->entryId); } if ($flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); } $thumbAssets = thumbAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds)); if (count($thumbAssets)) { $syncKey = reset($thumbAssets)->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); } }
public function __construct(KalturaDistributionJobData $distributionJobData = null) { if (!$distributionJobData) { return; } if (!$distributionJobData->distributionProfile instanceof KalturaYoutubeApiDistributionProfile) { return; } $flavorAssets = flavorAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds)); if (count($flavorAssets)) { // if we have specific flavor assets for this distribution, grab the first one $flavorAsset = reset($flavorAssets); } else { // take the source asset $flavorAsset = flavorAssetPeer::retrieveOriginalReadyByEntryId($distributionJobData->entryDistribution->entryId); } if ($flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); } $thumbAssets = thumbAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds)); if (count($thumbAssets)) { $syncKey = reset($thumbAssets)->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); } $this->loadPlaylistsFromMetadata($distributionJobData->entryDistribution->entryId, $distributionJobData->distributionProfile); $entryDistributionDb = EntryDistributionPeer::retrieveByPK($distributionJobData->entryDistributionId); // if ($entryDistributionDb) // $this->currentPlaylists = $entryDistributionDb->getFromCustomData('currentPlaylists'); // else // KalturaLog::err('Entry distribution ['.$distributionJobData->entryDistributionId.'] not found'); }
public static function getInstance() { if (!self::$myInstance) { self::$myInstance = new thumbAssetPeer(); } if (!self::$instance || !self::$instance instanceof thumbAssetPeer) { self::$instance = self::$myInstance; } return self::$myInstance; }
public function initService($serviceId, $serviceName, $actionName) { parent::initService($serviceId, $serviceName, $actionName); parent::applyPartnerFilterForClass(new conversionProfile2Peer()); parent::applyPartnerFilterForClass(thumbAssetPeer::getInstance()); parent::applyPartnerFilterForClass(thumbParamsOutputPeer::getInstance()); $partnerGroup = null; if ($actionName == 'get' || $actionName == 'list') { $partnerGroup = $this->partnerGroup . ',0'; } parent::applyPartnerFilterForClass(thumbParamsPeer::getInstance(), $partnerGroup); }
/** * Called on the server side and enables you to populate the object with any data from the DB * * @param KalturaDistributionJobData $distributionJobData */ public function __construct(KalturaDistributionJobData $distributionJobData = null) { if (!$distributionJobData) { return; } if (!$distributionJobData->distributionProfile instanceof KalturaExampleDistributionProfile) { return; } $this->videoAssetFilePaths = new KalturaExampleDistributionAssetPathArray(); // loads all the flavor assets that should be submitted to the remote destination site $flavorAssets = flavorAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds)); foreach ($flavorAssets as $flavorAsset) { $videoAssetFilePath = new KalturaExampleDistributionAssetPath(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $videoAssetFilePath->path = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); $this->videoAssetFilePaths[] = $videoAssetFilePath; } $thumbAssets = thumbAssetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds)); if (count($thumbAssets)) { $thumbAsset = reset($thumbAssets); $syncKey = $thumbAssets->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, true); } }
/** * decideThumbGenerate is the decision layer for a single thumbnail generation * * @param entry $entry * @param thumbParams $destThumbParams * @param BatchJob $parentJob * @return thumbAsset */ public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false) { $srcAsset = null; assetPeer::resetInstanceCriteriaFilter(); if ($sourceAssetId) { $srcAsset = assetPeer::retrieveById($sourceAssetId); } else { if ($destThumbParams->getSourceParamsId()) { KalturaLog::debug("Look for flavor params [" . $destThumbParams->getSourceParamsId() . "]"); $srcAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getSourceParamsId()); } if (is_null($srcAsset)) { KalturaLog::debug("Look for original flavor"); $srcAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); } if (is_null($srcAsset) || $srcAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::debug("Look for highest bitrate flavor"); $srcAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId()); } } if (is_null($srcAsset)) { throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY); } $errDescription = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription); $thumbAsset = thumbAssetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId()); if ($thumbAsset) { $description = $thumbAsset->getDescription() . "\n" . $errDescription; $thumbAsset->setDescription($description); } else { $thumbAsset = new thumbAsset(); $thumbAsset->setPartnerId($entry->getPartnerId()); $thumbAsset->setEntryId($entry->getId()); $thumbAsset->setDescription($errDescription); $thumbAsset->setFlavorParamsId($destThumbParams->getId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); $thumbAsset->setTags($destThumbParamsOutput->getTags()); $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt()); if (!$destThumbParamsOutput) { $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); return null; } $thumbAsset->save(); // save flavor params $destThumbParamsOutput->setPartnerId($entry->getPartnerId()); $destThumbParamsOutput->setEntryId($entry->getId()); $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId()); $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion()); $destThumbParamsOutput->save(); $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcAssetType = $srcAsset->getType(); if (!$runSync) { $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAssetType, $destThumbParamsOutput); return $thumbAsset; } $errDescription = null; $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription); // failed if (!$capturedPath) { $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}"); $thumbAsset->save(); return $thumbAsset; } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); if (file_exists($capturedPath)) { list($width, $height, $type, $attr) = getimagesize($capturedPath); $thumbAsset->setWidth($width); $thumbAsset->setHeight($height); $thumbAsset->setSize(filesize($capturedPath)); } $logPath = $capturedPath . '.log'; if (file_exists($logPath)) { $thumbAsset->incLogFileVersion(); $thumbAsset->save(); // creats the file sync $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); kFileSyncUtils::moveFromFile($logPath, $logSyncKey); KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey)); } else { $thumbAsset->save(); } $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($capturedPath, $syncKey); KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { // increment thumbnail version $entry->setThumbnail(".jpg"); $entry->save(); $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey, false); if ($syncFile) { // removes the DEFAULT_THUMB tag from all other thumb assets $entryThumbAssets = thumbAssetPeer::retrieveByEntryId($thumbAsset->getEntryId()); foreach ($entryThumbAssets as $entryThumbAsset) { if ($entryThumbAsset->getId() == $thumbAsset->getId()) { continue; } if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { continue; } $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB)); $entryThumbAsset->save(); } } } if (!is_null($thumbAsset->getFlavorParamsId())) { kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId()); } return $thumbAsset; }
/** * @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; }
/** * @param BatchJob $parentJob * @param int $srcParamsId */ public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null) { $profile = null; try { $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId); } catch (Exception $e) { KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage()); } if (!$profile) { KalturaLog::notice("Profile not found for entry id [{$entryId}]"); return; } $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { KalturaLog::notice("Entry id [{$entryId}] not found"); return; } $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId()); if (!count($assetParamsIds)) { KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]"); return; } // the alternative is the source or the highest bitrate if source not defined $alternateFlavorParamsId = null; if (is_null($srcParamsId)) { $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds); foreach ($flavorParamsObjects as $flavorParams) { if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) { $alternateFlavorParamsId = $flavorParams->getId(); } } if (is_null($alternateFlavorParamsId)) { $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId); $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId(); } if (is_null($alternateFlavorParamsId)) { KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]"); return; } } // create list of created thumbnails $thumbAssetsList = array(); $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId); if (count($thumbAssets)) { foreach ($thumbAssets as $thumbAsset) { if (!is_null($thumbAsset->getFlavorParamsId())) { $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset; } } } $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds); foreach ($thumbParamsObjects as $thumbParams) { // check if this thumbnail already created if (isset($thumbAssetsList[$thumbParams->getId()])) { continue; } if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) { // alternative should be used $thumbParams->setSourceParamsId($alternateFlavorParamsId); } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) { // only thumbnails that uses srcParamsId should be generated for now continue; } kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob); } }
/** * @param EntryDistribution $entryDistribution * @param entry $entry * @param DistributionProfile $distributionProfile * @return boolean true if the list of thumbnails modified */ public static function assignThumbAssets(EntryDistribution $entryDistribution, entry $entry, DistributionProfile $distributionProfile) { $thumbAssetsIds = array(); $thumbDimensions = $distributionProfile->getThumbDimensionsObjects(); $thumbDimensionsWithKeys = array(); foreach ($thumbDimensions as $thumbDimension) { $thumbDimensionsWithKeys[$thumbDimension->getKey()] = $thumbDimension; } $originalList = $entryDistribution->getThumbAssetIds(); // remove deleted thumb assets $assignedThumbAssetIds = $originalList; if ($assignedThumbAssetIds) { $thumbAssetsIds = explode(',', $assignedThumbAssetIds); $assignedThumbAssets = thumbAssetPeer::retrieveByIds($thumbAssetsIds); foreach ($assignedThumbAssets as $assignedThumbAsset) { $key = $assignedThumbAsset->getWidth() . 'x' . $assignedThumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); } } } // add new thumb assets $requiredThumbParamsIds = $distributionProfile->getAutoCreateThumbArray(); $thumbAssets = thumbAssetPeer::retreiveReadyByEntryId($entry->getId()); foreach ($thumbAssets as $thumbAsset) { if (in_array($thumbAsset->getFlavorParamsId(), $requiredThumbParamsIds)) { $thumbAssetsIds[] = $thumbAsset->getId(); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from required thumbnail params ids"); continue; } $key = $thumbAsset->getWidth() . 'x' . $thumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from dimension [{$key}]"); $thumbAssetsIds[] = $thumbAsset->getId(); } } $entryDistribution->setThumbAssetIds($thumbAssetsIds); return $originalList != $entryDistribution->getThumbAssetIds(); }
/** * @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; }
/** * @action delete * @param string $thumbAssetId * * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND */ public function deleteAction($thumbAssetId) { $thumbAssetDb = thumbAssetPeer::retrieveById($thumbAssetId); if (!$thumbAssetDb) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId); } $thumbAssetDb->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_DELETED); $thumbAssetDb->setDeletedAt(time()); $thumbAssetDb->save(); }