/** * * @param $version * @param $format * @return FileSync */ public function getDownloadFileSyncAndLocal($version = NULL, $format = null, $sub_type = null) { $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($this->getPartnerId(), $format); if (!$flavorParams) { return null; } $flavorAssets = assetPeer::retrieveByEntryIdAndParams($this->getId(), $flavorParams->getId()); if (!$flavorAssets) { return null; } $syncKey = $flavorAssets->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!$syncKey) { return null; } return kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { KalturaLog::log("adddownloadAction: executeImpl ( {$partner_id} , {$subp_id} , {$puser_id} , {$partner_prefix} , {$puser_kuser})"); $entry_id = $this->getPM("entry_id"); $version = $this->getP("version"); $file_format = strtolower($this->getPM("file_format")); $conversion_quality = $this->getP("conversion_quality", null); $force_download = $this->getP("force_download", null); $entry = entryPeer::retrieveByPK($entry_id); if (!$entry) { KalturaLog::log("add download Action entry not found"); $this->addError(APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix(), $entry_id); return; } KalturaLog::log("adddownloadAction: entry found [{$entry_id}]"); /* $content_path = myContentStorage::getFSContentRootPath(); $file_name = $content_path . $entry->getDataPath( $version ); // replaced__getDataPath if (!file_exists($file_name)) */ $sync_key = null; $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId()); if ($originalFlavorAsset) { $sync_key = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); } if (!$sync_key) { $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); } if (!kFileSyncUtils::file_exists($sync_key)) { // if not found local file - perhaps wasn't created here and wasn't synced yet // try to see if remote exists - and proxy the request if it is. list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true); if (!$local) { // take input params and add to URL $queryArr = array('entry_id' => $entry_id, 'version' => $version, 'file_format' => $file_format, 'conversion_quality' => $conversion_quality, 'force_download' => $force_download, 'ks' => $this->ks->toSecureString(), 'partner_id' => $partner_id, 'subp_id' => $subp_id, 'format' => $this->response_type); $get_query = http_build_query($queryArr, '', '&'); $remote_url = kDataCenterMgr::getRedirectExternalUrl($fileSync, $_SERVER['REQUEST_URI']); $url = strpos($remote_url, '?') === FALSE ? $remote_url . '?' . $get_query : $remote_url . '&' . $get_query; // prxoy request to other DC KalturaLog::log(__METHOD__ . ": redirecting to [{$url}]"); kFileUtils::dumpUrl($url); } KalturaLog::log("add download Action sync key doesn't exists"); $this->addError(APIErrors::INVALID_ENTRY_VERSION, $this->getObjectPrefix(), $entry_id, $version); return; } if ($entry->getType() == entryType::MIX) { KalturaLog::log("The Batch job for flattening a mix is no longer supported"); $this->addError(APIErrors::INVALID_ENTRY_TYPE, $this->getObjectPrefix(), $entry_id, $version); return; } $flavorParamsId = 0; if ($file_format != "original") { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { $file_format = "flv"; } // Backward compatebility if (!$file_format && $entry->getType() == entryType::DOCUMENT) { $file_format = "swf"; } $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($partner_id, $file_format); $flavorParamsId = $flavorParams->getId(); } $jobs = kJobsManager::addBulkDownloadJob($partner_id, $puser_id, $entry->getId(), $flavorParamsId); $job = $jobs[0]; // remove kConvertJobData object from batchJob.data $job->setData(null); $jobWrapperClass = objectWrapperBase::getWrapperClass($job, objectWrapperBase::DETAIL_LEVEL_DETAILED); $this->addMsg("download", $jobWrapperClass); // Backwards compatebilty for document entries if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_DOCUMENT || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_PDF) { $this->addMsg("OOconvert", $jobWrapperClass); $download_path = $entry->getDownloadUrl(); //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3 $download_path .= '/direct_serve/true/type/download/forceproxy/true/format/' . $file_format; $this->addMsg('downloadUrl', $download_path); } }
/** * Request a new conversion job, this can be used to convert the media entry to a different format * * @action requestConversion * @param string $entryId Media entry id * @param string $fileFormat Format to convert * @return int The queued job id * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ public function requestConversionAction($entryId, $fileFormat) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } if ($dbEntry->getMediaType() == KalturaMediaType::AUDIO) { // for audio - force format flv regardless what the user really asked for $fileFormat = "flv"; } // $job = myBatchDownloadVideoServer::addJob($this->getKuser()->getPuserId(), $dbEntry, null, $fileFormat); $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($this->getPartnerId(), $fileFormat); $err = null; $job = kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParams->getId(), $err); if ($job) { return $job->getId(); } else { return null; } }
/** * This will queue a batch job for converting the document file to swf * Returns the URL where the new swf will be available * * @action convertPptToSwf * @param string $entryId * @return string */ function convertPptToSwf($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $sync_key = null; $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($sync_key)) { // if not found local file - perhaps wasn't created here and wasn't synced yet // try to see if remote exists - and proxy the request if it is. list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true); if (!$local) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrl($fileSync); kFileUtils::dumpApiRequest($remoteDCHost); } KalturaLog::log("convertPptToSwf sync key doesn't exists"); return; } $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF); $flavorParamsId = $flavorParams->getId(); $puserId = $this->getKuser()->getPuserId(); $err = ""; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err); $downloadPath = $dbEntry->getDownloadUrl(); //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3 return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf'; }
/** * This will queue a batch job for converting the document file to swf * Returns the URL where the new swf will be available * * @action convertPptToSwf * @param string $entryId * @return string */ function convertPptToSwf($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } assetPeer::resetInstanceCriteriaFilter(); $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $sync_key = null; $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($sync_key)) { // if not found local file - perhaps wasn't created here and wasn't synced yet // try to see if remote exists - and proxy the request if it is. list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true); if (!$local) { // take input params and add to URL $queryArr = array('service' => 'document', 'action' => 'convertPptToSwf', 'entryId' => $entryId, 'format' => $this->params["format"], 'ks' => $this->getKs()->toSecureString()); $get_query = http_build_query($queryArr, '', '&'); $remote_url = kDataCenterMgr::getRedirectExternalUrl($fileSync, $_SERVER['REQUEST_URI']); $url = strpos($remote_url, '?') === FALSE ? $remote_url . '?' . $get_query : $remote_url . '&' . $get_query; // prxoy request to other DC KalturaLog::log(__METHOD__ . ": redirecting to [{$url}]"); kFile::dumpUrl($url); } KalturaLog::log("convertPptToSwf sync key doesn't exists"); return; } $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF); $flavorParamsId = $flavorParams->getId(); $puserId = $this->getKuser()->getPuserId(); $err = ""; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err); $downloadPath = $dbEntry->getDownloadUrl(); //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3 return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf'; }