/** * Function constructs a core object of type kBulkUploadJobData * @param int $conversionProfileId * @param string $filePath * @param string $userId * @param int $bulkUploadType * @param string $uploadedBy * @param string $fileName * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND */ protected function constructJobData($filePath, $fileName, Partner $partner, $puserId, $uploadedBy, $conversionProfileId = null, $coreBulkUploadType = null) { $data = KalturaPluginManager::loadObject('kBulkUploadJobData', $coreBulkUploadType); if (is_null($data)) { throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $coreBulkUploadType); } $data->setFilePath($filePath); $data->setUserId($puserId); $data->setUploadedBy($uploadedBy); $data->setFileName($fileName); if (!$conversionProfileId) { $conversionProfileId = $partner->getDefaultConversionProfileId(); } $kmcVersion = $partner->getKmcVersion(); $check = null; if ($kmcVersion < 2) { $check = ConversionProfilePeer::retrieveByPK($conversionProfileId); } else { $check = conversionProfile2Peer::retrieveByPK($conversionProfileId); } if (!$check) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $objectData = new kBulkUploadEntryData(); $objectData->setConversionProfileId($conversionProfileId); $data->setObjectData($objectData); return $data; }
/** * * @param int $objectType * @param string $objectId * @return ISyncableFile */ public static function retrieveObject($objectType, $objectId) { $object = null; switch ($objectType) { case FileSyncObjectType::ENTRY: entryPeer::setUseCriteriaFilter(false); $object = entryPeer::retrieveByPK($objectId); entryPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::UICONF: uiConfPeer::setUseCriteriaFilter(false); $object = uiConfPeer::retrieveByPK($objectId); uiConfPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::BATCHJOB: BatchJobPeer::setUseCriteriaFilter(false); $object = BatchJobPeer::retrieveByPK($objectId); BatchJobPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::FLAVOR_ASSET: assetPeer::setUseCriteriaFilter(false); $object = assetPeer::retrieveById($objectId); assetPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::SYNDICATION_FEED: syndicationFeedPeer::setUseCriteriaFilter(false); $object = syndicationFeedPeer::retrieveByPK($objectId); syndicationFeedPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::CONVERSION_PROFILE: conversionProfile2Peer::setUseCriteriaFilter(false); $object = conversionProfile2Peer::retrieveByPK($objectId); conversionProfile2Peer::setUseCriteriaFilter(true); break; case FileSyncObjectType::FILE_ASSET: conversionProfile2Peer::setUseCriteriaFilter(false); $object = FileAssetPeer::retrieveByPK($objectId); conversionProfile2Peer::setUseCriteriaFilter(true); break; } if ($object == null) { $object = KalturaPluginManager::loadObject('ISyncableFile', $objectType, array('objectId' => $objectId)); } if ($object == null) { $error = __METHOD__ . " Cannot find object type [" . $objectType . "] with object_id [" . $objectId . "]"; KalturaLog::err($error); throw new kFileSyncException($error); } return $object; }
/** * Update asset parmas of conversion profile by ID * * @action update * @param int $conversionProfileId * @param int $assetParamsId * @param KalturaConversionProfileAssetParams $conversionProfileAssetParams * @return KalturaConversionProfileAssetParams */ public function updateAction($conversionProfileId, $assetParamsId, KalturaConversionProfileAssetParams $conversionProfileAssetParams) { $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId); if (!$conversionProfile) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($assetParamsId, $conversionProfileId); if (!$flavorParamsConversionProfile) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ASSET_PARAMS_NOT_FOUND, $conversionProfileId, $assetParamsId); } $conversionProfileAssetParams->toUpdatableObject($flavorParamsConversionProfile); $flavorParamsConversionProfile->save(); $conversionProfileAssetParams->fromObject($flavorParamsConversionProfile, $this->getResponseProfile()); return $conversionProfileAssetParams; }
/** * Add new bulk upload batch job * Conversion profile id can be specified in the API or in the CSV file, the one in the CSV file will be stronger. * If no conversion profile was specified, partner's default will be used * * @action add * @param int $conversionProfileId Convertion profile id to use for converting the current bulk (-1 to use partner's default) * @param file $csvFileData CSV File * @return KalturaBulkUpload */ function addAction($conversionProfileId, $csvFileData) { // first we copy the file to "content/batchfiles/[partner_id]/" $origFilename = $csvFileData["name"]; $fileInfo = pathinfo($origFilename); $extension = strtolower($fileInfo["extension"]); if ($extension != "csv") { throw new KalturaAPIException(KalturaErrors::INVALID_FILE_EXTENSION); } $job = new BatchJob(); $job->setPartnerId($this->getPartnerId()); $job->save(); $syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV); // kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"])); try { kFileSyncUtils::moveFromFile($csvFileData["tmp_name"], $syncKey, true); } catch (Exception $e) { throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR); } $csvPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $data = new KalturaBulkUploadJobData(); $data->csvFilePath = $csvPath; $data->userId = $this->getKuser()->getPuserId(); $data->uploadedBy = $this->getKuser()->getScreenName(); if ($conversionProfileId === -1) { $conversionProfileId = $this->getPartner()->getDefaultConversionProfileId(); } $kmcVersion = $this->getPartner()->getKmcVersion(); $check = null; if ($kmcVersion < 2) { $check = ConversionProfilePeer::retrieveByPK($conversionProfileId); } else { $check = conversionProfile2Peer::retrieveByPK($conversionProfileId); } if (!$check) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $data->conversionProfileId = $conversionProfileId; $dbJob = kJobsManager::addJob($job, $data->toObject(), KalturaBatchJobType::BULKUPLOAD); $bulkUpload = new KalturaBulkUpload(); $bulkUpload->fromObject($dbJob); return $bulkUpload; }
/** * Get Thumb Params by Conversion Profile ID * * @action getByConversionProfileId * @param int $conversionProfileId * @return KalturaThumbParamsArray */ public function getByConversionProfileIdAction($conversionProfileId) { $conversionProfileDb = conversionProfile2Peer::retrieveByPK($conversionProfileId); if (!$conversionProfileDb) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $thumbParamsConversionProfilesDb = $conversionProfileDb->getthumbParamsConversionProfilesJointhumbParams(); $thumbParamsDb = array(); foreach ($thumbParamsConversionProfilesDb as $item) { $thumbParamsDb[] = $item->getThumbParams(); } $thumbParams = KalturaThumbParamsArray::fromDbArray($thumbParamsDb); return $thumbParams; }
private function getConversionQuality($entry) { $conversionQuality = $entry->conversionQuality; if (parent::getConversionQualityFromRequest()) { $conversionQuality = parent::getConversionQualityFromRequest(); } if (is_null($conversionQuality)) { return null; } $conversionProfile2 = conversionProfile2Peer::retrieveByPK($conversionQuality); if (!$conversionProfile2) { KalturaLog::debug("Maybe old conversion profile"); $conversionProfile = ConversionProfilePeer::retrieveByPK($conversionQuality); if ($conversionProfile) { $conversionQuality = $conversionProfile->getConversionProfile2Id(); } } return $conversionQuality; }
public function getconversionProfile2(PropelPDO $con = null) { return conversionProfile2Peer::retrieveByPK($this->conversion_profile_id, $con); }
/** * Function adds bulk upload job to the queue * @param Partner $partner * @param kBulkUploadJobData $jobData * @param string $bulkUploadType * @throws APIException * @return BatchJob */ public static function addBulkUploadJob(Partner $partner, kBulkUploadJobData $jobData, $bulkUploadType = null, $objectId = null, $objectType = null) { KalturaLog::debug("adding BulkUpload job"); $job = new BatchJob(); $job->setPartnerId($partner->getId()); $job->setJobType(BatchJobType::BULKUPLOAD); $job->setJobSubType($bulkUploadType); if (!is_null($objectId) && !is_null($objectType)) { $job->setObjectId($objectId); $job->setObjectType($objectType); } if (is_null($jobData)) { throw new APIException(APIErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $bulkUploadType); } $job->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS); $job = kJobsManager::addJob($job, $jobData, BatchJobType::BULKUPLOAD, $bulkUploadType); if (!is_null($jobData->getFilePath())) { $syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD); // kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"])); try { kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true); } catch (Exception $e) { KalturaLog::err($e); throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR); } $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $jobData->setFilePath($filePath); } if (!$jobData->getBulkUploadObjectType()) { $jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY); } if ($jobData->getBulkUploadObjectType() == BulkUploadObjectType::ENTRY && !$jobData->getObjectData()->getConversionProfileId()) { $jobData->setConversionProfileId($partner->getDefaultConversionProfileId()); $kmcVersion = $partner->getKmcVersion(); $check = null; if ($kmcVersion < 2) { $check = ConversionProfilePeer::retrieveByPK($jobData->getConversionProfileId()); } else { $check = conversionProfile2Peer::retrieveByPK($jobData->getConversionProfileId()); } if (!$check) { throw new APIException(APIErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $jobData->getConversionProfileId()); } } $job->setData($jobData); return kJobsManager::updateBatchJob($job, BatchJob::BATCHJOB_STATUS_PENDING); }
/** * Delete Conversion Profile by ID * * @action delete * @param int $id */ public function deleteAction($id) { $conversionProfileDb = conversionProfile2Peer::retrieveByPK($id); if (!$conversionProfileDb) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $id); } if ($conversionProfileDb->getIsDefault() === true) { throw new KalturaAPIException(KalturaErrors::CANNOT_DELETE_DEFAULT_CONVERSION_PROFILE); } $this->deleteFlavorParamsRelation($conversionProfileDb); $conversionProfileDb->setDeletedAt(time()); $conversionProfileDb->save(); }
<?php require_once __DIR__ . '/../bootstrap.php'; if ($argc == 3) { $flavor_param_id = $argv[1]; $conversion_profile_id = $argv[2]; } else { die('usage: php ' . $_SERVER['SCRIPT_NAME'] . " [flavor_param_id] [conversion profile id]" . PHP_EOL); } $conversion_flavor = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor_param_id, $conversion_profile_id); if (!$conversion_flavor) { die('no such flavor param id and conversion profile id.' . PHP_EOL); } $conversion = conversionProfile2Peer::retrieveByPK($conversion_profile_id); $input_tags_maps = $conversion->getInputTagsMap(); if (strpos($input_tags_maps, ",mbr") === false) { $input_tags_maps .= ",mbr"; $conversion->setInputTagsMap($input_tags_maps); $conversion->save(); } $conversion_flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL); $conversion_flavor->save(); echo "Done.";
/** * Will return for each OLD ConversionProfile a new one, IF NEEDED. * The old conversionProfile will hold a reference to the new one, so if already created a new one, it will be re-used. * All the necessary flavorParams will be added too to fit the old conversion params. * * @param ConversionProfile $conversion_profile * @return conversionProfile2 */ public static function createConversionProfile2FromConversionProfile(ConversionProfile $old_conversion_profile) { if (!$old_conversion_profile) { throw new Exception("Cannot create new conversionProfile2 for null"); } if ($old_conversion_profile->getConversionProfile2Id()) { $new_profile = conversionProfile2Peer::retrieveByPK($old_conversion_profile->getConversionProfile2Id()); if ($new_profile) { // found a valid new profile - return it return $new_profile; } } // whether there was no id or no profile - create on now and set it to be the conversionProfile2Id $new_profile = new conversionProfile2(); $new_profile->setPartnerId($old_conversion_profile->getPartnerId()); $new_name = $old_conversion_profile->getName(); $new_name = $new_name ? $new_name : "From [{$old_conversion_profile->getId()}]"; $new_profile->setName($new_name . " " . $old_conversion_profile->getProfileType()); if ($old_conversion_profile->getBypassFlv()) { $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV); $map = flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR; } else { $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC); $map = flavorParams::TAG_WEB; } $new_profile->setInputTagsMap($map); // use the OLD code to simulate what was performed on the old_conversion_profile to retrieve the old_conversion_params list $conv_client = new kConversionClientBase("", "", "", ""); $old_conversion_command = $conv_client->createConversionCommandFromConverionProfile("src", "target", $old_conversion_profile); $description = ''; foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) { // use the helper utility to fill the gaps $desc = ''; self::fixDimensionsByAspectRatio($old_conversion_params, $desc); $description .= $desc; } $new_profile->setDescription($description); $new_profile->save(); // at this point - the all $old_conversion_params are filled with the values used by the old conversion servers // transform from old to new ... // create the flavorParams and the flavorParamsConversionParams table foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) { $new_flavor_params = new flavorParams(); // set all the properties for the new flavor_params $new_flavor_params->setPartnerId($old_conversion_profile->getPartnerId()); $new_flavor_params->setCreationMode(flavorParams::FLAVOR_PARAMS_CREATION_MODE_AUTOMATIC); $audio_bitrate = $old_conversion_params->audio_bitrate; if (!$audio_bitrate) { $audio_bitrate = 96; } // if empty - hard-code 96 $new_flavor_params->setAudioBitrate($audio_bitrate); // default $new_flavor_params->setAudioChannels(0); // default $new_flavor_params->setAudioResolution(0); $new_flavor_params->setAudioSampleRate(0); if ($old_conversion_profile->getCommercialTranscoder()) { // first comes ON2... $new_flavor_params->setConversionEngines(conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM . "," . conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER); // $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params); } else { // first comes ffmpeg ... $new_flavor_params->setConversionEngines(conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER . "," . conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM, ","); // $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params); } $target_format = "flv"; // this code will always be called for flv files // the format can be flv | mp4 | mov | avi | mp3 // IMPORTANT: // except for the FLV videos, none of the formats should be assumed WEB - they are not supposed to be played using our player at first stage. switch ($target_format) { case "mp3": $new_flavor_params->setFormat("flv"); $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3); // set default mp3 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6); /* $new_flavor_params->setTags ( flavorParams::TAG_WEB ); */ break; case "mp4": $new_flavor_params->setFormat($target_format); $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC); $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264); $new_flavor_params->setTags(',mp4_export'); break; case "mov": $new_flavor_params->setFormat($target_format); $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC); $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264); $new_flavor_params->setTags('mov_export'); break; case "avi": $new_flavor_params->setFormat($target_format); $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3); $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264); $new_flavor_params->setTags('avi_export'); break; case "flv": $new_flavor_params->setFormat($target_format); $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3); $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6); $new_flavor_params->setTags(flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR); break; } $new_flavor_params->setName($new_name); $new_flavor_params->setFrameRate(0); // DONT set the framerate $old_conversion_params->framerate ); if ($old_conversion_params->gop_size == 5) { $new_flavor_params->setGopSize(5); $new_flavor_params->removeTag(flavorParams::TAG_MBR); $new_flavor_params->addTag(flavorParams::TAG_EDIT); } else { $new_flavor_params->setGopSize(0); // 0 will automatically allow default gopsize } $new_flavor_params->setWidth($old_conversion_params->width); $new_flavor_params->setHeight($old_conversion_params->height); $new_flavor_params->setVersion(1); $new_flavor_params->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL); $new_flavor_params->setVideoBitrate($old_conversion_params->bitrate ? $old_conversion_params->bitrate : ""); // TODO - fill the rest ... $new_flavor_params->save(); // add to the 1-to-many table $flavor_params_conversion_profile = new flavorParamsConversionProfile(); $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId()); $flavor_params_conversion_profile->setFlavorParamsId($new_flavor_params->getId()); $flavor_params_conversion_profile->setReadyBehavior($new_flavor_params->getReadyBehavior()); $flavor_params_conversion_profile->save(); } // always add to the *source* flavotParams to the 1-to-many table $flavor_params_conversion_profile = new flavorParamsConversionProfile(); $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId()); $flavor_params_conversion_profile->setFlavorParamsId(flavorParams::SOURCE_FLAVOR_ID); $flavor_params_conversion_profile->save(); // point to the new profile and save the old one $old_conversion_profile->setConversionProfile2Id($new_profile->getId()); $old_conversion_profile->save(); return $new_profile; }
protected function getOriginalOrTransformIfNeeded(DropFolder $folder, $xmlPath) { if (!file_exists($xmlPath) || !filesize($xmlPath)) { throw new Exception('Empty file supplied as input'); } if (!$folder->getConversionProfileId()) { KalturaLog::debug('No conversion profile found on drop folder [' . $folder->getId() . '] assuming no xsl transformation is needed'); return file_get_contents($xmlPath); } $conversionProfile = conversionProfile2Peer::retrieveByPK($folder->getConversionProfileId()); if (!$conversionProfile || strlen($conversionProfile->getXsl()) == 0) { KalturaLog::debug('No conversion profile found Or no xsl transform found'); return file_get_contents($xmlPath); } $originalXmlDoc = file_get_contents($xmlPath); $origianlXml = new KDOMDocument(); if (!$origianlXml->loadXML($originalXmlDoc)) { KalturaLog::debug('Could not load original xml'); $errorMessage = kXml::getLibXmlErrorDescription($originalXmlDoc); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } libxml_clear_errors(); $proc = new XSLTProcessor(); $xsl = new KDOMDocument(); if (!$xsl->loadXML($conversionProfile->getXsl())) { KalturaLog::debug('Could not load xsl ' . $conversionProfile->getXsl()); $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl()); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } $proc->importStyleSheet($xsl); libxml_clear_errors(); $transformedXml = $proc->transformToXML($origianlXml); if (!$transformedXml) { KalturaLog::debug('Could not transform xml ' . $conversionProfile->getXsl()); $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl()); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } $xmlDoc = new KDOMDocument(); $res = $xmlDoc->loadXML($transformedXml); if (!$res) { throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } return $transformedXml; }
public function validateConversionProfile(entry $sourceObject = null) { if (!is_null($this->conversionProfileId) && $this->conversionProfileId != conversionProfile2::CONVERSION_PROFILE_NONE) { $conversionProfile = conversionProfile2Peer::retrieveByPK($this->conversionProfileId); if (!$conversionProfile || $conversionProfile->getType() != ConversionProfileType::LIVE_STREAM) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $this->conversionProfileId); } } }
<?php if ($argc < 3) { echo "Required parameter [conversionProfileId] missing. Required form php addRequiredCopyPermissionConversionProfile.php <conversionProfileId> <comma-separated permissions>"; die; } require_once __DIR__ . '/../bootstrap.php'; $conversionProfileId = $argv[1]; $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId); $partner = PartnerPeer::retrieveByPK($conversionProfile->getPartnerId()); if ($partner->getPartnerGroupType() != PartnerGroupType::TEMPLATE) { die("Conversion profile with id [{$conversionProfileId}] does not belong to a template partner. Aborting."); } $conversionProfile->setRequiredCopyTemplatePermissions(explode(',', $argv[2])); $conversionProfile->save();
/** * Get Flavor Params by Conversion Profile ID * * @action getByConversionProfileId * @param int $conversionProfileId * @return KalturaFlavorParamsArray */ public function getByConversionProfileIdAction($conversionProfileId) { $conversionProfileDb = conversionProfile2Peer::retrieveByPK($conversionProfileId); if (!$conversionProfileDb) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $flavorParamsConversionProfilesDb = $conversionProfileDb->getflavorParamsConversionProfilesJoinflavorParams(); $flavorParamsDb = array(); foreach ($flavorParamsConversionProfilesDb as $item) { /* @var $item flavorParamsConversionProfile */ $flavorParamsDb[] = $item->getassetParams(); } $flavorParams = KalturaFlavorParamsArray::fromDbArray($flavorParamsDb); return $flavorParams; }
/** * Convert entry * * @param string $entryId Media entry id * @param int $conversionProfileId * @param KalturaConversionAttributeArray $dynamicConversionAttributes * @return bigint job id * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND * @throws KalturaErrors::FLAVOR_PARAMS_NOT_FOUND */ protected function convert($entryId, $conversionProfileId = null, KalturaConversionAttributeArray $dynamicConversionAttributes = null) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (!$srcFlavorAsset) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } if (is_null($conversionProfileId) || $conversionProfileId <= 0) { $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId); if (!$conversionProfile) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } $conversionProfileId = $conversionProfile->getId(); } else { //The search is with the entry's partnerId. so if conversion profile wasn't found it means that the //conversionId is not exist or the conversion profileId does'nt belong to this partner. $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId); if (is_null($conversionProfile)) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId); } } $srcSyncKey = $srcFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); if (!$fileSync) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } else { if (!$local) { kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync)); } } // even if it null $entry->setConversionQuality($conversionProfileId); $entry->save(); if ($dynamicConversionAttributes) { $flavors = assetParamsPeer::retrieveByProfile($conversionProfileId); if (!count($flavors)) { throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_NOT_FOUND); } $srcFlavorParamsId = null; $flavorParams = $entry->getDynamicFlavorAttributes(); foreach ($flavors as $flavor) { if ($flavor->hasTag(flavorParams::TAG_SOURCE)) { $srcFlavorParamsId = $flavor->getId(); } $flavorParams[$flavor->getId()] = $flavor; } $dynamicAttributes = array(); foreach ($dynamicConversionAttributes as $dynamicConversionAttribute) { if (is_null($dynamicConversionAttribute->flavorParamsId)) { $dynamicConversionAttribute->flavorParamsId = $srcFlavorParamsId; } if (is_null($dynamicConversionAttribute->flavorParamsId)) { continue; } $dynamicAttributes[$dynamicConversionAttribute->flavorParamsId][trim($dynamicConversionAttribute->name)] = trim($dynamicConversionAttribute->value); } if (count($dynamicAttributes)) { $entry->setDynamicFlavorAttributes($dynamicAttributes); $entry->save(); } } $srcFilePath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey); $job = kJobsManager::addConvertProfileJob(null, $entry, $srcFlavorAsset->getId(), $srcFilePath); if (!$job) { return null; } return $job->getId(); }
public function validateConversionProfile(entry $sourceObject = null) { if (is_null($this->conversionProfileId)) { return; } if ($sourceObject && $sourceObject->getStatus() != entryStatus::NO_CONTENT) { throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_ENTRY_STATUS, $this->getFormattedPropertyNameWithClassName('conversionProfileId'), $sourceObject->getStatus()); } if ($this->conversionProfileId != conversionProfile2::CONVERSION_PROFILE_NONE) { $conversionProfile = conversionProfile2Peer::retrieveByPK($this->conversionProfileId); if (!$conversionProfile || $conversionProfile->getType() != ConversionProfileType::MEDIA) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $this->conversionProfileId); } } }
/** * Update an existing KalturaDropFolder object * * @action update * @param int $dropFolderId * @param KalturaDropFolder $dropFolder * @return KalturaDropFolder * * @throws KalturaErrors::INVALID_OBJECT_ID * @throws KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND * @throws KalturaErrors::DATA_CENTER_ID_NOT_FOUND */ public function updateAction($dropFolderId, KalturaDropFolder $dropFolder) { $dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId); if (!$dbDropFolder) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId); } $dropFolder->validatePropertyMinValue('fileSizeCheckInterval', 0, true); $dropFolder->validatePropertyMinValue('autoFileDeleteDays', 0, true); if (!is_null($dropFolder->path) && $dropFolder->path != $dbDropFolder->getPath() && $dropFolder->type == KalturaDropFolderType::LOCAL) { $existingDropFolder = DropFolderPeer::retrieveByPathDefaultFilter($dropFolder->path); if ($existingDropFolder) { throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_ALREADY_EXISTS, $dropFolder->path); } } if (!is_null($dropFolder->dc)) { if (!kDataCenterMgr::dcExists($dropFolder->dc)) { throw new KalturaAPIException(KalturaErrors::DATA_CENTER_ID_NOT_FOUND, $dropFolder->dc); } } if (!is_null($dropFolder->conversionProfileId)) { $conversionProfileDb = conversionProfile2Peer::retrieveByPK($dropFolder->conversionProfileId); if (!$conversionProfileDb) { throw new KalturaAPIException(KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND, $dropFolder->conversionProfileId); } } $dbDropFolder = $dropFolder->toUpdatableObject($dbDropFolder); $dbDropFolder->save(); $dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType()); $dropFolder->fromObject($dbDropFolder, $this->getResponseProfile()); return $dropFolder; }