public static function getInstance() { if (!self::$myInstance) { self::$myInstance = new thumbParamsPeer(); } if (!self::$instance || !self::$instance instanceof thumbParamsPeer) { self::$instance = self::$myInstance; } return self::$myInstance; }
/** * List Thumb Params by filter with paging support (By default - all system default params will be listed too) * * @action list * @param KalturaThumbParamsFilter $filter * @param KalturaFilterPager $pager * @return KalturaThumbParamsListResponse */ public function listAction(KalturaThumbParamsFilter $filter = null, KalturaFilterPager $pager = null) { if (!$filter) { $filter = new KalturaThumbParamsFilter(); } if (!$pager) { $pager = new KalturaFilterPager(); } $thumbParamsFilter = new assetParamsFilter(); $filter->toObject($thumbParamsFilter); $c = new Criteria(); $thumbParamsFilter->attachToCriteria($c); $pager->attachToCriteria($c); $dbList = thumbParamsPeer::doSelect($c); $c->setLimit(null); $totalCount = thumbParamsPeer::doCount($c); $list = KalturaThumbParamsArray::fromDbArray($dbList); $response = new KalturaThumbParamsListResponse(); $response->objects = $list; $response->totalCount = $totalCount; return $response; }
/** * @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 DistributionProfile $distributionProfile * @param bool $submitWhenReady * @return BatchJob */ public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true) { if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) { return null; } $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED); if (!in_array($entryDistribution->getStatus(), $validStatus)) { KalturaLog::notice("wrong entry distribution status [" . $entryDistribution->getStatus() . "]"); return null; } if ($submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) { $entryDistribution->setStatus(EntryDistributionStatus::QUEUED); $entryDistribution->save(); } $validationErrors = $entryDistribution->getValidationErrors(); if (!count($validationErrors)) { $sunrise = $entryDistribution->getSunrise(null); if ($sunrise) { $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) { $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise(); if ($sunrise > time()) { KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED); $entryDistribution->save(); return null; } } } return self::addSubmitAddJob($entryDistribution, $distributionProfile); } KalturaLog::log("Validation errors found"); $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId()); if (!$entry) { KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found"); return null; } $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray(); $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray(); foreach ($validationErrors as $validationError) { if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) { $errDescription = null; KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription); if ($errDescription) { KalturaLog::log($errDescription); } } if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && in_array($validationError->getData(), $autoCreateThumbs)) { $destThumbParams = thumbParamsPeer::retrieveByPK($validationError->getData()); if ($destThumbParams) { KalturaLog::log("Adding thumbnail [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams); } else { KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]"); } } } return null; }
/** * @action regenerate * @param string $thumbAssetId * @return KalturaThumbAsset * * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED * @throws KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED * @throws KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND * @throws KalturaErrors::INVALID_ENTRY_STATUS */ public function regenerateAction($thumbAssetId) { $thumbAsset = thumbAssetPeer::retrieveById($thumbAssetId); if (!$thumbAsset) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId); } if (is_null($thumbAsset->getFlavorParamsId())) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, null); } $destThumbParams = thumbParamsPeer::retrieveByPK($thumbAsset->getFlavorParamsId()); if (!$destThumbParams) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, $thumbAsset->getFlavorParamsId()); } $entry = $thumbAsset->getentry(); if ($entry->getType() != entryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED, $entry->getType()); } if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO) { throw new KalturaAPIException(KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED, $entry->getMediaType()); } $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY); if (!in_array($entry->getStatus(), $validStatuses)) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS); } $dbThumbAsset = kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams); if (!$dbThumbAsset) { return null; } $thumbAsset = new KalturaThumbAsset(); $thumbAsset->fromObject($dbThumbAsset); return $thumbAsset; }