public static function getAssetUrl(asset $asset, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null, $urlParameters = '') { $partner = PartnerPeer::retrieveByPK($asset->getPartnerId()); if (!$partner) { return null; } $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = self::getExternalStorageUrl($partner, $asset, $syncKey, $servePlayManifest, $playManifestClientTag, $storageId); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } if ($asset instanceof flavorAsset && $servePlayManifest) { $url = requestUtils::getApiCdnHost() . $asset->getPlayManifestUrl($playManifestClientTag, $storageId); } else { $urlManager = DeliveryProfilePeer::getDeliveryProfile($asset->getEntryId()); if ($asset instanceof flavorAsset) { $urlManager->initDeliveryDynamicAttributes(null, $asset); } $profileAttributes = $urlManager->getDynamicAttributes(); $profileAttributes->setUrlParams($urlParameters); $url = $urlManager->getFullAssetUrl($asset); $url = preg_replace('/^https?:\\/\\//', '', $url); $protocol = infraRequestUtils::getProtocol(); $deliveryProfileProtocols = $urlManager->getMediaProtocols(); if (!is_null($deliveryProfileProtocols) && !in_array($protocol, explode(',', $deliveryProfileProtocols))) { $protocol = infraRequestUtils::PROTOCOL_HTTP; } $url = $protocol . "://" . $url; } return $url; }
/** * @param asset $asset * @param string $fileName * @param bool $forceProxy * @param int $version * @throws KalturaErrors::FILE_DOESNT_EXIST */ protected function serveAsset(asset $asset, $fileName, $forceProxy = false, $version = null) { $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $version); $fileSync = null; $serveRemote = false; $partner = PartnerPeer::retrieveByPK($asset->getPartnerId()); switch ($partner->getStorageServePriority()) { case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY: $serveRemote = true; $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } break; case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_FIRST: $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if ($fileSync && $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_READY) { $serveRemote = true; } break; case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST: $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); if ($fileSync) { break; } $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } $serveRemote = true; break; case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY: $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); if (!$fileSync) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } break; } if ($serveRemote && $fileSync) { header("Location: " . $fileSync->getExternalUrl($asset->getEntryId())); die; } return $this->serveFile($asset, asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $fileName, $asset->getEntryId(), $forceProxy); }
public static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription) { $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $errDescription = 'Source asset could has no valid file sync'; return false; } $srcPath = $fileSync->getFullPath(); $uniqid = uniqid('thumb_'); $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg"; $logPath = $destPath . '.log'; if (!file_exists($srcPath)) { $errDescription = "Source file [{$srcPath}] does not exist"; return false; } if (!is_file($srcPath)) { $errDescription = "Source file [{$srcPath}] is not a file"; return false; } try { if ($srcAsset->getType() == assetType::FLAVOR) { // generates the thumbnail $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg')); $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset()); if (!$created || !file_exists($destPath)) { $errDescription = "Thumbnail not captured"; return false; } $srcPath = $destPath; $uniqid = uniqid('thumb_'); $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg"; } $quality = $destThumbParamsOutput->getQuality(); $cropType = $destThumbParamsOutput->getCropType(); $cropX = $destThumbParamsOutput->getCropX(); $cropY = $destThumbParamsOutput->getCropY(); $cropWidth = $destThumbParamsOutput->getCropWidth(); $cropHeight = $destThumbParamsOutput->getCropHeight(); $bgcolor = $destThumbParamsOutput->getBackgroundColor(); $width = $destThumbParamsOutput->getWidth(); $height = $destThumbParamsOutput->getHeight(); $scaleWidth = $destThumbParamsOutput->getScaleWidth(); $scaleHeight = $destThumbParamsOutput->getScaleHeight(); $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true); $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor); if (!$cropped || !file_exists($destPath)) { $errDescription = "Crop failed"; return false; } return $destPath; } catch (Exception $ex) { $errDescription = $ex->getMessage(); return false; } }
public function isPendingExport(asset $asset) { $key = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $c = FileSyncPeer::getCriteriaForFileSyncKey($key); $c->addAnd(FileSyncPeer::DC, $this->getId(), Criteria::EQUAL); $fileSync = FileSyncPeer::doSelectOne($c); if (!$fileSync) { return false; } return $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_PENDING; }
private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription, $rotate = null) { $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $errDescription = 'Source asset could has no valid file sync'; return false; } $srcPath = $fileSync->getFullPath(); $uniqid = uniqid('thumb_'); $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg'; $logPath = $destPath . '.log'; if (!file_exists($srcPath)) { $errDescription = "Source file [{$srcPath}] does not exist"; return false; } if (!is_file($srcPath)) { $errDescription = "Source file [{$srcPath}] is not a file"; return false; } try { if ($srcAsset->getType() == assetType::FLAVOR) { /* @var $srcAsset flavorAsset */ $dar = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); if ($mediaInfo) { $dar = $mediaInfo->getVideoDar(); } // generates the thumbnail $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg')); $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar); if (!$created || !file_exists($destPath)) { $errDescription = "Thumbnail not captured"; return false; } $srcPath = $destPath; $uniqid = uniqid('thumb_'); $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg'; } if ($srcAsset->getType() == assetType::THUMBNAIL) { $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . "." . $srcAsset->getFileExt(); } $quality = $destThumbParamsOutput->getQuality(); $cropType = $destThumbParamsOutput->getCropType(); $cropX = $destThumbParamsOutput->getCropX(); $cropY = $destThumbParamsOutput->getCropY(); $cropWidth = $destThumbParamsOutput->getCropWidth(); $cropHeight = $destThumbParamsOutput->getCropHeight(); $bgcolor = $destThumbParamsOutput->getBackgroundColor(); $width = $destThumbParamsOutput->getWidth(); $height = $destThumbParamsOutput->getHeight(); $scaleWidth = $destThumbParamsOutput->getScaleWidth(); $scaleHeight = $destThumbParamsOutput->getScaleHeight(); $density = $destThumbParamsOutput->getDensity(); $stripProfiles = $destThumbParamsOutput->getStripProfiles(); $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true); $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $rotate, $stripProfiles); if (!$cropped || !file_exists($destPath)) { $errDescription = "Crop failed"; return false; } return $destPath; } catch (Exception $ex) { $errDescription = $ex->getMessage(); return false; } }
private static function deleteAssetLocalFileSyncs($fileSyncVersion, asset $asset) { $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $fileSyncVersion); kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ISM, $fileSyncVersion); kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ISMC, $fileSyncVersion); kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); }
/** * @param asset $asset * @param string $class * @param string $encodingProfile * @param string $duration * @param string $url */ protected function createEnclosureXml(asset $asset, $class, $encodingProfile, $duration) { /** * * In QuickPlay's XML example, the namespace "http://www.quickplaymedia.com" is added to the "enclosure" * element regardless to the fact that it was registerted with the prefix "qpm" on the root element. * We cannot set a namespace that was already defined with a prefix because DOMDocument will add the element * as "qpm:enclosure" and won't set the namespace explicitly. * * The hack is to create a new KDOMDocument with default namespace "http://www.quickplaymedia.com" and then * add it to the xml manually (see getXml() method) * */ $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey); $contentNode = $this->_enclosureNode->cloneNode(true); kXml::setNodeValue($this->_xpath, '@encodingProfile', $encodingProfile, $contentNode); $url = $this->getAssetUrl($asset); $mimeType = $this->getContentTypeFromUrl($url); $enclosureDoc = new KDOMDocument(); $enclosureElement = $enclosureDoc->createElementNS('http://www.quickplaymedia.com', 'enclosure'); $xmlElement = $enclosureDoc->createElement('xml'); $enclosureDoc->appendChild($xmlElement); $enclosureNode = $enclosureDoc->importNode($contentNode, true); $enclosureNode->setAttribute('class', $class); $link = $enclosureNode->getElementsByTagName('link')->item(0); $link->setAttribute('type', $mimeType); $link->setAttribute('length', $fileSync->getFileSize()); $link->setAttribute('duration', $duration); $link->setAttribute('url', pathinfo($fileSync->getFilePath(), PATHINFO_BASENAME)); $xmlElement->appendChild($enclosureNode); return $enclosureDoc->saveXML($enclosureNode); }
/** * @param asset $asset * @return string */ public static function getAssetUrl(asset $asset, $storageId = null) { $partner = PartnerPeer::retrieveByPK($asset->getPartnerId()); if (!$partner) { return null; } $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = self::getExternalStorageUrl($partner, $asset, $syncKey, $storageId); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId()); $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId()); $urlManager->setDomain($cdnHost); $url = $urlManager->getAssetUrl($asset); $url = $cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); return 'http://' . $url; }