/**
  * return the flavor params the best fits the fileFormat for a given partner_id
  * 
  * @param int $partnerId
  * @param string $fileFormat
  * @return FlavorParams
  */
 public static function getFlavorParamsFromFileFormat($partnerId, $fileFormat, $ignoreSourceTag = true)
 {
     $defaultCriteria = flavorParamsPeer::getCriteriaFilter()->getFilter();
     $defaultCriteria->remove(flavorParamsPeer::PARTNER_ID);
     //		flavorParamsPeer::allowAccessToPartner0AndPartnerX($partnerId); // the flavor params can be from partner 0 too
     $c = new Criteria();
     $c->addAnd(flavorParamsPeer::PARTNER_ID, array($partnerId, 0), Criteria::IN);
     //		$c->add (  flavorParamsPeer::FORMAT , $fileFormat );
     $possible_flavor_params = flavorParamsPeer::doSelect($c);
     flavorParamsPeer::setDefaultCriteriaFilter();
     $best_fp = null;
     foreach ($possible_flavor_params as $fp) {
         if ($fileFormat != $fp->getFormat()) {
             continue;
         }
         if ($ignoreSourceTag && $fp->hasTag(flavorParams::TAG_SOURCE)) {
             continue;
         }
         if (!$best_fp) {
             $best_fp = $fp;
         }
         if ($fp->getPartnerId() != $partnerId) {
             continue;
         }
         // same format for the partner
         $best_fp = $fp;
         break;
     }
     // if not fount any - choose the first flavor params from the list
     if (!$best_fp) {
         $best_fp = $possible_flavor_params[0];
     }
     return $best_fp;
 }
Пример #2
0
 public function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     EmailIngestionProfilePeer::clearInstancePool();
     entryPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     flavorAssetPeer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     flavorParamsOutputPeer::clearInstancePool();
     flavorParamsPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     notificationPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     // TODO clear default filters
     // TODO call all memory cleaner plugins
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
Пример #3
0
 public static function filterTagFlavors(array $flavors)
 {
     KalturaLog::log("Filter Tag Flavors, " . count($flavors) . " flavors supplied");
     // check if there is a complete flavor
     $hasComplied = false;
     $hasForced = false;
     $originalFlavorParamsIds = array();
     foreach ($flavors as $flavorParamsId => $flavor) {
         $originalFlavorParamsIds[] = $flavor->getFlavorParamsId();
         if (!$flavor->_isNonComply) {
             $hasComplied = true;
         }
         if ($flavor->_force) {
             $hasForced = true;
         }
     }
     $originalFlavorParams = array();
     $dbOriginalFlavorParams = flavorParamsPeer::retrieveByPKs($originalFlavorParamsIds);
     foreach ($dbOriginalFlavorParams as $dbFlavorParams) {
         $originalFlavorParams[$dbFlavorParams->getId()] = $dbFlavorParams;
     }
     // return only complete flavors
     if ($hasComplied) {
         KalturaLog::log("Has complied flavors");
     }
     if ($hasForced) {
         KalturaLog::log("Has forced flavors");
     }
     if ($hasComplied || $hasForced) {
         return $flavors;
     }
     // find the lowest flavor
     $lowestFlavorParamsId = null;
     foreach ($flavors as $flavorParamsId => $flavor) {
         if (!$flavor->IsValid()) {
             continue;
         }
         // is lower than the selected
         if (!isset($originalFlavorParams[$flavor->getFlavorParamsId()])) {
             continue;
         }
         $currentOriginalFlavor = $originalFlavorParams[$flavor->getFlavorParamsId()];
         // is first flavor to check
         if (is_null($lowestFlavorParamsId)) {
             $lowestFlavorParamsId = $flavorParamsId;
             continue;
         }
         $lowestOriginalFlavor = $originalFlavorParams[$flavors[$lowestFlavorParamsId]->getFlavorParamsId()];
         if (self::isFlavorLower($currentOriginalFlavor, $lowestOriginalFlavor)) {
             $lowestFlavorParamsId = $flavorParamsId;
         }
     }
     if ($lowestFlavorParamsId) {
         KalturaLog::log("Lowest flavor selected [{$lowestFlavorParamsId}]");
         $flavors[$lowestFlavorParamsId]->_create_anyway = true;
     }
     return $flavors;
 }
Пример #4
0
 public function initService($serviceId, $serviceName, $actionName)
 {
     parent::initService($serviceId, $serviceName, $actionName);
     parent::applyPartnerFilterForClass(flavorAssetPeer::getInstance());
     parent::applyPartnerFilterForClass(flavorParamsPeer::getInstance());
     parent::applyPartnerFilterForClass(flavorParamsOutputPeer::getInstance());
     parent::applyPartnerFilterForClass(new entryPeer());
     parent::applyPartnerFilterForClass(new syndicationFeedPeer());
 }
Пример #5
0
 public static function getInstance()
 {
     if (!self::$myInstance) {
         self::$myInstance = new flavorParamsPeer();
     }
     if (!self::$instance || !self::$instance instanceof flavorParamsPeer) {
         self::$instance = self::$myInstance;
     }
     return self::$myInstance;
 }
Пример #6
0
 /**
  * Creates new download job for multiple entry ids (comma separated), an email will be sent when the job is done
  * This sevice support the following entries: 
  * - MediaEntry
  * 	   - Video will be converted using the flavor params id
  *     - Audio will be downloaded as MP3
  *     - Image will be downloaded as Jpeg
  * - MixEntry will be flattend using the flavor params id
  * - Other entry types are not supported
  * 
  * Returns the admin email that the email message will be sent to 
  * 
  * @action xAddBulkDownload
  * @param string $entryIds Comma separated list of entry ids
  * @param string $flavorParamsId
  * @return string
  */
 public function xAddBulkDownloadAction($entryIds, $flavorParamsId = "")
 {
     $flavorParamsDb = null;
     if ($flavorParamsId !== null && $flavorParamsId != "") {
         $flavorParamsDb = flavorParamsPeer::retrieveByPK($flavorParamsId);
         if (!$flavorParamsDb) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
         }
     }
     kJobsManager::addBulkDownloadJob($this->getPartnerId(), $this->getKuser()->getPuserId(), $entryIds, $flavorParamsId);
     return $this->getKuser()->getEmail();
 }
Пример #7
0
 public function initService($serviceId, $serviceName, $actionName)
 {
     parent::initService($serviceId, $serviceName, $actionName);
     parent::applyPartnerFilterForClass(flavorAssetPeer::getInstance());
     parent::applyPartnerFilterForClass(flavorParamsOutputPeer::getInstance());
     parent::applyPartnerFilterForClass(new conversionProfile2Peer());
     $partnerGroup = null;
     if ($actionName == 'add' || $actionName == 'update') {
         $partnerGroup = $this->partnerGroup . ',0';
     }
     parent::applyPartnerFilterForClass(flavorParamsPeer::getInstance(), $partnerGroup);
 }
Пример #8
0
 /**
  * Get the associated assetParams object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     assetParams The associated assetParams object.
  * @throws     PropelException
  */
 public function getFlavorParams(PropelPDO $con = null)
 {
     if ($this->aassetParams === null && $this->flavor_params_id !== null) {
         $this->aassetParams = flavorParamsPeer::retrieveByPk($this->flavor_params_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aassetParams->addassets($this);
         		 */
     }
     return $this->aassetParams;
 }
Пример #9
0
 /**
  * Get Flavor Asset with the relevant Flavor Params (Flavor Params can exist without Flavor Asset & vice versa)
  * 
  * @action getFlavorAssetsWithParams
  * @param string $entryId
  * @return KalturaFlavorAssetWithParamsArray
  */
 public function getFlavorAssetsWithParamsAction($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     // get all the flavor params of partner 0 and the current partner (note that partner 0 is defined as partner group in service.ct)
     $flavorParamsDb = flavorParamsPeer::doSelect(new Criteria());
     // get the flavor assets for this entry
     $c = new Criteria();
     $c->add(flavorAssetPeer::ENTRY_ID, $entryId);
     $c->add(flavorAssetPeer::STATUS, array(flavorAsset::FLAVOR_ASSET_STATUS_DELETED, flavorAsset::FLAVOR_ASSET_STATUS_TEMP), Criteria::NOT_IN);
     $flavorAssetsDb = flavorAssetPeer::doSelect($c);
     // find what flavot params are required
     $requiredFlavorParams = array();
     foreach ($flavorAssetsDb as $item) {
         $requiredFlavorParams[$item->getFlavorParamsId()] = true;
     }
     // now merge the results, first organize the flavor params in an array with the id as the key
     $flavorParamsArray = array();
     foreach ($flavorParamsDb as $item) {
         $flavorParams = $item->getId();
         $flavorParamsArray[$flavorParams] = $item;
         if (isset($requiredFlavorParams[$flavorParams])) {
             unset($requiredFlavorParams[$flavorParams]);
         }
     }
     // adding missing required flavors params to the list
     if (count($requiredFlavorParams)) {
         $flavorParamsDb = flavorParamsPeer::retrieveByPKsNoFilter(array_keys($requiredFlavorParams));
         foreach ($flavorParamsDb as $item) {
             $flavorParamsArray[$item->getId()] = $item;
         }
     }
     $usedFlavorParams = array();
     // loop over the flavor assets and add them, if it has flavor params add them too
     $flavorAssetWithParamsArray = new KalturaFlavorAssetWithParamsArray();
     foreach ($flavorAssetsDb as $flavorAssetDb) {
         $flavorParamsId = $flavorAssetDb->getFlavorParamsId();
         $flavorAssetWithParams = new KalturaFlavorAssetWithParams();
         $flavorAssetWithParams->entryId = $entryId;
         $flavorAsset = new KalturaFlavorAsset();
         $flavorAsset->fromObject($flavorAssetDb);
         $flavorAssetWithParams->flavorAsset = $flavorAsset;
         if (isset($flavorParamsArray[$flavorParamsId])) {
             $flavorParamsDb = $flavorParamsArray[$flavorParamsId];
             $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType());
             $flavorParams->fromObject($flavorParamsDb);
             $flavorAssetWithParams->flavorParams = $flavorParams;
             // we want to log which flavor params are in use, there could be more
             // than one flavor asset using same params
             $usedFlavorParams[$flavorParamsId] = $flavorParamsId;
         }
         //			else if ($flavorAssetDb->getIsOriginal())
         //			{
         //				// create a dummy flavor params
         //				$flavorParams = new KalturaFlavorParams();
         //				$flavorParams->name = "Original source";
         //				$flavorAssetWithParams->flavorParams = $flavorParams;
         //			}
         $flavorAssetWithParamsArray[] = $flavorAssetWithParams;
     }
     // copy the remaining params
     foreach ($flavorParamsArray as $flavorParamsId => $flavorParamsDb) {
         if (isset($usedFlavorParams[$flavorParamsId])) {
             // flavor params already exists for a flavor asset, not need
             // to list it one more time
             continue;
         }
         $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType());
         $flavorParams->fromObject($flavorParamsDb);
         $flavorAssetWithParams = new KalturaFlavorAssetWithParams();
         $flavorAssetWithParams->entryId = $entryId;
         $flavorAssetWithParams->flavorParams = $flavorParams;
         $flavorAssetWithParamsArray[] = $flavorAssetWithParams;
     }
     return $flavorAssetWithParamsArray;
 }
Пример #10
0
 /**
  * @param BatchJob $parentJob
  * @param int $flavorParamsId
  * @param string $puserId
  * @return int job id
  */
 public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null)
 {
     $job = null;
     if ($this->getType() == entryType::MIX) {
         // if flavor params == SOURCE, or no format defined for flavor params, default to 'flv'
         $flattenFormat = null;
         if ($flavorParamsId != 0) {
             $flattenFormat = flavorParamsPeer::retrieveByPK($flavorParamsId)->getFormat();
         }
         if (!$flattenFormat) {
             $flattenFormat = 'flv';
         }
         $job = myBatchFlattenClient::addJob($puserId, $this, $this->getVersion(), $flattenFormat);
     } else {
         $err = '';
         $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err);
     }
     if ($job) {
         return $job->getId();
     }
     return null;
 }
Пример #11
0
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
define('ROOT_DIR', realpath(dirname(__FILE__) . '/../../../'));
require_once ROOT_DIR . '/infra/bootstrap_base.php';
require_once ROOT_DIR . '/infra/KAutoloader.php';
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "document", "*"));
KAutoloader::setClassMapFilePath('../../cache/classMap.cache');
KAutoloader::register();
date_default_timezone_set(kConf::get("date_default_timezone"));
// America/New_York
KalturaLog::setLogger(new KalturaStdoutLogger());
DbManager::setConfig(kConf::getDB());
DbManager::initialize();
$flavorParams = null;
if ($flavorParamsId) {
    $flavorParams = flavorParamsPeer::retrieveByPK($flavorParamsId);
    if (!$flavorParams instanceof SwfFlavorParams) {
        echo "Flavor params id [{$flavorParamsId}] is not SWF flavor params\n";
        exit;
    }
    $flavorParams->setVersion($flavorParams->getVersion() + 1);
} else {
    $flavorParams = new SwfFlavorParams();
    $flavorParams->setVersion(1);
    $flavorParams->setFormat(flavorParams::CONTAINER_FORMAT_SWF);
}
$swfOperator = new kOperator();
$swfOperator->id = kConvertJobData::CONVERSION_ENGINE_PDF2SWF;
$pdfOperator = new kOperator();
$pdfOperator->id = kConvertJobData::CONVERSION_ENGINE_PDF_CREATOR;
$operators = new kOperatorSets();
 private function renderITunesFeed()
 {
     if (is_null($this->mimeType)) {
         $flavor = flavorParamsPeer::retrieveByPK($this->syndicationFeed->flavorParamId);
         if (!$flavor) {
             throw new Exception("flavor not found for id " . $this->syndicationFeed->flavorParamId);
         }
         switch ($flavor->getFormat()) {
             case 'mp4':
                 $this->mimeType = 'video/mp4';
                 break;
             case 'm4v':
                 $this->mimeType = 'video/x-m4v';
                 break;
             case 'mov':
                 $this->mimeType = 'video/quicktime';
                 break;
             default:
                 $this->mimeType = 'video/mp4';
         }
     }
     $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId);
     header("content-type: text/xml; charset=utf-8");
     '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
     $this->writeOpenXmlNode('rss', 0, array('xmlns:itunes' => "http://www.itunes.com/dtds/podcast-1.0.dtd", 'version' => "2.0"));
     $this->writeOpenXmlNode('channel', 1);
     $this->writeFullXmlNode('title', $this->stringToSafeXml($this->syndicationFeed->name), 2);
     $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 2);
     $this->writeFullXmlNode('language', $this->syndicationFeed->language, 2);
     $this->writeFullXmlNode('copyright', $partner->getName(), 2);
     $this->writeFullXmlNode('itunes:subtitle', $this->syndicationFeed->name, 2);
     $this->writeFullXmlNode('itunes:author', $this->syndicationFeed->feedAuthor, 2);
     $this->writeFullXmlNode('itunes:summary', $this->syndicationFeed->feedDescription, 2);
     $this->writeFullXmlNode('description', $this->syndicationFeed->feedDescription, 2);
     $this->writeOpenXmlNode('itunes:owner', 2);
     $this->writeFullXmlNode('itunes:name', $this->syndicationFeed->ownerName, 3);
     $this->writeFullXmlNode('itunes:email', $this->syndicationFeed->ownerEmail, 3);
     $this->writeClosingXmlNode('itunes:owner', 2);
     if ($this->syndicationFeed->feedImageUrl) {
         $this->writeOpenXmlNode('image', 2);
         $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 3);
         $this->writeFullXmlNode('url', $this->syndicationFeed->feedLandingPage, 3);
         $this->writeFullXmlNode('title', $this->syndicationFeed->name, 3);
         $this->writeClosingXmlNode('image', 2);
         $this->writeFullXmlNode('itunes:image', '', 2, array('href' => $this->syndicationFeed->feedImageUrl));
     }
     $categories = explode(',', $this->syndicationFeed->categories);
     $catTree = array();
     foreach ($categories as $category) {
         if (!$category) {
             continue;
         }
         if (strpos($category, '/')) {
             $category_parts = explode('/', $category);
             $catTree[$category_parts[0]][] = $category_parts[1];
         } else {
             $this->writeFullXmlNode('itunes:category', '', 2, array('text' => $category));
         }
     }
     foreach ($catTree as $topCat => $subCats) {
         if (!$topCat) {
             continue;
         }
         $this->writeOpenXmlNode('itunes:category', 2, array('text' => $topCat));
         foreach ($subCats as $cat) {
             if (!$cat) {
                 continue;
             }
             $this->writeFullXmlNode('itunes:category', '', 3, array('text' => $cat));
         }
         $this->writeClosingXmlNode('itunes:category', 2);
     }
     while ($entry = $this->getNextEntry()) {
         $e = new KalturaMediaEntry();
         $e->fromObject($entry);
         $url = $this->getFlavorAssetUrl($e);
         $this->writeOpenXmlNode('item', 2);
         $this->writeFullXmlNode('title', $this->stringToSafeXml($e->name), 3);
         $this->writeFullXmlNode('link', $this->syndicationFeed->landingPage . $e->id, 3);
         $this->writeFullXmlNode('guid', $url, 3);
         $this->writeFullXmlNode('pubDate', date('r', $e->createdAt), 3);
         $this->writeFullXmlNode('description', $this->stringToSafeXml($e->description), 3);
         $enclosure_attr = array('url' => $url, 'type' => $this->mimeType);
         $this->writeFullXmlNode('enclosure', '', 3, $enclosure_attr);
         $kuser = $entry->getkuser();
         if ($kuser && $kuser->getScreenName()) {
             $this->writeFullXmlNode('itunes:author', $this->stringToSafeXml($kuser->getScreenName()), 3);
         }
         if ($e->description) {
             $this->writeFullXmlNode('itunes:subtitle', $this->stringToSafeXml($e->description), 3);
             $this->writeFullXmlNode('itunes:summary', $this->stringToSafeXml($e->description), 3);
         }
         $this->writeFullXmlNode('itunes:duration', $this->secondsToWords($e->duration), 3);
         $this->writeFullXmlNode('itunes:explicit', $this->syndicationFeed->adultContent, 3);
         $this->writeFullXmlNode('itunes:image', '', 3, array('href' => $e->thumbnailUrl . '/width/600/height/600/ext.jpg'));
         if ($e->tags) {
             $this->writeFullXmlNode('itunes:keywords', $this->stringToSafeXml($e->tags), 3);
         }
         $this->writeClosingXmlNode('item', 2);
     }
     $this->writeClosingXmlNode('channel', 1);
     $this->writeClosingXmlNode('rss');
 }
Пример #13
0
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @param string $link
  * @param string $filterFlavors
  * @return SimpleXMLElement
  */
 public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, $link = null, $fitlerByFlovorParams = null)
 {
     if (!$mrss) {
         $mrss = new SimpleXMLElement('<item/>');
     }
     $mrss->addChild('entryId', $entry->getId());
     $mrss->addChild('createdAt', $entry->getCreatedAt(null));
     $mrss->addChild('title', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('link', $link . $entry->getId());
     $mrss->addChild('type', $entry->getType());
     $mrss->addChild('licenseType', $entry->getLicenseType());
     $mrss->addChild('userId', $entry->getPuserId(true));
     $mrss->addChild('name', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('description', self::stringToSafeXml($entry->getDescription()));
     $thumbnailUrl = $mrss->addChild('thumbnailUrl');
     $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl());
     $tags = $mrss->addChild('tags');
     foreach (explode(',', $entry->getTags()) as $tag) {
         $tags->addChild('tag', self::stringToSafeXml($tag));
     }
     $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData()));
     $mrss->addChild('accessControlId', $entry->getAccessControlId());
     $categories = explode(',', $entry->getCategories());
     foreach ($categories as $category) {
         if ($category) {
             $mrss->addChild('category', self::stringToSafeXml($category));
         }
     }
     if ($entry->getStartDate(null)) {
         $mrss->addChild('startDate', $entry->getStartDate(null));
     }
     if ($entry->getEndDate(null)) {
         $mrss->addChild('endDate', $entry->getEndDate(null));
     }
     switch ($entry->getType()) {
         case entryType::MEDIA_CLIP:
             self::appendMediaEntryMrss($entry, $mrss);
             break;
         case entryType::MIX:
             self::appendMixEntryMrss($entry, $mrss);
             break;
         case entryType::PLAYLIST:
             self::appendPlaylistEntryMrss($entry, $mrss);
             break;
         case entryType::DATA:
             self::appendDataEntryMrss($entry, $mrss);
             break;
         case entryType::LIVE_STREAM:
             self::appendLiveStreamEntryMrss($entry, $mrss);
             break;
         default:
             break;
     }
     $flavorAssets = flavorAssetPeer::retreiveReadyByEntryId($entry->getId());
     foreach ($flavorAssets as $flavorAsset) {
         if (!is_null($fitlerByFlovorParams) && $flavorAsset->getFlavorParamsId() != $fitlerByFlovorParams) {
             continue;
         }
         $content = $mrss->addChild('content');
         $content->addAttribute('url', self::getAssetUrl($flavorAsset));
         $content->addAttribute('flavorAssetId', $flavorAsset->getId());
         $content->addAttribute('isSource', $flavorAsset->getIsOriginal() ? 'true' : 'false');
         $content->addAttribute('containerFormat', $flavorAsset->getContainerFormat());
         $content->addAttribute('extension', $flavorAsset->getFileExt());
         if (!is_null($flavorAsset->getFlavorParamsId())) {
             $content->addAttribute('flavorParamsId', $flavorAsset->getFlavorParamsId());
             $flavorParams = flavorParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
             if ($flavorParams) {
                 $content->addAttribute('flavorParamsName', $flavorParams->getName());
                 $content->addAttribute('format', $flavorParams->getFormat());
                 $content->addAttribute('videoBitrate', $flavorParams->getVideoBitrate());
                 $content->addAttribute('videoCodec', $flavorParams->getVideoCodec());
                 $content->addAttribute('audioBitrate', $flavorParams->getAudioBitrate());
                 $content->addAttribute('audioCodec', $flavorParams->getAudioCodec());
                 $content->addAttribute('frameRate', $flavorParams->getFrameRate());
                 $content->addAttribute('height', $flavorParams->getHeight());
                 $content->addAttribute('width', $flavorParams->getWidth());
             }
         }
         $tags = $content->addChild('tags');
         foreach (explode(',', $flavorAsset->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $thumbAssets = thumbAssetPeer::retreiveReadyByEntryId($entry->getId());
     foreach ($thumbAssets as $thumbAsset) {
         $thumbnail = $mrss->addChild('thumbnail');
         $thumbnail->addAttribute('url', self::getAssetUrl($thumbAsset));
         $thumbnail->addAttribute('thumbAssetId', $thumbAsset->getId());
         $thumbnail->addAttribute('isDefault', $thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB) ? 'true' : 'false');
         $thumbnail->addAttribute('format', $thumbAsset->getContainerFormat());
         if ($thumbAsset->getFlavorParamsId()) {
             $thumbnail->addAttribute('thumbParamsId', $thumbAsset->getFlavorParamsId());
         }
         $tags = $thumbnail->addChild('tags');
         foreach (explode(',', $thumbAsset->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $mrssContributors = self::getMrssContributors();
     if (count($mrssContributors)) {
         foreach ($mrssContributors as $mrssContributor) {
             $mrssContributor->contribute($entry, $mrss);
         }
     }
     return $mrss;
 }
Пример #14
0
 public function execute()
 {
     $this->forceSystemAuthentication();
     $this->pid = $this->getRequestParameter("pid", 0);
     if (!is_null($this->getRequestParameter("advanced"))) {
         $this->getResponse()->setCookie('flavor-params-advanced', $this->getRequestParameter("advanced"));
         $this->advanced = (int) $this->getRequestParameter("advanced");
     } else {
         $this->advanced = (int) $this->getRequest()->getCookie('flavor-params-advanced');
     }
     myDbHelper::$use_alternative_con = null;
     $this->editFlavorParam = null;
     if ($this->getRequestParameter("id")) {
         $this->editFlavorParam = flavorParamsPeer::retrieveByPK($this->getRequestParameter("id"));
         if ($this->getRequestParameter("clone")) {
             $newFalvorParams = $this->editFlavorParam->copy();
             $newFalvorParams->setIsDefault(false);
             $newFalvorParams->setPartnerId(-1);
             $newFalvorParams->save();
             $this->redirect("system/flavorParams?pid=" . $this->pid . "&id=" . $newFalvorParams->getId());
         }
         if ($this->getRequestParameter("delete")) {
             if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
                 $this->editFlavorParam->setDeletedAt(time());
                 $this->editFlavorParam->save();
             }
             $this->redirect("system/flavorParams?pid=" . $this->pid);
         }
         if ($this->getRequest()->getMethod() == sfRequest::POST) {
             if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
                 $partnerId = $this->getRequestParameter("partner-id");
                 if ($this->advanced) {
                     $this->editFlavorParam->setPartnerId($partnerId);
                 } else {
                     if ($partnerId != 0) {
                         $this->editFlavorParam->setPartnerId($partnerId);
                     }
                 }
                 if ($this->advanced >= 1) {
                     $this->editFlavorParam->setName($this->getRequestParameter("name"));
                     $this->editFlavorParam->setDescription($this->getRequestParameter("description"));
                     $this->editFlavorParam->setIsDefault($this->getRequestParameter("is-default", false));
                     $this->editFlavorParam->setReadyBehavior($this->getRequestParameter("ready-behavior"));
                     $this->editFlavorParam->setTags($this->getRequestParameter("tags"));
                     $this->editFlavorParam->setFormat($this->getRequestParameter("format"));
                     $this->editFlavorParam->setTwoPass($this->getRequestParameter("two-pass", false));
                     $this->editFlavorParam->setWidth($this->getRequestParameter("width"));
                     $this->editFlavorParam->setHeight($this->getRequestParameter("height"));
                     $this->editFlavorParam->setVideoCodec($this->getRequestParameter("video-codec"));
                     $this->editFlavorParam->setVideoBitrate($this->getRequestParameter("video-bitrate"));
                     $this->editFlavorParam->setFrameRate($this->getRequestParameter("frame-rate"));
                     $this->editFlavorParam->setGopSize($this->getRequestParameter("gop-size"));
                     $this->editFlavorParam->setAudioCodec($this->getRequestParameter("audio-codec"));
                     $this->editFlavorParam->setAudioBitrate($this->getRequestParameter("audio-bitrate"));
                     $this->editFlavorParam->setAudioChannels($this->getRequestParameter("audio-channels"));
                     $this->editFlavorParam->setAudioSampleRate($this->getRequestParameter("audio-sample-rate"));
                     $this->editFlavorParam->setAudioResolution($this->getRequestParameter("audio-resolution"));
                     $this->editFlavorParam->setConversionEngines($this->getRequestParameter("conversion-engines"));
                     $this->editFlavorParam->setConversionEnginesExtraParams($this->getRequestParameter("conversion-engines-extra-params"));
                     $this->editFlavorParam->setOperators($this->getRequestParameter("operators"));
                     $this->editFlavorParam->setEngineVersion($this->getRequestParameter("engine-version"));
                 }
                 $this->editFlavorParam->save();
             }
             $this->redirect("system/flavorParams?pid=" . $this->editFlavorParam->getPartnerId());
         }
     }
     $c = new Criteria();
     $c->add(flavorParamsPeer::PARTNER_ID, array(0, $this->pid), Criteria::IN);
     $this->flavorParams = flavorParamsPeer::doSelect($c);
     $this->formats = self::getEnumValues("flavorParams", "CONTAINER_FORMAT");
     $this->videoCodecs = self::getEnumValues("flavorParams", "VIDEO_CODEC");
     $this->audioCodecs = self::getEnumValues("flavorParams", "AUDIO_CODEC");
     $this->readyBehaviors = self::getEnumValues("flavorParamsConversionProfile", "READY_BEHAVIOR");
     $this->creationModes = self::getEnumValues("flavorParams", "CREATION_MODE");
 }
Пример #15
0
 /**
  * @param BatchJob $parentJob
  * @param int $srcParamsId
  */
 public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null)
 {
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     } catch (Exception $e) {
         KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
     }
     if (!$profile) {
         KalturaLog::notice("Profile not found for entry id [{$entryId}]");
         return;
     }
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         KalturaLog::notice("Entry id [{$entryId}] not found");
         return;
     }
     $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId());
     if (!count($assetParamsIds)) {
         KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]");
         return;
     }
     // the alternative is the source or the highest bitrate if source not defined
     $alternateFlavorParamsId = null;
     if (is_null($srcParamsId)) {
         $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds);
         foreach ($flavorParamsObjects as $flavorParams) {
             if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) {
                 $alternateFlavorParamsId = $flavorParams->getId();
             }
         }
         if (is_null($alternateFlavorParamsId)) {
             $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId);
             $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId();
         }
         if (is_null($alternateFlavorParamsId)) {
             KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]");
             return;
         }
     }
     // create list of created thumbnails
     $thumbAssetsList = array();
     $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId);
     if (count($thumbAssets)) {
         foreach ($thumbAssets as $thumbAsset) {
             if (!is_null($thumbAsset->getFlavorParamsId())) {
                 $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset;
             }
         }
     }
     $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds);
     foreach ($thumbParamsObjects as $thumbParams) {
         // check if this thumbnail already created
         if (isset($thumbAssetsList[$thumbParams->getId()])) {
             continue;
         }
         if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) {
             // alternative should be used
             $thumbParams->setSourceParamsId($alternateFlavorParamsId);
         } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) {
             // only thumbnails that uses srcParamsId should be generated for now
             continue;
         }
         kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob);
     }
 }
Пример #16
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Пример #17
0
 /**
  * Convert entry
  * 
  * @param string $entryId Media entry id
  * @param int $conversionProfileId
  * @param KalturaConversionAttributeArray $dynamicConversionAttributes
  * @return int job id
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND
  * @throws KalturaErrors::FLAVOR_PARAMS_NOT_FOUND
  */
 protected function convert($entryId, $conversionProfileId = null, KalturaConversionAttributeArray $dynamicConversionAttributes = null)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $srcFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (!$srcFlavorAsset) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     if (is_null($conversionProfileId) || $conversionProfileId <= 0) {
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
         if (!$conversionProfile) {
             throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
         }
         $conversionProfileId = $conversionProfile->getId();
     }
     $srcSyncKey = $srcFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     if (!$local) {
         // over come a bug in kFileSyncUtils which return an unready filesync as the filesync of a remote dc
         $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($srcSyncKey, 1 - kDataCenterMgr::getCurrentDcId());
         $fileSync = kFileSyncUtils::resolve($fileSync);
         kFile::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync));
     } else {
         if (!$fileSync) {
             throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
         }
     }
     // even if it null
     $entry->setConversionQuality($conversionProfileId);
     $entry->setConversionProfileId($conversionProfileId);
     $entry->save();
     if ($dynamicConversionAttributes) {
         $flavors = flavorParamsPeer::retrieveByProfile($conversionProfileId);
         if (!count($flavors)) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_NOT_FOUND);
         }
         $srcFlavorParamsId = null;
         $flavorParams = $entry->getDynamicFlavorAttributes();
         foreach ($flavors as $flavor) {
             if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
                 $srcFlavorParamsId = $flavor->getId();
             }
             $flavorParams[$flavor->getId()] = $flavor;
         }
         $dynamicAttributes = array();
         foreach ($dynamicConversionAttributes as $dynamicConversionAttribute) {
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 $dynamicConversionAttribute->flavorParamsId = $srcFlavorParamsId;
             }
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 continue;
             }
             $dynamicAttributes[$dynamicConversionAttribute->flavorParamsId][trim($dynamicConversionAttribute->name)] = trim($dynamicConversionAttribute->value);
         }
         if (count($dynamicAttributes)) {
             $entry->setDynamicFlavorAttributes($dynamicAttributes);
             $entry->save();
         }
     }
     $srcFilePath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey);
     $job = kJobsManager::addConvertProfileJob(null, $entry, $srcFlavorAsset->getId(), $srcFilePath);
     if (!$job) {
         return null;
     }
     return $job->getId();
 }
Пример #18
0
 /**
  * @param int $conversionProfileId
  * @param $con
  * @return array<flavorParamsOutput>
  */
 public static function retrieveByProfile($conversionProfileId, $con = null)
 {
     $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileId);
     $criteria = new Criteria();
     $criteria->add(flavorParamsPeer::ID, $flavorIds, Criteria::IN);
     return flavorParamsPeer::doSelect($criteria, $con);
 }
Пример #19
0
 /**
  * List Flavor Params by filter with paging support (By default - all system default params will be listed too)
  * 
  * @action list
  * @param KalturaFlavorParamsFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaFlavorParamsListResponse
  */
 public function listAction(KalturaFlavorParamsFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!$filter) {
         $filter = new KalturaFlavorParamsFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $flavorParamsFilter = new assetParamsFilter();
     $filter->toObject($flavorParamsFilter);
     $c = new Criteria();
     $flavorParamsFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $dbList = flavorParamsPeer::doSelect($c);
     $c->setLimit(null);
     $totalCount = flavorParamsPeer::doCount($c);
     $list = KalturaFlavorParamsArray::fromDbArray($dbList);
     $response = new KalturaFlavorParamsListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }