/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $entryId = $this->getRequestParameter("entry_id"); $flavorId = $this->getRequestParameter("flavor"); $fileName = $this->getRequestParameter("file_name"); $ksStr = $this->getRequestParameter("ks"); $referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } // get entry $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($entry->getPartnerId()); $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer); $securyEntryHelper->validateForDownload($entry, $ksStr); $flavorAsset = null; if ($flavorId) { // get flavor asset $flavorAsset = flavorAssetPeer::retrieveById($flavorId); if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } // the request flavor should belong to the requested entry if ($flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } } else { $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId()); } // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) { $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); } if ($flavorAsset) { $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset); } else { $syncKey = $this->getBestSyncKeyForEntry($entry); } list($fileBaseName, $fileExt) = $this->getFileName($entry, $flavorAsset); if (!$fileName) { $fileName = $fileBaseName; } if ($fileExt) { $fileName = $fileName . '.' . $fileExt; } if (is_null($syncKey)) { KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $this->handleFileSyncRedirection($syncKey); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $this->dumpFile($filePath, $fileName); die; // no view }
public static function fromThumbAsset($thumbAsset) { $fileSyncKey = $thumbAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $thumbPath = kFileSyncUtils::getReadyLocalFilePathForKey($fileSyncKey); $thumbWidth = $thumbAsset->getWidth(); $thumbHeight = $thumbAsset->getHeight(); return self::fromParams($thumbWidth, $thumbHeight, $thumbPath, false); }
private function reconvertEntry($entry_id, $conversion_profile_id, $job_priority) { $entry = entryPeer::retrieveByPK($entry_id); $this->error = ""; if (!$entry) { $error = "Cannot reconvert entry [{$entry_id}]. Might be a deleted entry"; return array($entry_id, null, null, $error); } $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id); if (!$flavorAsset) { $flavorAsset = assetPeer::retrieveReadyWebByEntryId($entry_id); if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entry_id); if (!$flavorAssets) { $error = "Cannot find good enough flavor asset to re-convert from"; return array($entry_id, $entry, null, $error); } $flavorAsset = $flavorAssets[0]; // choose the first one } } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if (!$filePath) { $error = "Cannot find a fileSync for the flavorAsset [" . $flavorAsset->getId() . "]"; return array($entry_id, $entry, null, $error); } $dbBatchJob = new BatchJob(); $dbBatchJob->setEntryId($entry_id); $dbBatchJob->setPartnerId($entry->getPartnerId()); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING); $dbBatchJob->setDc(kDataCenterMgr::getCurrentDcId()); //$dbBatchJob->setPriority ( $job_priority ); Not supported anymore $dbBatchJob->setObjectId($entry_id); $dbBatchJob->setObjectType(BatchJobObjectType::ENTRY); $dbBatchJob->setJobType(BatchJobType::CONVERT_PROFILE); $dbBatchJob->save(); // creates a convert profile job $convertProfileData = new kConvertProfileJobData(); $convertProfileData->setFlavorAssetId($flavorAsset->getId()); $convertProfileData->setInputFileSyncLocalPath($filePath); kJobsManager::addJob($dbBatchJob, $convertProfileData, BatchJobType::CONVERT_PROFILE); // save again afget the addJob $dbBatchJob->save(); return array($entry_id, $entry, $dbBatchJob, $error); }
public function getLocalThumbFilePath($version, $width, $height, $type, $bgcolor = "ffffff", $crop_provider = null, $quality = 0, $src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $density = 0, $stripProfiles = false, $flavorId = null, $fileName = null) { KalturaLog::log("flavor_id [{$flavorId}] file_name [{$fileName}]"); if (is_null($flavorId)) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'flavor_id'); } $flavor = assetPeer::retrieveById($flavorId); if (is_null($flavor)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND, $flavorId); } $flavorSyncKey = $flavor->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $file_path = kFileSyncUtils::getReadyLocalFilePathForKey($flavorSyncKey); $orig_image_path = null; if (is_dir($file_path)) { if (is_null($fileName)) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'file name'); } $orig_image_path = $file_path . DIRECTORY_SEPARATOR . $fileName; } try { return myEntryUtils::resizeEntryImage($this, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $orig_image_path, $density); } catch (Exception $ex) { if ($ex->getCode() == kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) { $remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($flavorSyncKey, false); if (!$remoteFileSync) { // file does not exist on any DC - die KalturaLog::err("No FileSync for flavor [{$flavorId}]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) { KalturaLog::err("Trying to redirect to myself - stop here."); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } if (!in_array($remoteFileSync->getDc(), kDataCenterMgr::getDcIds())) { KalturaLog::err("Origin file sync is on remote storage."); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync); kFileUtils::dumpUrl($remoteUrl); } } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $entry_id = $this->getP("entry_id"); $kshow_id = $this->getP("kshow_id"); // Make sure the request is for a ready roughcut $c = entryPeer::getCriteriaFilter()->getFilter(); $c->addAnd(entryPeer::STATUS, entryStatus::READY, Criteria::EQUAL); list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id); if ($error_obj) { $this->addError($error_obj); return; } $version = $this->getP("version"); // it's a path on the disk if (kString::beginsWith($version, ".")) { // someone is trying to hack in the system return sfView::ERROR; } elseif ($version == "-1") { $version = null; } // in case we're making a roughcut out of a regular invite, we start from scratch $entry_data_path = kFileSyncUtils::getLocalFilePathForKey($entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version)); //replaced__getDataPath if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW || $entry_data_path === null) { $this->xml_content = "<xml></xml>"; return; } $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); $file_name = kFileSyncUtils::getReadyLocalFilePathForKey($sync_key, false); // fetch content of file from disk - it should hold the XML if (kString::endsWith($file_name, "xml")) { $xml_content = kFileSyncUtils::file_get_contents($sync_key, false, false); if (!$xml_content) { $xml_content = "<xml></xml>"; } myMetadataUtils::updateEntryForPending($entry, $version, $xml_content); $this->addMsg("metadata", $xml_content); } else { $this->addError(APIErrors::INVALID_FILE_NAME, $file_name); } }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { // where file is {entryId/flavorId}.{ism,ismc,ismv} $objectId = $type = null; $objectIdStr = $this->getRequestParameter("objectId"); if ($objectIdStr) { list($objectId, $type) = @explode(".", $objectIdStr); } if (!$type || !$objectId) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER); } $ks = $this->getRequestParameter("ks"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $syncKey = $this->getFileSyncKey($objectId, $type); KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveIsm', $this->entry->getPartnerId()); myPartnerUtils::enforceDelivery($this->entry, $this->flavorAsset); if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for type [{$type}] objectId [{$objectId}]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFileUtils::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if ($type == 'ism') { $fileData = $this->fixIsmManifestForReplacedEntry($path); $renderer = new kRendererString($fileData, 'image/ism'); $renderer->output(); KExternalErrors::dieGracefully(); } else { kFileUtils::dumpFile($path); } }
/** * here we'll manipulate the video asset and set the from_byte & to_byte from the milliseconds * */ private static function fixMetadataImpl(&$xml_doc, &$total_duration, $timeline) { self::log(__METHOD__); /* $xml_doc = new DOMDocument(); $xml_doc->loadXML( $content ); */ // $meatadata_elem_list = $xml_doc->getElementsByTagName( "MetaData" ); // if ( $meatadata_elem_list != null && $meatadata_elem_list->length > 0 ) $duration_list = $xml_doc->getElementsByTagName("SeqDuration"); if ($duration_list != null && $duration_list->length > 0) { $total_duration = $duration_list->item(0)->nodeValue; } $xpath = new DOMXPath($xml_doc); $assets = $xpath->query($timeline == "video" ? "//VideoAssets/vidAsset" : ($timeline == "audio" ? "//AudioAssets/AudAsset" : "//VoiceAssets/voiAsset")); $lastTimestamp = 0; $real_start_byte = 0; // the start byte of the current clip in the final merged stream $calculated_total_bytes = 0; // use the entryPool and a 2-pass iteration to reduce the hits to the DB $id_list = array(); $entry_pool = new entryPool(); // first pass - populate the entryPool in a single request to the DB self::log(__METHOD__, "Before assets"); foreach ($assets as $asset) { $type = $asset->getAttribute("type"); if ($type != "VIDEO" && $type != "AUDIO") { continue; } // fetch the file name from the DB $asset_id = $asset->getAttribute("k_id"); $id_list[] = $asset_id; } self::log(__METHOD__, "After assets", count($id_list), $id_list); if ($id_list) { $entry_pool->addEntries(entryPeer::retrieveByPKsNoFilter($id_list)); } // second pass - the entryPool is supposed to already be populated $was_modified = false; foreach ($assets as $asset) { // fix only VIDEO assets $type = $asset->getAttribute("type"); if ($type != "VIDEO" && $type != "AUDIO") { continue; } // fetch the file name from the DB $asset_id = $asset->getAttribute("k_id"); self::log(__METHOD__, "in loop", $asset_id); //$entry = entryPeer::retrieveByPKNoFilter( $asset_id ); $entry = $entry_pool->retrieveByPK($asset_id); // is supposed to exist already in the pool if ($entry == NULL) { // set an error on the asset element $asset->setAttribute("fix_status", "error in k_id [{$asset_id}]"); $was_modified = true; continue; } elseif ($entry->getStatus() == entryStatus::DELETED) { // set an error on the asset element $asset->setAttribute("fix_status", "error in k_id [{$asset_id}] - asset was deleted"); $was_modified = true; continue; } $file_name = null; //TODO: need to work on only an FLV asset $flavor_asset_play = assetPeer::retrieveBestPlayByEntryId($entry->getId()); if (!$flavor_asset_play) { KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no play flavor asset for entry ' . $entry->getId()); } else { $file_name = kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_play->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET)); } $use_multi_flavor = false; $flv_file_name_edit = false; $flavor_asset_edit = assetPeer::retrieveBestEditByEntryId($entry->getId()); if (!$flavor_asset_edit) { KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no edit flavor asset for entry ' . $entry->getId()); } else { $flv_file_name_edit = kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_edit->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET)); $use_multi_flavor = $flv_file_name_edit && file_exists($flv_file_name_edit) && $timeline == "video"; } if (!$flv_file_name_edit && !$file_name) { KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no edit & play flavor assets for entry ' . $entry->getId()); continue; } $flv_file_name = kFile::fixPath($file_name); $stream_info_list = $asset->getElementsByTagName("StreamInfo"); foreach ($stream_info_list as $stream_info) { $file_name = "?"; try { $stream_info->setAttribute("file_name", kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_play->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET))); // replaced__getDataPath $start_byte = $stream_info->getAttribute("start_byte"); $end_byte = $stream_info->getAttribute("end_byte"); $total_bytes = $stream_info->getAttribute("total_bytes"); if ($start_byte == NULL) { $start_byte = self::MISSING_VALUE; } if ($end_byte == NULL) { $end_byte = self::MISSING_VALUE; } if ($total_bytes == NULL) { $total_bytes = self::MISSING_VALUE; } $len_time = floor(1000 * $stream_info->getAttribute("len_time")); if (1 || $start_byte == self::MISSING_VALUE || $end_byte == self::MISSING_VALUE || $total_bytes == self::MISSING_VALUE) { // set the values from start_time & len_time - the original numbers are in seconds (with a decimal point) $start_time = floor(1000 * $stream_info->getAttribute("start_time")); $end_time = $start_time + $len_time; $real_start_byte += $calculated_total_bytes; $calculated_start_byte = 0; $calculated_end_byte = 0; $calculated_total_bytes = 0; $calculated_real_seek_time = 0; $calculated_start_byte_play = 0; $calculated_end_byte_play = 0; $calculated_total_bytes_play = 0; /* $file_name = $stream_info->getAttribute ( "file_name" ); $flv_file_name = kFile::fixPath( myContentStorage::getFSContentRootPath() . $file_name ); $ext = pathinfo ($flv_file_name, PATHINFO_EXTENSION); if ( $ext == NULL ) $flv_file_name .= ".flv"; */ try { self::log(__METHOD__, "before findBytesFromTimestamps", $flv_file_name); //$use_multi_flavor = myFlvStaticHandler::isMultiFlavor ( $flv_file_name ) && $timeline == "video"; $calculated_real_seek_time = $lastTimestamp; $start_time_play = null; if ($use_multi_flavor) { $start_time_play = $start_time; // play // $start_time_play - will be modified according to the first keyframe's time stamp AFTER (not before) the requested timestamp $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name, $start_time_play, $end_time, $calculated_start_byte_play, $calculated_end_byte_play, $calculated_total_bytes_play, $lastTimestamp, $timeline != "video", 1); KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " play {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})"); if ($result) { if ($start_time_play != $start_time) { // we need to fill the gap between the user requested keyframe and the one actually found in the play (low res) flavor // edit - more keyfrmaes ! $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name_edit, $start_time, $start_time_play, $calculated_start_byte, $calculated_end_byte, $calculated_total_bytes, $lastTimestamp, $timeline != "video", 2); KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " edit {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})"); } } } else { // no reason to have multi-flavor files // either because NOT video or because the edit flavor does not exist $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name, $start_time, $end_time, $calculated_start_byte, $calculated_end_byte, $calculated_total_bytes, $lastTimestamp, $timeline != "video", 0); KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " only play {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})"); } self::log(__METHOD__, "after findBytesFromTimestamps", $flv_file_name); } catch (Exception $ex1) { debugUtils::log("Error while converting time2bytes in file [{$file_name}]\n{$ex1}"); echo "Error while converting time2bytes in file [{$file_name}]\n{$ex1}"; } $calculated_total_bytes += $calculated_total_bytes_play; if ($result) { if (1 || $start_byte == self::MISSING_VALUE) { $stream_info->setAttribute("start_byte", $calculated_start_byte); $stream_info->setAttribute("start_byte_play", $calculated_start_byte_play); } if (1 || $end_byte == self::MISSING_VALUE) { $stream_info->setAttribute("end_byte", $calculated_end_byte); $stream_info->setAttribute("end_byte_play", $calculated_end_byte_play); } if (1 || $calculated_total_bytes == self::MISSING_VALUE) { $stream_info->setAttribute("total_bytes", $calculated_total_bytes); $stream_info->setAttribute("real_start_byte", $real_start_byte); $stream_info->setAttribute("real_end_byte", $real_start_byte + $calculated_total_bytes); } if (1 || $calculated_real_seek_time == self::MISSING_VALUE) { // retrun the calculated_real_seek_time in seconds with 2 decimal points $stream_info->setAttribute("real_seek_time", number_format($calculated_real_seek_time / 1000, 3, '.', '')); } if ($asset->hasAttribute("fix_status")) { $asset->removeAttribute("fix_status"); } } elseif (!$result) { // set an error on the asset element $asset->setAttribute("fix_status", "Missing file or invalid FLV structure"); } $was_modified = true; } } catch (Exception $ex2) { echo "Error parsing file [{$file_name}]\n{$ex2}"; } } } return $xml_doc; /* if ( $was_modified ) { return $xml_doc->saveXML(); } else { // nothing was modified - use the original string return $content; } */ }
private static function getUrlAndName($entry) { $data = kFileSyncUtils::getReadyLocalFilePathForKey($entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA)); // replaced__getDataPath $entry_type = self::getEntryType($entry); if ($entry_type->type == self::TYPE_RTMP) { // the url should be where the RTMP service is $url = self::getRTMPPath(); // the name should start with the content directory // and should not include the file extension ! $name = pathinfo($data, PATHINFO_DIRNAME) . "/" . kFile::getFileNameNoExtension($data); } else { $url = requestUtils::getHost() . $data; $name = pathinfo($data, PATHINFO_BASENAME); } $url_name = new urlName(); $url_name->url = $url; $url_name->name = $name; return $url_name; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $entryId = $this->getRequestParameter("entry_id"); $flavorId = $this->getRequestParameter("flavor"); $fileName = $this->getRequestParameter("file_name"); $fileName = basename($fileName); $ksStr = $this->getRequestParameter("ks"); $referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $entry = null; if ($ksStr) { try { kCurrentContext::initKsPartnerUser($ksStr); } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS); } } else { $entry = kCurrentContext::initPartnerByEntryId($entryId); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } kEntitlementUtils::initEntitlementEnforcement(); if (!$entry) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } else { if (!kEntitlementUtils::isEntryEntitled($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } myPartnerUtils::blockInactivePartner($entry->getPartnerId()); $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, accessControlContextType::DOWNLOAD); $securyEntryHelper->validateForDownload($entry, $ksStr); $flavorAsset = null; if ($flavorId) { // get flavor asset $flavorAsset = assetPeer::retrieveById($flavorId); if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } // the request flavor should belong to the requested entry if ($flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } } else { $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId()); } // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); } if ($flavorAsset) { $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset); } else { $syncKey = $this->getBestSyncKeyForEntry($entry); } if (is_null($syncKey)) { KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $this->handleFileSyncRedirection($syncKey); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $wamsAssetId = kFileSyncUtils::getWamsAssetIdForKey($syncKey); $wamsURL = kFileSyncUtils::getWamsURLForKey($syncKey); list($fileBaseName, $fileExt) = $this->getFileName($entry, $flavorAsset); if (!$fileName) { $fileName = $fileBaseName; } if ($fileExt && !is_dir($filePath)) { $fileName = $fileName . '.' . $fileExt; } //enable downloading file_name which inside the flavor asset directory if (is_dir($filePath)) { $filePath = $filePath . DIRECTORY_SEPARATOR . $fileName; } $this->dumpFile($filePath, $fileName, $wamsAssetId, $wamsURL); die; // no view }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { // where file is {entryId/flavorId}.{ism,ismc,ismv} $objectId = $type = null; $objectIdStr = $this->getRequestParameter("objectId"); list($objectId, $type) = @explode(".", $objectIdStr); if (!$type || !$objectId) { die; } $ks = $this->getRequestParameter("ks"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } if ($type == "ism" || $type == "ismc") { // backward compatiblity - to be removed once ismc is created with pure objectId.ext instead of entryId_flavorId_version.ext if (strlen($objectId) != 10) { $version = substr($objectId, 13); $objectId = substr($objectId, 0, 10); } else { $version = null; } $entry = entryPeer::retrieveByPK($objectId); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } $syncKey = $entry->getSyncKey($type == "ism" ? entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM : entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC, $version); } else { if ($type == "ismv") { // backward compatiblity - to be removed once ismc is created with pure objectId.ext instead of entryId_flavorId_version.ext if (strlen($objectId) != 10) { $version = substr($objectId, 22); $objectId = substr($objectId, 11, 10); } else { $version = null; } $flavorAsset = flavorAssetPeer::retrieveById($objectId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId()); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version); } else { die; } } if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for type [{$type}] objectId [{$objectId}]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFile::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); kFile::dumpFile($path); }
public static function resizeEntryImage(entry $entry, $version, $width, $height, $type, $bgcolor = "ffffff", $crop_provider = null, $quality = 0, $src_x = 0, $src_y = 0, $src_w = 0, $src_h = 0, $vid_sec = -1, $vid_slice = 0, $vid_slices = -1, $orig_image_path = null) { $contentPath = myContentStorage::getFSContentRootPath(); $entry_status = $entry->getStatus(); $tempThumbName = $entry->getId() . "_{$width}_{$height}_{$type}_{$crop_provider}_{$bgcolor}_{$quality}_{$src_x}_{$src_y}_{$src_w}_{$src_h}_{$vid_sec}_{$vid_slice}_{$vid_slices}_{$entry_status}"; $entryThumbFilename = $entry->getThumbnail() ? $entry->getThumbnail() : "0.jpg"; if ($entry->getStatus() != entryStatus::READY || @$entryThumbFilename[0] == '&') { $tempThumbName .= "_NOCACHE_"; } // we remove the & from the template thumb otherwise getGeneralEntityPath will drop $tempThumbName from the final path $entryThumbFilename = str_replace("&", "", $entryThumbFilename); $basePath = myContentStorage::getGeneralEntityPath("entry/tempthumb", $entry->getIntId(), $tempThumbName, $entryThumbFilename, $version); $tempThumbPath = $contentPath . $basePath; $cachedTempThumbPath = myContentStorage::getFSCacheRootPath() . $basePath; if (file_exists($cachedTempThumbPath)) { header("X-Kaltura:cached-local-thumb-exists," . md5($cachedTempThumbPath)); return $cachedTempThumbPath; } if (file_exists($tempThumbPath)) { header("X-Kaltura:cached-thumb-exists," . md5($tempThumbPath)); return $tempThumbPath; } if ($orig_image_path === null || !file_exists($orig_image_path)) { $sub_type = $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE ? entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA : entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB; $orig_image_key = $entry->getSyncKey($sub_type, $version); $orig_image_path = kFileSyncUtils::getReadyLocalFilePathForKey($orig_image_key); } // remark added so ffmpeg will try to load the thumbnail from the original source //if (!file_exists($orig_image_path)) // KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); // check a request for animated thumbs without a concrete vid_slice // in which case we'll create all the frames as one wide image $multi = $vid_slice == -1 && $vid_slices != -1; $count = $multi ? $vid_slices : 1; $im = null; if ($multi) { $vid_slice = 0; } while ($count--) { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO && ($vid_sec != -1 || $vid_slices != -1) || !file_exists($orig_image_path)) { if ($vid_sec != -1) { $calc_vid_sec = min($vid_sec, floor($entry->getLengthInMsecs() / 1000)); } else { if ($vid_slices != -1) { $calc_vid_sec = floor($entry->getLengthInMsecs() / $vid_slices * min($vid_slice, $vid_slices) / 1000); } else { if ($entry->getStatus() != entryStatus::READY && $entry->getLengthInMsecs() == 0) { $calc_vid_sec = $entry->getPartner() && $entry->getPartner()->getDefThumbOffset() ? $entry->getPartner()->getDefThumbOffset() : 3; } else { $calc_vid_sec = $entry->getBestThumbOffset(); } } } $capturedThumbName = $entry->getId() . "_sec_{$calc_vid_sec}"; $capturedThumbPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempthumb", $entry->getIntId(), $capturedThumbName, $entry->getThumbnail(), $version); $orig_image_path = $capturedThumbPath . "temp_1.jpg"; // if we already captured the frame at that second, dont recapture, just use the existing file if (!file_exists($orig_image_path)) { // creating the thumbnail is a very heavy operation // prevent calling it in parallel for the same thubmnail for 5 minutes $cache = new myCache("thumb-processing", 5 * 60); // 5 minutes $processing = $cache->get($orig_image_path); if ($processing) { KExternalErrors::dieError(KExternalErrors::PROCESSING_CAPTURE_THUMBNAIL); } $cache->put($orig_image_path, true); $flavorAsset = flavorAssetPeer::retrieveOriginalReadyByEntryId($entry->getId()); if (is_null($flavorAsset) || !($flavorAsset->hasTag(flavorParams::TAG_MBR) || $flavorAsset->hasTag(flavorParams::TAG_WEB))) { // try the best playable $flavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId()); } if (is_null($flavorAsset)) { // if no READY ORIGINAL entry is available, try to retreive a non-READY ORIGINAL entry $flavorAsset = flavorAssetPeer::retreiveOriginalByEntryId($entry->getId()); } if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $flavorSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $entry_data_path = kFileSyncUtils::getReadyLocalFilePathForKey($flavorSyncKey); if (!$entry_data_path) { // since this is not really being processed on this server, and will probably cause redirect in thumbnailAction // remove from cache so later requests will still get redirected and will not fail on PROCESSING_CAPTURE_THUMBNAIL $cache->remove($orig_image_path); throw new kFileSyncException('no ready filesync on current DC', kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC); } myFileConverter::autoCaptureFrame($entry_data_path, $capturedThumbPath . "temp_", $calc_vid_sec, -1, -1); $cache->remove($orig_image_path); } } kFile::fullMkdir($tempThumbPath); if ($crop_provider) { $convertedImagePath = myFileConverter::convertImageUsingCropProvider($orig_image_path, $tempThumbPath, $width, $height, $type, $crop_provider, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h); } else { $convertedImagePath = myFileConverter::convertImage($orig_image_path, $tempThumbPath, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h); } // die if resize operation failed if ($convertedImagePath === null) { KExternalErrors::dieError(KExternalErrors::IMAGE_RESIZE_FAILED); } if ($multi) { list($w, $h, $type, $attr, $srcIm) = myFileConverter::createImageByFile($tempThumbPath); if (!$im) { $im = imagecreatetruecolor($w * $vid_slices, $h); } imagecopy($im, $srcIm, $w * $vid_slice, 0, 0, 0, $w, $h); imagedestroy($srcIm); ++$vid_slice; } } if ($multi) { imagejpeg($im, $tempThumbPath); imagedestroy($im); } return $tempThumbPath; }
public function execute() { requestUtils::handleConditionalGet(); // set the memory size to be able to serve big files in a single chunk ini_set("memory_limit", "64M"); // set the execution time to be able to serve big files in a single chunk ini_set("max_execution_time", 240); $meta = $this->getRequestParameter("meta", false); $file_info = $this->getRequestParameter("file_info"); $this->entry_id = 0; $this->kshow_id = 0; $version = $this->getRequestParameter("version", null); // returned the version feature to allow rollback $addPadding = false; if (!empty($file_info)) { $file_info_arr = explode("-", $file_info); // the format of file_info is assumed <kshow_id>-<video|audio|voice>-<1|2|3> // OR // e<entry_id>-<video|audio|voice>-<1|2|3> if (count($file_info_arr) == 0) { $this->error = "Invalid request format [{$file_info}]"; return sfView::ERROR; } if ($file_info_arr[0][0] == 'e') { $this->entry_id = substr($file_info_arr[0], 1); } else { $this->kshow_id = $file_info_arr[0]; } if (count($file_info_arr) == 1) { // on this case we assume that the single info parameter is an entry id // we redirect to it ! $entry = entryPeer::retrieveByPK($this->entry_id); if (!$entry) { // very bad - no such entry !! echo "no entry " . $this->entry_id; die; } $dataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath $path = kFileSyncUtils::getReadyLocalFilePathForKey($dataKey); $host = requestUtils::getHost(); $this->redirect($host . $path); } $this->timeline = $file_info_arr[1]; if (count($file_info_arr) > 2) { // this migth include a .flv suffix $last_token = $file_info_arr[2]; $last_token_srr = explode(".", $last_token); $this->streamNum = $last_token_srr[0]; if (count($file_info_arr) > 3) { $version = $file_info_arr[3]; } if (count($file_info_arr) > 4 && $file_info_arr[4] == "padding") { $addPadding = true; } } else { $this->streamNum = 3; } } else { $this->kshow_id = @$_GET["kshow_id"]; $this->entry_id = @$_GET["entry_id"]; $this->timeline = @$_GET["timeline"]; $this->streamNum = $this->getRequestParameter('num', 3); } $entry = null; if ($this->entry_id) { $entry = entryPeer::retrieveByPK($this->entry_id); if (!$entry) { $this->error = "No such entry " . $this->entry_id; return sfView::ERROR; } $this->kshow_id = $entry->getKshowId(); } $kshow = kshowPeer::retrieveByPK($this->kshow_id); if (!$kshow) { $this->error = "No such kshow " . $this->kshow_id; return sfView::ERROR; } if (!$entry) { // if we received only the kshow (old widgets) retrieve the entry $entry = entryPeer::retrieveByPK($kshow->getShowEntryId()); } if (!$entry) { $this->error = "No such entry for kshow " . $this->kshow_id; return sfView::ERROR; } // update the widget log only for video && stream 1 if ($this->timeline == "video" && $this->streamNum == 1) { $referer = @$_SERVER['HTTP_REFERER']; //since we're using a cdn this is useless //$kshow->incPlays(); //WidgetLog::incPlaysIfExists( $this->kshow_id , $this->entry_id ); } $dataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); // replaced__getDataPath $path = kFileSyncUtils::getReadyLocalFilePathForKey($dataKey); $this->flv_streamer = new myFlvStreamer($path, $this->timeline, $this->streamNum, $addPadding); $this->total_length = $this->flv_streamer->getTotalLength(true); // $total_length; //$this->getController()->setRenderMode ( sfView::RENDER_CLIENT ); myStatisticsMgr::saveAllModified(); //if ( $meta ) return "Meta"; return sfView::SUCCESS; }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { if (!$partner_id) { die; } $entry_id = $this->getP("entry_id"); // if the entry_type was sent by the client - make sure it's of type ENTRY_TYPE_SHOW. // this is to prevent this service as part of a bad multirequest $entry_type = $this->getP("entry_type", null); if (!empty($entry_type) && $entry_type != entryType::MIX) { $this->addDebug("entry", "not of type " . entryType::MIX); return; } $kshow_id = $this->getP("kshow_id"); list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id); if ($error_obj) { $this->addError($error_obj); return; } KalturaLog::log(__METHOD__ . " kshow_id [{$kshow_id}] entry_id [{$entry_id}]"); $list_type = $this->getP("list_type", self::LIST_TYPE_ROUGHCUT); $version = $this->getP("version", null); if ((int) $version == -1) { $version = null; } // will retrieve the latest $disable_roughcut_entry_data = $this->getP("disable_roughcut_entry_data", false); $disable_user_data = $this->getP("disable_user_data", false); // will allow to optimize the cals and NOT join with the kuser table $merge_entry_lists = false; if ($this->getPartner()) { $merge_entry_lists = $this->getPartner()->getMergeEntryLists(); } $kshow_entry_list = array(); $kuser_entry_list = array(); $aggrigate_id_list = array(); $this->benchmarkStart("list_type_kshow"); if ($list_type & self::LIST_TYPE_KSHOW && $kshow_id) { $c = new Criteria(); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); // $c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL ); $c->addAnd(entryPeer::KSHOW_ID, $kshow_id); $this->addIgnoreIdList($c, $aggrigate_id_list); // $this->addOffsetAndLimit ( $c ); // fetch as many as the kshow has if ($disable_user_data) { $kshow_entry_list = entryPeer::doSelect($c); } else { $kshow_entry_list = entryPeer::doSelectJoinkuser($c); } $this->updateAggrigatedIdList($aggrigate_id_list, $kshow_entry_list); } $this->benchmarkEnd("list_type_kshow"); $this->benchmarkStart("list_type_kuser"); if ($list_type & self::LIST_TYPE_KUSER) { // try to get puserKuser - PS2 $puser_kuser = PuserKuserPeer::retrieveByPartnerAndUid($partner_id, null, $puser_id, false); // try to get kuser by partnerId & puserId - PS3 - backward compatibility $apiv3Kuser = kuserPeer::getKuserByPartnerAndUid($partner_id, $puser_id, true); if ($puser_kuser && $puser_kuser->getKuserId() || $apiv3Kuser) { $c = new Criteria(); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); // $c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL ); $kuserIds = array(); if ($puser_kuser && $puser_kuser->getKuserId()) { $kuserIds[] = $puser_kuser->getKuserId(); } if ($apiv3Kuser) { if (!$puser_kuser || $puser_kuser->getKuserId() != $apiv3Kuser->getId()) { $kuserIds[] = $apiv3Kuser->getId(); } } /* if(count($kuserIds) > 1) { $c->addAnd ( entryPeer::KUSER_ID , $kuserIds, Criteria::IN ); } else { $c->addAnd ( entryPeer::KUSER_ID , $kuserIds[0] ); } if ( $merge_entry_lists ) { // if will join lists - no need to fetch entries twice $this->addIgnoreIdList ($c , $aggrigate_id_list); } $this->addOffsetAndLimit ( $c ); // limit the number of the user's clips if ( $disable_user_data ) $kuser_entry_list = entryPeer::doSelect( $c ); else $kuser_entry_list = entryPeer::doSelectJoinkuser( $c ); */ $this->addOffsetAndLimit($c); // limit the number of the user's clips if ($merge_entry_lists) { // if will join lists - no need to fetch entries twice $this->addIgnoreIdList($c, $aggrigate_id_list); } $kuser_entry_list = array(); $kuserIds = array_unique($kuserIds); foreach ($kuserIds as $kuserId) { $newC = clone $c; $newC->addAnd(entryPeer::KUSER_ID, $kuserId); if ($disable_user_data) { $one_kuser_list = entryPeer::doSelect($newC); } else { $one_kuser_list = entryPeer::doSelectJoinkuser($newC); } $kuser_entry_list = array_merge($kuser_entry_list, $one_kuser_list); } // Since we are using 2 potential kusers, we might not have the obvious kuser from $puser_kuser $strEntries = ""; if ($puser_kuser) { $kuser = kuserPeer::retrieveByPk($puser_kuser->getKuserId()); if ($kuser) { $strEntriesTemp = @unserialize($kuser->getPartnerData()); if ($strEntriesTemp) { $strEntries .= $strEntriesTemp; } } } if ($apiv3Kuser) { $strEntriesTemp = @unserialize($apiv3Kuser->getPartnerData()); if ($strEntriesTemp) { $strEntries .= $strEntriesTemp; } } if ($strEntries) { $entries = explode(',', $strEntries); $fixed_entry_list = array(); foreach ($entries as $entryId) { $fixed_entry_list[] = trim($entryId); } $c = new Criteria(); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); $c->addAnd(entryPeer::ID, $fixed_entry_list, Criteria::IN); if ($merge_entry_lists) { // if will join lists - no need to fetch entries twice $this->addIgnoreIdList($c, $aggrigate_id_list); } if ($disable_user_data) { $extra_user_entries = entryPeer::doSelect($c); } else { $extra_user_entries = entryPeer::doSelectJoinkuser($c); } if (count($extra_user_entries)) { $kuser_entry_list = array_merge($extra_user_entries, $kuser_entry_list); } } } else { $kuser_entry_list = array(); } if ($merge_entry_lists) { $kshow_entry_list = kArray::append($kshow_entry_list, $kuser_entry_list); $kuser_entry_list = null; } } $this->benchmarkEnd("list_type_kuser"); $this->benchmarkStart("list_type_episode"); if ($list_type & self::LIST_TYPE_EPISODE) { if ($kshow && $kshow->getEpisodeId()) { // episode_id will point to the "parent" kshow // fetch the entries of the parent kshow $c = new Criteria(); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); // $c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL ); $c->addAnd(entryPeer::KSHOW_ID, $kshow->getEpisodeId()); $this->addIgnoreIdList($c, $aggrigate_id_list); // $this->addOffsetAndLimit ( $c ); // limit the number of the inherited entries from the episode if ($disable_user_data) { $parent_kshow_entries = entryPeer::doSelect($c); } else { $parent_kshow_entries = entryPeer::doSelectJoinkuser($c); } if (count($parent_kshow_entries)) { $kshow_entry_list = kArray::append($kshow_entry_list, $parent_kshow_entries); } } } $this->benchmarkEnd("list_type_episode"); // fetch all entries that were used in the roughcut - those of other kusers // - appeared under kuser_entry_list when someone else logged in $this->benchmarkStart("list_type_roughcut"); $entry_data_from_roughcut_map = array(); // will hold an associative array where the id is the key if ($list_type & self::LIST_TYPE_ROUGHCUT) { if ($entry->getType() == entryType::MIX) { $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); $roughcut_file_name = kFileSyncUtils::getReadyLocalFilePathForKey($sync_key); $entry_data_from_roughcut = myFlvStreamer::getAllAssetsData($roughcut_file_name); $final_id_list = array(); foreach ($entry_data_from_roughcut as $data) { $id = $data["id"]; // first element is the id $entry_data_from_roughcut_map[] = $data; $found = false; foreach ($kshow_entry_list as $entry) { // see we are not fetching duplicate entries if ($entry->getId() == $id) { $found = true; break; } } if (!$found) { $final_id_list[] = $id; } } if (count($final_id_list) > 0) { // allow deleted entries when searching for entries on the roughcut // don't forget to return the status at the end of the process entryPeer::allowDeletedInCriteriaFilter(); $c = new Criteria(); $c->addAnd(entryPeer::ID, $final_id_list, Criteria::IN); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); $this->addIgnoreIdList($c, $aggrigate_id_list); // $this->addOffsetAndLimit ( $c ); if ($disable_user_data) { $extra_entries = entryPeer::doSelect($c); } else { $extra_entries = entryPeer::doSelectJoinkuser($c); } // return the status to the criteriaFilter entryPeer::blockDeletedInCriteriaFilter(); // merge the 2 lists into 1: $kshow_entry_list = kArray::append($kshow_entry_list, $extra_entries); } } } $this->benchmarkEnd("list_type_roughcut"); $this->benchmarkStart("create_wrapper"); $entry_wrapper = objectWrapperBase::getWrapperClass($kshow_entry_list, objectWrapperBase::DETAIL_LEVEL_REGULAR, -3, 0, array("contributorScreenName")); //$entry_wrapper->addFields ( array ( "kuser.screenName" ) ); $this->addMsg("show", $entry_wrapper); // if ! $disable_roughcut_entry_data - add the roughcut_entry_data if (!$disable_roughcut_entry_data) { $this->addMsg("roughcut_entry_data", $entry_data_from_roughcut_map); } if (count($kuser_entry_list) > 0) { $this->addMsg("user", objectWrapperBase::getWrapperClass($kuser_entry_list, objectWrapperBase::DETAIL_LEVEL_REGULAR)); } else { $this->addMsg("user", null); } $this->benchmarkEnd("create_wrapper"); }
/** * Get all ready media entries that exist in the given mix id * * @action getReadyMediaEntries * @param string $mixId * @param int $version Desired version to get the data from * @return KalturaMediaEntryArray */ public function getReadyMediaEntriesAction($mixId, $version = -1) { $dbEntry = entryPeer::retrieveByPK($mixId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MIX) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $mixId); } $dataSyncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $mixFileName = kFileSyncUtils::getReadyLocalFilePathForKey($dataSyncKey, false); if (!$mixFileName) { KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $entryDataFromMix = myFlvStreamer::getAllAssetsData($mixFileName); $ids = array(); foreach ($entryDataFromMix as $data) { $ids[] = $data["id"]; } $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::ID, $ids, Criteria::IN); $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP); $dbEntries = entryPeer::doSelect($c); $mediaEntries = KalturaMediaEntryArray::fromEntryArray($dbEntries); return $mediaEntries; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $entryId = $this->getRequestParameter("entry_id"); $flavorId = $this->getRequestParameter("flavor"); $fileName = $this->getRequestParameter("file_name"); $fileName = basename($fileName); $ksStr = $this->getRequestParameter("ks"); $referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $entry = null; if ($ksStr) { try { kCurrentContext::initKsPartnerUser($ksStr); } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS); } } else { $entry = kCurrentContext::initPartnerByEntryId($entryId); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } kEntitlementUtils::initEntitlementEnforcement(); if (!$entry) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } else { if (!kEntitlementUtils::isEntryEntitled($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } KalturaMonitorClient::initApiMonitor(false, 'extwidget.download', $entry->getPartnerId()); myPartnerUtils::blockInactivePartner($entry->getPartnerId()); $shouldPreview = false; $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, ContextType::DOWNLOAD); if ($securyEntryHelper->shouldPreview()) { $shouldPreview = true; } else { $securyEntryHelper->validateForDownload(); } $flavorAsset = null; if ($flavorId) { // get flavor asset $flavorAsset = assetPeer::retrieveById($flavorId); if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } // the request flavor should belong to the requested entry if ($flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } } else { $flavorAssets = assetPeer::retrieveReadyWebByEntryId($entry->getId()); foreach ($flavorAssets as $curFlavorAsset) { if ($securyEntryHelper->isAssetAllowed($curFlavorAsset)) { $flavorAsset = $curFlavorAsset; break; } } } // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) { $flavorAsset = null; } } if ($flavorAsset) { $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset); } else { $syncKey = $this->getBestSyncKeyForEntry($entry); } if (is_null($syncKey)) { KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $this->handleFileSyncRedirection($syncKey); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); list($fileBaseName, $fileExt) = kAssetUtils::getFileName($entry, $flavorAsset); if (!$fileName) { $fileName = $fileBaseName; } if ($fileExt && !is_dir($filePath)) { $fileName = $fileName . '.' . $fileExt; } $preview = 0; if ($shouldPreview && $flavorAsset) { $preview = $flavorAsset->estimateFileSize($entry, $securyEntryHelper->getPreviewLength()); } else { if (kCurrentContext::$ks_object) { $preview = kCurrentContext::$ks_object->getPrivilegeValue(kSessionBase::PRIVILEGE_PREVIEW, 0); } } //enable downloading file_name which inside the flavor asset directory if (is_dir($filePath)) { $filePath = $filePath . DIRECTORY_SEPARATOR . $fileName; } $this->dumpFile($filePath, $fileName, $preview); KExternalErrors::dieGracefully(); // no view }
public function execute() { //entitlement should be disabled to serveFlavor action as we do not get ks on this action. KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); requestUtils::handleConditionalGet(); $flavorId = $this->getRequestParameter("flavorId"); $shouldProxy = $this->getRequestParameter("forceproxy", false); $fileName = $this->getRequestParameter("fileName"); $fileParam = $this->getRequestParameter("file"); $fileParam = basename($fileParam); $pathOnly = $this->getRequestParameter("pathOnly", false); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $flavorAsset = assetPeer::retrieveById($flavorId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entryId = $this->getRequestParameter("entryId"); if (!is_null($entryId) && $flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if ($fileName) { header("Content-Disposition: attachment; filename=\"{$fileName}\""); header("Content-Type: application/force-download"); header("Content-Description: File Transfer"); } $clipTo = null; $entry = $flavorAsset->getentry(); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveFlavor', $flavorAsset->getPartnerId()); myPartnerUtils::enforceDelivery($entry, $flavorAsset); $version = $this->getRequestParameter("v"); if (!$version) { $version = $flavorAsset->getVersion(); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version); if ($pathOnly && kIpAddressUtils::isInternalIp($_SERVER['REMOTE_ADDR'])) { $path = null; list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, false, false); if ($file_sync) { $parent_file_sync = kFileSyncUtils::resolve($file_sync); $path = $parent_file_sync->getFullPath(); if ($fileParam && is_dir($path)) { $path .= "/{$fileParam}"; } } $renderer = new kRendererString('{"sequences":[{"clips":[{"type":"source","path":"' . $path . '"}]}]}', 'application/json'); if ($path) { $this->storeCache($renderer, $flavorAsset->getPartnerId()); } $renderer->output(); KExternalErrors::dieGracefully(); } if (kConf::hasParam('serve_flavor_allowed_partners') && !in_array($flavorAsset->getPartnerId(), kConf::get('serve_flavor_allowed_partners'))) { KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED); } if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } // always dump remote urls so they will be cached by the cdn transparently $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFileUtils::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $isFlv = false; if (!$shouldProxy) { $flvWrapper = new myFlvHandler($path); $isFlv = $flvWrapper->isFlv(); } $clipFrom = $this->getRequestParameter("clipFrom", 0); // milliseconds if (is_null($clipTo)) { $clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO); } // milliseconds if ($clipTo == 0) { $clipTo = self::NO_CLIP_TO; } if (!is_numeric($clipTo) || $clipTo < 0) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number'); } $seekFrom = $this->getRequestParameter("seekFrom", -1); if ($seekFrom <= 0) { $seekFrom = -1; } $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1); if ($seekFromBytes <= 0) { $seekFromBytes = -1; } if ($fileParam && is_dir($path)) { $path .= "/{$fileParam}"; kFileUtils::dumpFile($path, null, null); KExternalErrors::dieGracefully(); } else { if (!$isFlv || $clipTo == self::NO_CLIP_TO && $seekFrom < 0 && $seekFromBytes < 0) { $limit_file_size = 0; if ($clipTo != self::NO_CLIP_TO) { if (strtolower($flavorAsset->getFileExt()) == 'mp4' && PermissionPeer::isValidForPartner(PermissionName::FEATURE_ACCURATE_SERVE_CLIPPING, $flavorAsset->getPartnerId())) { $contentPath = myContentStorage::getFSContentRootPath(); $tempClipName = $version . '_' . $clipTo . '.mp4'; $tempClipPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempclip", $flavorAsset->getIntId(), $flavorAsset->getId(), $tempClipName); if (!file_exists($tempClipPath)) { kFile::fullMkdir($tempClipPath); $clipToSec = round($clipTo / 1000, 3); $cmdLine = kConf::get("bin_path_ffmpeg") . " -i {$path} -vcodec copy -acodec copy -f mp4 -t {$clipToSec} -y {$tempClipPath} 2>&1"; KalturaLog::log("Executing {$cmdLine}"); $output = array(); $return_value = ""; exec($cmdLine, $output, $return_value); KalturaLog::log("ffmpeg returned {$return_value}, output:" . implode("\n", $output)); } if (file_exists($tempClipPath)) { KalturaLog::log("Dumping {$tempClipPath}"); kFileUtils::dumpFile($tempClipPath); } else { KalturaLog::err('Failed to clip the file using ffmpeg, falling back to rough clipping'); } } $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@kFile::fileSize($path) * ($clipTo / $duration) * 1.2); } } $renderer = kFileUtils::getDumpFileRenderer($path, null, null, $limit_file_size); if (!$fileName) { $this->storeCache($renderer, $flavorAsset->getPartnerId()); } $renderer->output(); KExternalErrors::dieGracefully(); } } $audioOnly = $this->getRequestParameter("audioOnly"); // milliseconds if ($audioOnly === '0') { // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) { $audioOnly = true; } $bytes = 0; if ($seekFrom !== -1 && $seekFrom !== 0) { list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly); list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly); $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte; } else { list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); } $metadataSize = $flvWrapper->getMetadataSize($audioOnly); $dataOffset = $metadataSize + myFlvHandler::getHeaderSize(); $totalLength = $dataOffset + $bytes; list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength); if ($totalLength < 1000) { // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache requestUtils::sendCdnHeaders("flv", $rangeLength, 0); } else { requestUtils::sendCdnHeaders("flv", $rangeLength); } // dont inject cuepoint into the stream $cuepointTime = 0; $cuepointPos = 0; try { Propel::close(); } catch (Exception $e) { $this->logMessage("serveFlavor: error closing db {$e}"); } header("Content-Type: video/x-flv"); $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos); KExternalErrors::dieGracefully(); }
public function execute() { requestUtils::handleConditionalGet(); $flavorId = $this->getRequestParameter("flavorId"); $shouldProxy = $this->getRequestParameter("forceproxy", false); $ks = $this->getRequestParameter("ks"); $fileParam = $this->getRequestParameter("file"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $flavorAsset = flavorAssetPeer::retrieveById($flavorId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId()); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($flavorAsset->getPartnerId()); myPartnerUtils::enforceDelivery($flavorAsset->getPartnerId()); //disabled enforce cdn because of rtmp delivery //requestUtils::enforceCdnDelivery($flavorAsset->getPartnerId()); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } // always dump remote urls so they will be cached by the cdn transparently $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFile::dumpUrl($remoteUrl, true, true); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $flvWrapper = new myFlvHandler($path); $isFlv = $flvWrapper->isFlv(); $clipFrom = $this->getRequestParameter("clipFrom", 0); // milliseconds $clipTo = $this->getRequestParameter("clipTo", 2147483647); // milliseconds if ($clipTo == 0) { $clipTo = 2147483647; } if (is_dir($path) && $fileParam) { $path .= "/{$fileParam}"; //echo "path($path),file($fileParam)"; kFile::dumpFile($path, null, null); die; } else { if (!$isFlv) { $limit_file_size = 0; if ($clipTo != 2147483647) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@filesize($path) * ($clipTo / $duration)); } } kFile::dumpFile($path, null, null, $limit_file_size); die; } } $audioOnly = $this->getRequestParameter("audioOnly"); // milliseconds if ($audioOnly === '0') { // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) { $audioOnly = true; } $seekFrom = $this->getRequestParameter("seekFrom", -1); if ($seekFrom <= 0) { $seekFrom = -1; } $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1); if ($seekFromBytes <= 0) { $seekFromBytes = -1; } $bytes = 0; if ($seekFrom !== -1 && $seekFrom !== 0) { list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly); list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly); $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte; } else { list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); } $metadataSize = $flvWrapper->getMetadataSize($audioOnly); $dataOffset = $metadataSize + myFlvHandler::getHeaderSize(); $totalLength = $dataOffset + $bytes; list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength); if ($totalLength < 1000) { // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache requestUtils::sendCdnHeaders("flv", $rangeLength, 0); } else { requestUtils::sendCdnHeaders("flv", $rangeLength); } header('Content-Disposition: attachment; filename="video.flv"'); // dont inject cuepoint into the stream $cuepointTime = 0; $cuepointPos = 0; try { Propel::close(); } catch (Exception $e) { $this->logMessage("serveFlavor: error closing db {$e}"); } header("Content-Type: video/x-flv"); $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos); die; }
public function execute() { requestUtils::handleConditionalGet(); $entry_id = $this->getRequestParameter("entry_id"); $ks_str = $this->getRequestParameter("ks"); $base64_referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64_referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $clip_from = $this->getRequestParameter("clip_from", 0); // milliseconds $clip_to = $this->getRequestParameter("clip_to", 2147483647); // milliseconds if ($clip_to == 0) { $clip_to = 2147483647; } $request = $_SERVER["REQUEST_URI"]; // remove dynamic fields from the url so we'll request a single url from the cdn $request = str_replace("/referrer/{$base64_referrer}", "", $request); $request = str_replace("/ks/{$ks_str}", "", $request); // workaround the filter which hides all the deleted entries - // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($entry->getPartnerId()); // set the memory size to be able to serve big files in a single chunk ini_set("memory_limit", "64M"); // set the execution time to be able to serve big files in a single chunk ini_set("max_execution_time", 240); if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) { // because the fiter was turned off - a manual check for deleted entries must be done. die; } else { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $version = $this->getRequestParameter("version", null); $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); $crop_provider = $this->getRequestParameter("crop_provider", null); $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $type = $this->getRequestParameter("type", 1); $quality = $this->getRequestParameter("quality", 0); $src_x = $this->getRequestParameter("src_x", 0); $src_y = $this->getRequestParameter("src_y", 0); $src_w = $this->getRequestParameter("src_w", 0); $src_h = $this->getRequestParameter("src_h", 0); $vid_sec = $this->getRequestParameter("vid_sec", -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); if ($width == -1 && $height == -1) { $width = 640; $height = 480; } else { if ($width == -1) { // if only either width or height is missing reset them to zero, and convertImage will handle them $width = 0; } else { if ($height == -1) { $height = 0; } } } $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices); kFile::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0); } } $audio_only = $this->getRequestParameter("audio_only"); // milliseconds $flavor = $this->getRequestParameter("flavor", 1); // $flavor_param_id = $this->getRequestParameter("flavor_param_id", null); // $streamer = $this->getRequestParameter("streamer"); // if (substr($streamer, 0, 4) == "rtmp") { // the fms may add .mp4 to the end of the url $streamer = "rtmp"; } // grab seek_from_bytes parameter and normalize url $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1); $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request); if ($seek_from_bytes <= 0) { $seek_from_bytes = -1; } // grab seek_from parameter and normalize url $seek_from = $this->getRequestParameter("seek_from", -1); $request = str_replace("/seek_from/{$seek_from}", "", $request); if ($seek_from <= 0) { $seek_from = -1; } $this->dump_from_byte = 0; // reset accurate seek from timestamp $seek_from_timestamp = -1; // backward compatibility if ($flavor === "0") { // for edit version $flavor = "edit"; } if ($flavor === "1" || $flavor === 1) { // for play version $flavor = null; } // when flavor is null, we will get a default flavor if ($flavor == "edit") { $flavorAsset = flavorAssetPeer::retrieveBestEditByEntryId($entry->getId()); } elseif (!is_null($flavor)) { $flavorAsset = flavorAssetPeer::retrieveById($flavor); // when specific asset was request, we don't validate its tags if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) { $flavorAsset = null; } // we will throw an error later } elseif (is_null($flavor) && !is_null($flavor_param_id)) { $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entry->getId(), $flavor_param_id); if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAsset = null; } // we will throw an error later } else { if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); } else { $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId()); } if (!$flavorAsset) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB); if (count($flavorAssets) > 0) { $flavorAsset = $flavorAssets[0]; } } } if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::file_exists($syncKey, false)) { $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); } else { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); $this->redirect($remoteUrl); } $flv_wrapper = new myFlvHandler($path); $isFlv = $flv_wrapper->isFlv(); // scrubbing is not allowed within mp4 files if (!$isFlv) { $seek_from = $seek_from_bytes = -1; } if ($seek_from !== -1 && $seek_from !== 0) { if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only); list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only); $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte; } // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath(); $extStorageUrl = $entry->getExtStorageUrl(); if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $request_host = parse_url($extStorageUrl, PHP_URL_HOST); $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl); $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); die; } elseif ($extStorageUrl) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$extStorageUrl}"); die; } // use headers to detect cdn $cdn_name = ""; $via_header = @$_SERVER["HTTP_VIA"]; if (strpos($via_header, "llnw.net") !== false) { $cdn_name = "limelight"; } else { if (strpos($via_header, "akamai") !== false) { $cdn_name = "akamai"; } else { if (strpos($via_header, "Level3") !== false) { $cdn_name = "level3"; } } } // setting file extension - first trying frrom flavor asset $ext = $flavorAsset->getFileExt(); // if failed, set extension according to file type (isFlv) if (!$ext) { $ext = $isFlv ? "flv" : "mp4"; } $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0"; // dont check for rtmp / and for an already redirect url if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // check security using ks $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer); if ($securyEntryHelper->shouldPreview()) { $this->checkForPreview($securyEntryHelper, $clip_to); } else { $securyEntryHelper->validateForPlay($entry, $ks_str); } } else { // if needs security check using cdn authentication mechanism // for now assume this is a cdn request and don't check for security } // use limelight mediavault if either security policy requires it or if we're trying to seek within the video if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) { // we have three options: // arrived through limelight mediavault url - the url is secured // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url // didnt use limelight - enforce ks // the cdns are configured to authenticate request for /s/.... // check if we're already in a redirected secure link using the "/s/" prefix $secure_request = substr($request, 0, 3) == "/s/"; if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) { // request was validated by cdn let it through } else { // extract ks $ks_str = $this->getRequestParameter("ks", ""); if ($entry->getSecurityPolicy()) { if (!$ks_str) { $this->logMessage("flvclipper - no KS"); die; } $ks = kSessionUtils::crackKs($ks_str); if (!$ks) { $this->logMessage("flvclipper - invalid ks [{$ks_str}]"); die; } $matched_privs = $ks->verifyPrivileges("sview", $entry_id); $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]"); if (!$matched_privs) { $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]"); die; } } if ($cdn_name == "limelight") { $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension; $secret = kConf::get("limelight_madiavault_password"); $expire = "&e=" . (time() + 120); $ll_url .= $expire; $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}"; $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs; //header("Location: $ll_url"); $this->redirect($ll_url); } else { if ($cdn_name == "level3") { $level3_url = $request . $flv_extension; if ($entry->getSecurityPolicy()) { $level3_url = "/s{$level3_url}"; // set expire time in GMT hence the date("Z") offset $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30); $level3_url .= $expire; $secret = kConf::get("level3_authentication_key"); $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20); $level3_url .= "&h={$hash}"; } $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}"; header("Location: {$level3_url}"); die; } else { if ($cdn_name == "akamai") { $akamai_url = $request . $flv_extension; // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); die; } } } // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $this->dump_from_byte = $seek_from_bytes; } } } // always add the file suffix to the request (needed for scrubbing by some cdns, // and also breaks without extension on some corporate antivirus). // we add the the novar paramter since a leaving a trailing "?" will be trimmed // and then the /seek_from request will result in another url which level3 // will try to refetch from the origin // note that for streamer we dont add the file extension if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $request .= "/seek_from_bytes/{$seek_from_bytes}"; } requestUtils::sendCdnHeaders("flv", 0); header("Location: {$request}" . $flv_extension); die; } // mp4 if (!$isFlv) { kFile::dumpFile($path); } $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning"); if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } //$start = microtime(true); list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only); $metadata_size = $flv_wrapper->getMetadataSize($audio_only); $this->from_byte = $from_byte; $this->to_byte = $to_byte; //$end1 = microtime(true); //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]"); $data_offset = $metadata_size + myFlvHandler::getHeaderSize(); // if we're returning a partial file adjust the total size: // substract the metadata and bytes which are not delivered if ($this->dump_from_byte >= $data_offset && !$audio_only) { $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset); } $this->total_length = $data_offset + $bytes; //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die; $this->cuepoint_time = 0; $this->cuepoint_pos = 0; if ($streamer == "chunked" && $clip_to != 2147483647) { $this->cuepoint_time = $clip_to - 1; $this->cuepoint_pos = $cuepoint_pos; $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE; } //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); $this->flv_wrapper = $flv_wrapper; $this->audio_only = $audio_only; try { Propel::close(); } catch (Exception $e) { $this->logMessage("flvclipperAction: error closing db {$e}"); } return sfView::SUCCESS; }
public function updateImageDimensions() { $dataPath = kFileSyncUtils::getReadyLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA)); list($width, $height) = $arr = myFileConverter::getImageDimensions($dataPath); if ($width) { $this->putInCustomData("height", $height); $this->putInCustomData("width", $width); } return $arr; }
public static function getLocalImageFilePathByEntry($entry, $version = null) { $sub_type = $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE ? entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA : entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB; $entry_image_key = $entry->getSyncKey($sub_type, $version); $entry_image_path = kFileSyncUtils::getReadyLocalFilePathForKey($entry_image_key); return $entry_image_path; }