本文整理汇总了PHP中kFile::downloadUrlToFile方法的典型用法代码示例。如果您正苦于以下问题:PHP kFile::downloadUrlToFile方法的具体用法?PHP kFile::downloadUrlToFile怎么用?PHP kFile::downloadUrlToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kFile
的用法示例。
在下文中一共展示了kFile::downloadUrlToFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addParseCaptionAssetJob
/**
* @param CaptionAsset $captionAsset
* @param BatchJob $parentJob
* @throws kCoreException FILE_NOT_FOUND
* @return BatchJob
*/
public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null)
{
$syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
$fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
if (!$fileSync) {
if (!PermissionPeer::isValidForPartner(CaptionPermissionName::IMPORT_REMOTE_CAPTION_FOR_INDEXING, $captionAsset->getPartnerId())) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
$fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
if (!$fileSync) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
$fullPath = myContentStorage::getFSUploadsPath() . '/' . $captionAsset->getId() . '.tmp';
if (!kFile::downloadUrlToFile($fileSync->getExternalUrl($captionAsset->getEntryId()), $fullPath)) {
throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND);
}
kFileSyncUtils::moveFromFile($fullPath, $syncKey, true, false, true);
}
$jobData = new kParseCaptionAssetJobData();
$jobData->setCaptionAssetId($captionAsset->getId());
$batchJob = null;
if ($parentJob) {
$batchJob = $parentJob->createChild();
} else {
$batchJob = new BatchJob();
$batchJob->setEntryId($captionAsset->getEntryId());
$batchJob->setPartnerId($captionAsset->getPartnerId());
}
return kJobsManager::addJob($batchJob, $jobData, CaptionSearchPlugin::getBatchJobTypeCoreValue(CaptionSearchBatchJobType::PARSE_CAPTION_ASSET));
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:36,代码来源:kCaptionSearchFlowManager.php
示例2: attachUrl
/**
* @param AttachmentAsset $attachmentAsset
* @param string $url
*/
protected function attachUrl(AttachmentAsset $attachmentAsset, $url)
{
$fullPath = myContentStorage::getFSUploadsPath() . '/' . basename($url);
if (kFile::downloadUrlToFile($url, $fullPath)) {
return $this->attachFile($attachmentAsset, $fullPath);
}
if ($attachmentAsset->getStatus() == AttachmentAsset::ASSET_STATUS_QUEUED || $attachmentAsset->getStatus() == AttachmentAsset::ASSET_STATUS_NOT_APPLICABLE) {
$attachmentAsset->setDescription("Failed downloading file[{$url}]");
$attachmentAsset->setStatus(AttachmentAsset::ASSET_STATUS_ERROR);
$attachmentAsset->save();
}
throw new KalturaAPIException(KalturaAttachmentErrors::ATTACHMENT_ASSET_DOWNLOAD_FAILED, $url);
}
示例3: attachUrlResource
/**
* @param kUrlResource $resource
* @param entry $dbEntry
* @param asset $dbAsset
* @return asset
*/
protected function attachUrlResource(kUrlResource $resource, entry $dbEntry, asset $dbAsset = null)
{
if ($dbAsset instanceof flavorAsset) {
$dbEntry->setSource(KalturaSourceType::URL);
$dbEntry->save();
}
$url = $resource->getUrl();
if (!$resource->forceAsyncDownload()) {
// TODO - move image handling to media service
if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
$entryFullPath = myContentStorage::getFSUploadsPath() . '/' . $dbEntry->getId() . '.jpg';
if (kFile::downloadUrlToFile($url, $entryFullPath)) {
return $this->attachFile($entryFullPath, $dbEntry, $dbAsset);
}
KalturaLog::err("Failed downloading file[{$url}]");
$dbEntry->setStatus(entryStatus::ERROR_IMPORTING);
$dbEntry->save();
return null;
}
if ($dbAsset && !$dbAsset instanceof flavorAsset) {
$ext = pathinfo($url, PATHINFO_EXTENSION);
$entryFullPath = myContentStorage::getFSUploadsPath() . '/' . $dbEntry->getId() . '.' . $ext;
if (kFile::downloadUrlToFile($url, $entryFullPath)) {
$dbAsset = $this->attachFile($entryFullPath, $dbEntry, $dbAsset);
return $dbAsset;
}
KalturaLog::err("Failed downloading file[{$url}]");
$dbAsset->setStatus(asset::FLAVOR_ASSET_STATUS_ERROR);
$dbAsset->save();
return null;
}
}
kJobsManager::addImportJob(null, $dbEntry->getId(), $this->getPartnerId(), $url, $dbAsset, null, $resource->getImportJobData());
return $dbAsset;
}
示例4: myBatchFlattenServer
public function myBatchFlattenServer($script_name)
{
$this->script_name = $script_name;
$this->register($script_name);
SET_CONTEXT("FS");
$MAX_ITERATIONS_DUE_TO_PROPEL_MEMORY_LEAK = 10000000;
self::initDb();
list($sleep_between_cycles, $number_of_times_to_skip_writing_sleeping) = self::getSleepParams('app_flatten_');
$last_worker_count = 0;
$iteration = 0;
$c = new Criteria();
$currentDc = kDataCenterMgr::getCurrentDc();
$c->add(BatchJobPeer::DC, kDataCenterMgr::getCurrentDcId());
$c->add(BatchJobPeer::JOB_TYPE, BatchJobType::FLATTEN);
$c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_PROCESSED);
$temp_count = 0;
while (1) {
self::exitIfDone();
try {
sleep($sleep_between_cycles);
$jobs = BatchJobPeer::doSelect($c);
foreach ($jobs as $job) {
$data = json_decode($job->getData(true), true);
$entry_id = $data['entryId'];
$entry_int_id = $data['entryIntId'];
$entry_version = $data['entryVersion'];
$file_format = $data['fileFormat'];
$entry = entryPeer::retrieveByPK($entry_id);
if (!$entry) {
// entry is probably deleted if it is not returned from retrieveByPK
// close job as failed
$job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
$job->setDescription("could not retrieve entry, probably deleted");
TRACE("could not retrieve entry {$entry_id} , probably deleted");
$job->save();
continue;
}
$fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $file_format);
$fullFinalPath = kFileSyncUtils::getLocalFilePathForKey($fileSyncKey);
$finalPathNoExt = substr($fullFinalPath, 0, strlen($fullFinalPath) - strlen($file_format));
myContentStorage::fullMkdir($fullFinalPath);
$wildcardFinalPath = $finalPathNoExt . "*";
$older_files = glob($wildcardFinalPath);
foreach ($older_files as $older_file) {
TRACE("removing old file: [{$older_file}]");
@unlink($older_file);
}
TRACE("Downloading: {$fullFinalPath}");
kFile::downloadUrlToFile($data["serverUrl"], $fullFinalPath);
if (!file_exists($fullFinalPath)) {
TRACE("file doesnt exist: " . $data["serverUrl"]);
$job->setDescription("file doesnt exist: " . $data["serverUrl"]);
$job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
} else {
if (filesize($fullFinalPath) < 100000) {
@unlink($fullFinalPath);
TRACE("file too small: " . $data["serverUrl"]);
$job->setDescription("file too small: " . $data["serverUrl"]);
$job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
} else {
if ($data['email']) {
$downloadLink = $entry->getDownloadUrl() . '/format/' . $file_format;
kJobsManager::addMailJob(null, $entry_id, $entry->getPartnerId(), self::KALTURAS_FLATTEN_READY, kMailJobData::MAIL_PRIORITY_NORMAL, kConf::get("batch_flatten_video_sender_email"), kConf::get("batch_flatten_video_sender_name"), $data['email'], array($data['email'], $downloadLink));
}
TRACE("Deleting: " . $data["deleteUrl"]);
kFile::downloadUrlToString($data["deleteUrl"]);
myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
$job->setStatus(BatchJob::BATCHJOB_STATUS_FINISHED);
$filePath = kFileSyncUtils::getLocalFilePathForKey($fileSyncKey);
if (file_exists($filePath)) {
try {
kFileSyncUtils::createSyncFileForKey($fileSyncKey);
} catch (Exception $ex) {
TRACE("ignore ERROR: " . $ex->getMessage());
}
} else {
TRACE("The file [{$filePath}] doesn't exists, not creating FileSync");
}
}
}
$job->save();
}
} catch (Exception $ex) {
TRACE("ERROR: " . $ex->getMessage());
self::initDb(true);
self::failed();
}
if ($temp_count == 0) {
TRACE("Ended conversion. sleeping for a while (" . $sleep_between_cycles . " seconds). Will write to the log in (" . $sleep_between_cycles * $number_of_times_to_skip_writing_sleeping . ") seconds");
}
$temp_count++;
if ($temp_count >= $number_of_times_to_skip_writing_sleeping) {
$temp_count = 0;
}
}
}
示例5: handleEntry
private function handleEntry($onlyExtractThumb, $prefix, $type, $entry_id, $name = null, $tags = null, $entry = null)
{
KalturaLog::debug("handleEntry({$type}, {$entry_id}, {$name})");
$this->clear($prefix, $entry_id);
$kuser_id = $this->kuser_id;
$entry_data_prefix = $kuser_id . '_' . ($prefix == '' ? 'data' : rtrim($prefix, '_'));
$uploads = myContentStorage::getFSUploadsPath();
$content = myContentStorage::getFSContentRootPath();
$media_source = $this->getParam('entry_media_source');
$media_type = $this->getParam('entry_media_type');
$entry_url = $this->getParam('entry_url');
$entry_source_link = $this->getParam('entry_source_link');
$entry_fileName = $this->getParam('entry_data');
$entry_thumbNum = $this->getParam('entry_thumb_num', 0);
$entry_thumbUrl = $this->getParam('entry_thumb_url', '');
$should_copy = $this->getParam('should_copy', false);
$skip_conversion = $this->getParam('skip_conversion', false);
$webcam_suffix = $this->getParam('webcam_suffix', '');
$duration = $this->getParam('duration', null);
$entry_fullPath = "";
$ext = null;
$entry = null;
if ($entry_id) {
$entry = entryPeer::retrieveByPK($entry_id);
} else {
$entry = new entry();
}
$this->entry = $entry;
$entry_status = $entry->getStatus();
if (is_null($entry_status)) {
$entry_status = entryStatus::READY;
}
// by the end of this block of code $entry_fullPath will point to the location of the entry
// the entry status will be set (IMPORT / PRECONVERT / READY)
// a background image is always previewed by the user no matter what source he used
// so the entry is already in the /uploads directory
// continue tracking the file upload
$te = new TrackEntry();
$te->setEntryId($entry_id);
$te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
KalturaLog::debug("handleEntry: media_source: {$media_source}, prefix: {$prefix}");
if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE || $prefix == 'bg_') {
$full_path = $this->getParam('entry_full_path');
if ($full_path) {
$entry_fullPath = $full_path;
} else {
$entry_fullPath = $uploads . $entry_data_prefix . strrchr($entry_fileName, '.');
}
if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
$entry_status = entryStatus::PRECONVERT;
}
$te->setParam3Str($entry_fullPath);
$te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
} else {
if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
// set $entry_fileName to webcam output file and flag that conversion is not needed
$webcam_basePath = $content . '/content/webcam/' . ($webcam_suffix ? $webcam_suffix : 'my_recorded_stream_' . $kuser_id);
$entry_fullPath = $webcam_basePath . '.' . kWAMSWebcam::OUTPUT_FILE_EXT;
$ext = kWAMSWebcam::OUTPUT_FILE_EXT;
if (file_exists($entry_fullPath)) {
// continue tracking the webcam
$te->setParam3Str($entry_fullPath);
$te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_WEBCAM");
} else {
KalturaLog::err("File [{$entry_fullPath}] does not exist");
$entry_status = entryStatus::ERROR_IMPORTING;
}
} else {
// if the url ends with .ext, we'll extract it this way
$urlext = strrchr($entry_url, '.');
// TODO: fix this patch
if (strlen($urlext) > 4) {
$urlext = '.jpg';
}
// if we got something wierd, assume we're downloading a jpg
$entry_fileName = $entry_data_prefix . $urlext;
KalturaLog::debug("handleEntry: media_type: {$media_type}");
if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
$duration = 0;
$entry_fullPath = $uploads . $entry_fileName;
if (!kFile::downloadUrlToFile($entry_url, $entry_fullPath)) {
KalturaLog::debug("Failed downloading file[{$entry_url}]");
$entry_status = entryStatus::ERROR_IMPORTING;
}
// track images
$te->setParam3Str($entry_fullPath);
$te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_IMAGE");
} else {
if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
//fixme - we can extract during import
$ext = "flv";
} else {
$ext = "mp3";
}
$entry_status = entryStatus::IMPORT;
// track images
$te->setParam3Str($ext);
$te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_VIDEO");
}
}
//.........这里部分代码省略.........
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:101,代码来源:myInsertEntryHelper.class.php
示例6: attachUrl
/**
* @param thumbAsset $thumbAsset
* @param string $url
*/
protected function attachUrl(thumbAsset $thumbAsset, $url)
{
$fullPath = myContentStorage::getFSUploadsPath() . '/' . $thumbAsset->getId() . '.jpg';
if (kFile::downloadUrlToFile($url, $fullPath)) {
return $this->attachFile($thumbAsset, $fullPath);
}
if ($thumbAsset->getStatus() == thumbAsset::ASSET_STATUS_QUEUED || $thumbAsset->getStatus() == thumbAsset::ASSET_STATUS_NOT_APPLICABLE) {
$thumbAsset->setDescription("Failed downloading file[{$url}]");
$thumbAsset->setStatus(thumbAsset::ASSET_STATUS_ERROR);
$thumbAsset->save();
}
throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_DOWNLOAD_FAILED, $url);
}
示例7: addCapturaThumbJob
/**
* @param BatchJob $parentJob
* @param int $partnerId
* @param string $entryId
* @param string $thumbAssetId
* @param FileSyncKey $srcSyncKey
* @param string $srcAssetId
* @param int $srcAssetType enum of assetType
* @param thumbParamsOutput $thumbParams
* @return BatchJob
*/
public static function addCapturaThumbJob(BatchJob $parentJob = null, $partnerId, $entryId, $thumbAssetId, FileSyncKey $srcSyncKey, $srcAssetId, $srcAssetType, thumbParamsOutput $thumbParams = null)
{
$thumbAsset = assetPeer::retrieveById($thumbAssetId);
if (!$thumbAsset) {
KalturaLog::err("No thumbnail asset found for id [{$thumbAssetId}]");
return null;
}
$partner = PartnerPeer::retrieveByPK($thumbAsset->getPartnerId());
list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
if (!$fileSync) {
$thumbAsset->setStatus(asset::ASSET_STATUS_ERROR);
$thumbAsset->setDescription("Source file sync not found: {$srcSyncKey}");
$thumbAsset->save();
KalturaLog::err("Source file sync not found: {$srcSyncKey}");
return null;
}
if (!$local) {
if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
$url = $fileSync->getExternalUrl($entryId);
$originalAsset = kFileSyncUtils::retrieveObjectForSyncKey($srcSyncKey);
if ($originalAsset instanceof flavorAsset) {
KalturaLog::debug("Creates import job for remote file sync [{$url}]");
if ($thumbParams) {
$thumbParams->setSourceParamsId($originalAsset->getFlavorParamsId());
$thumbParams->save();
}
$thumbAsset->setStatus(asset::ASSET_STATUS_WAIT_FOR_CONVERT);
$thumbAsset->setDescription("Source file sync is importing: {$srcSyncKey}");
$thumbAsset->save();
return kJobsManager::addImportJob($parentJob, $thumbAsset->getEntryId(), $partner->getId(), $url, $originalAsset, null, null, true);
}
KalturaLog::debug("Downloading remote file sync [{$url}]");
$downloadPath = myContentStorage::getFSUploadsPath() . '/' . $thumbAsset->getId() . '.jpg';
if (kFile::downloadUrlToFile($url, $downloadPath)) {
kFileSyncUtils::moveFromFile($downloadPath, $srcSyncKey);
list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, false, false);
if (!$fileSync) {
throw new kCoreException("Source file not found for thumbnail capture [{$thumbAssetId}]", kCoreException::SOURCE_FILE_NOT_FOUND);
}
}
} else {
throw new kCoreException("Source file not found for thumbnail capture [{$thumbAssetId}]", kCoreException::SOURCE_FILE_NOT_FOUND);
}
}
$localPath = $fileSync->getFullPath();
$remoteUrl = $fileSync->getExternalUrl($entryId);
$srcWamsAssetId = $fileSync->getWamsAssetId();
// creates convert data
$data = new kCaptureThumbJobData();
$data->setThumbAssetId($thumbAssetId);
$data->setSrcAssetId($srcAssetId);
$data->setSrcAssetType($srcAssetType);
$data->setSrcFileSyncLocalPath($localPath);
$data->setSrcFileSyncRemoteUrl($remoteUrl);
$data->setThumbParamsOutputId($thumbParams->getId());
$data->setSrcWamsAssetId($srcWamsAssetId);
$batchJob = null;
if ($parentJob) {
$batchJob = $parentJob->createChild();
} else {
$batchJob = new BatchJob();
$batchJob->setEntryId($entryId);
$batchJob->setPartnerId($partnerId);
}
return kJobsManager::addJob($batchJob, $data, BatchJobType::CAPTURE_THUMB);
}