public function execute()
 {
     sfView::SUCCESS;
     /** check parameters and verify user is logged-in **/
     $this->partner_id = $this->getP("pid");
     $this->subp_id = $this->getP("subpid", (int) $this->partner_id * 100);
     $this->uid = $this->getP("uid");
     $this->ks = $this->getP("kmcks");
     if (!$this->ks) {
         // if kmcks from cookie doesn't exist, try ks from REQUEST
         $this->ks = $this->getP('ks');
     }
     $this->screen_name = $this->getP("screen_name");
     $this->email = $this->getP("email");
     /** if no KS found, redirect to login page **/
     if (!$this->ks) {
         $this->redirect("kmc/kmc");
         die;
     }
     $ksObj = kSessionUtils::crackKs($this->ks);
     /** END - check parameters and verify user is logged-in **/
     /** Get array of allowed partners for the current user **/
     $this->allowedPartners = array();
     $currentUser = kuserPeer::getKuserByPartnerAndUid($this->partner_id, $ksObj->user, true);
     if ($currentUser) {
         $partners = myPartnerUtils::getPartnersArray($currentUser->getAllowedPartnerIds());
         foreach ($partners as $partner) {
             $this->allowedPartners[] = array('id' => $partner->getId(), 'name' => $partner->getName());
         }
         $this->full_name = $currentUser->getFullName();
     }
     /** load partner from DB, and set templatePartnerId **/
     $this->partner = $partner = null;
     $this->templatePartnerId = self::SYSTEM_DEFAULT_PARTNER;
     $this->ignoreSeoLinks = false;
     $this->ignoreEntrySeoLinks = false;
     $this->useEmbedCodeProtocolHttps = false;
     $this->v2Flavors = false;
     if ($this->partner_id !== NULL) {
         $this->partner = $partner = PartnerPeer::retrieveByPK($this->partner_id);
         kmcUtils::redirectPartnerToCorrectKmc($partner, $this->ks, $this->uid, $this->screen_name, $this->email, self::CURRENT_KMC_VERSION);
         $this->templatePartnerId = $this->partner ? $this->partner->getTemplatePartnerId() : self::SYSTEM_DEFAULT_PARTNER;
         $this->ignoreSeoLinks = $this->partner->getIgnoreSeoLinks();
         $this->ignoreEntrySeoLinks = PermissionPeer::isValidForPartner(PermissionName::FEATURE_IGNORE_ENTRY_SEO_LINKS, $this->partner_id);
         $this->useEmbedCodeProtocolHttps = PermissionPeer::isValidForPartner(PermissionName::FEATURE_EMBED_CODE_DEFAULT_PROTOCOL_HTTPS, $this->partner_id);
         $this->v2Flavors = PermissionPeer::isValidForPartner(PermissionName::FEATURE_V2_FLAVORS, $this->partner_id);
     }
     /** END - load partner from DB, and set templatePartnerId **/
     /** set default flags **/
     $this->payingPartner = 'false';
     $this->kdp508_players = array();
     $this->first_login = false;
     /** END - set default flags **/
     /** set values for template **/
     $this->service_url = myPartnerUtils::getHost($this->partner_id);
     $this->host = $this->stripProtocol($this->service_url);
     $this->embed_host = $this->host;
     if (kConf::hasParam('cdn_api_host') && kConf::hasParam('www_host') && $this->host == kConf::get('cdn_api_host')) {
         $this->host = kConf::get('www_host');
     }
     $this->cdn_url = myPartnerUtils::getCdnHost($this->partner_id);
     $this->cdn_host = $this->stripProtocol($this->cdn_url);
     $this->rtmp_host = myPartnerUtils::getRtmpUrl($this->partner_id);
     $this->flash_dir = $this->cdn_url . myContentStorage::getFSFlashRootPath();
     // Decide if to hide akamai delivery type
     $this->hideAkamaiHDNetwork = $partner->getDisableAkamaiHDNetwork();
     /** set payingPartner flag **/
     if ($partner && $partner->getPartnerPackage() != PartnerPackages::PARTNER_PACKAGE_FREE) {
         $this->payingPartner = 'true';
     }
     /** END - set payingPartner flag **/
     /** get partner languae **/
     $this->language = null;
     if ($partner->getKMCLanguage()) {
         $this->language = $partner->getKMCLanguage();
     }
     /** END - get partner languae **/
     /** set first_login flag **/
     $this->first_login = $partner->getIsFirstLogin();
     if ($this->first_login === true) {
         $partner->setIsFirstLogin(false);
         $partner->save();
     }
     /** END - set first_login flag **/
     /** get logout url **/
     $this->logoutUrl = null;
     if ($partner->getLogoutUrl()) {
         $this->logoutUrl = $partner->getLogoutUrl();
     }
     /** END - get logout url**/
     /** partner-specific: change KDP version for partners working with auto-moderaion **/
     // set content kdp version according to partner id
     $moderated_partners = array(31079, 28575, 32774);
     $this->content_kdp_version = 'v2.7.0';
     if (in_array($this->partner_id, $moderated_partners)) {
         $this->content_kdp_version = 'v2.1.2.29057';
     }
     /** END - partner-specific: change KDP version for partners working with auto-moderaion **/
     $this->kmc_swf_version = kConf::get('kmc_version');
     /** uiconf listing work **/
     /** fill $this->confs with all uiconf objects for all modules **/
     $kmcGeneralUiConf = kmcUtils::getAllKMCUiconfs('kmc', $this->kmc_swf_version, self::SYSTEM_DEFAULT_PARTNER);
     $kmcGeneralTemplateUiConf = kmcUtils::getAllKMCUiconfs('kmc', $this->kmc_swf_version, $this->templatePartnerId);
     /** for each module, create separated lists of its uiconf, for each need **/
     /** kmc general uiconfs **/
     $this->kmc_general = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_kmcgeneral", false, $kmcGeneralUiConf);
     $this->kmc_permissions = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_kmcpermissions", false, $kmcGeneralUiConf);
     /** P&E players: **/
     //$this->content_uiconfs_previewembed = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_previewembed", true, $kmcGeneralUiConf);
     //$this->content_uiconfs_previewembed_list = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_previewembed_list", true, $kmcGeneralUiConf);
     $this->content_uiconfs_flavorpreview = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_flavorpreview", false, $kmcGeneralUiConf);
     /* KCW uiconfs */
     $this->content_uiconfs_upload_webcam = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_uploadWebCam", false, $kmcGeneralUiConf);
     $this->content_uiconfs_upload_import = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_uploadImport", false, $kmcGeneralUiConf);
     $this->content_uiconds_clipapp_kdp = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_kdpClipApp", false, $kmcGeneralUiConf);
     $this->content_uiconds_clipapp_kclip = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_kClipClipApp", false, $kmcGeneralUiConf);
     /** content KCW,KSE,KAE **/
     //$this->content_uiconfs_upload = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_upload", false, $kmcGeneralUiConf);
     //$this->simple_editor = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_simpleedit", false, $kmcGeneralUiConf);
     //$this->advanced_editor = kmcUtils::find_confs_by_usage_tag($kmcGeneralTemplateUiConf, "kmc_advanceedit", false, $kmcGeneralUiConf);
     /** END - uiconf listing work **/
     /** get templateXmlUrl for whitelabeled partners **/
     //$this->appstudio_templatesXmlUrl = $this->getAppStudioTemplatePath();
 }
 public function execute()
 {
     sfView::SUCCESS;
     /** check parameters and verify user is logged-in **/
     $this->partner_id = $this->getP("pid");
     $this->subp_id = $this->getP("subpid", (int) $this->partner_id * 100);
     $this->uid = $this->getP("uid");
     $this->ks = $this->getP("kmcks");
     if (!$this->ks) {
         // if kmcks from cookie doesn't exist, try ks from REQUEST
         $this->ks = $this->getP('ks');
     }
     $this->screen_name = $this->getP("screen_name");
     $this->email = $this->getP("email");
     /** if no KS found, redirect to login page **/
     if (!$this->ks) {
         $this->redirect("kmc/kmc");
         die;
     }
     /** END - check parameters and verify user is logged-in **/
     /** load partner from DB, and set templatePartnerId **/
     $this->partner = $partner = null;
     $this->templatePartnerId = self::SYSTEM_DEFAULT_PARTNER;
     if ($this->partner_id !== NULL) {
         $this->partner = $partner = PartnerPeer::retrieveByPK($this->partner_id);
         kmcUtils::redirectPartnerToCorrectKmc($partner, $this->ks, $this->uid, $this->screen_name, $this->email, self::CURRENT_KMC_VERSION);
         $this->templatePartnerId = $this->partner ? $this->partner->getTemplatePartnerId() : self::SYSTEM_DEFAULT_PARTNER;
     }
     /** END - load partner from DB, and set templatePartnerId **/
     /** set default flags **/
     $this->allow_reports = false;
     $this->payingPartner = 'false';
     $this->embed_code = "";
     $this->enable_live_streaming = 'false';
     $this->kmc_enable_custom_data = 'false';
     $this->kdp508_players = array();
     $this->first_login = false;
     $this->enable_vast = 'false';
     /** END - set default flags **/
     /** set values for template **/
     $this->service_url = myPartnerUtils::getHost($this->partner_id);
     $this->host = str_replace("http://", "", $this->service_url);
     $this->cdn_url = myPartnerUtils::getCdnHost($this->partner_id);
     $this->cdn_host = str_replace("http://", "", $this->cdn_url);
     $this->rtmp_host = myPartnerUtils::getRtmpUrl($this->partner_id);
     $this->flash_dir = $this->cdn_url . myContentStorage::getFSFlashRootPath();
     /** set embed_code value **/
     if ($this->partner_id !== null) {
         $widget = widgetPeer::retrieveByPK("_" . $this->partner_id);
         if ($widget) {
             $this->embed_code = $widget->getWidgetHtml("kaltura_player");
             $ui_conf = $widget->getuiConf();
         }
     }
     /** END - set embed_code value **/
     /** set payingPartner flag **/
     if ($partner && $partner->getPartnerPackage() != PartnerPackages::PARTNER_PACKAGE_FREE) {
         $this->payingPartner = 'true';
     }
     /** END - set payingPartner flag **/
     /** set enable_live_streaming flag **/
     if (kConf::get('kmc_content_enable_live_streaming') && $partner) {
         if ($partner->getLiveStreamEnabled()) {
             $this->enable_live_streaming = 'true';
         }
     }
     /** END - set enable_live_streaming flag **/
     /** set enable_live_streaming flag **/
     if ($partner && $partner->getEnableVast()) {
         $this->enable_vast = 'true';
     }
     /** END - set enable_live_streaming flag **/
     /** set kmc_enable_custom_data flag **/
     $defaultPlugins = kConf::get('default_plugins');
     if (is_array($defaultPlugins) && in_array('MetadataPlugin', $defaultPlugins) && $partner) {
         if ($partner->getPluginEnabled(MetadataPlugin::PLUGIN_NAME) && $partner->getKmcVersion() == self::CURRENT_KMC_VERSION) {
             $this->kmc_enable_custom_data = 'true';
         }
     }
     /** END - set kmc_enable_custom_data flag **/
     /** set allow_reports flag **/
     // 2009-08-27 is the date we added ON2 to KMC trial account
     // TODO - should be depracated
     if (strtotime($partner->getCreatedAt()) >= strtotime('2009-08-27') || $partner->getEnableAnalyticsTab()) {
         $this->allow_reports = true;
     }
     if ($partner->getEnableAnalyticsTab()) {
         $this->allow_reports = true;
     }
     // if the email is empty - it is an indication that the kaltura super user is logged in
     if (!$this->email) {
         $this->allow_reports = true;
     }
     /** END - set allow_reports flag **/
     /** set first_login and jw_license flags **/
     if ($partner) {
         $this->first_login = $partner->getIsFirstLogin();
         if ($this->first_login === true) {
             $partner->setIsFirstLogin(false);
             $partner->save();
         }
         $this->jw_license = $partner->getLicensedJWPlayer();
     }
     /** END - set first_login and jw_license flags **/
     /** partner-specific: change KDP version for partners working with auto-moderaion **/
     // set content kdp version according to partner id
     $moderated_partners = array(31079, 28575, 32774);
     $this->content_kdp_version = 'v2.7.0';
     if (in_array($this->partner_id, $moderated_partners)) {
         $this->content_kdp_version = 'v2.1.2.29057';
     }
     /** END - partner-specific: change KDP version for partners working with auto-moderaion **/
     /** applications versioning **/
     $this->kmc_content_version = kConf::get('kmc_content_version');
     $this->kmc_account_version = kConf::get('kmc_account_version');
     $this->kmc_appstudio_version = kConf::get('kmc_appstudio_version');
     $this->kmc_rna_version = kConf::get('kmc_rna_version');
     $this->kmc_dashboard_version = kConf::get('kmc_dashboard_version');
     /** END - applications versioning **/
     /** uiconf listing work **/
     /** fill $this->confs with all uiconf objects for all modules **/
     $contentSystemUiConfs = kmcUtils::getAllKMCUiconfs('content', $this->kmc_content_version, self::SYSTEM_DEFAULT_PARTNER);
     $contentTemplateUiConfs = kmcUtils::getAllKMCUiconfs('content', $this->kmc_content_version, $this->templatePartnerId);
     //$this->confs = kmcUtils::getAllKMCUiconfs('content',   $this->kmc_content_version, $this->templatePartnerId);
     $appstudioSystemUiConfs = kmcUtils::getAllKMCUiconfs('appstudio', $this->kmc_appstudio_version, self::SYSTEM_DEFAULT_PARTNER);
     $appstudioTemplateUiConfs = kmcUtils::getAllKMCUiconfs('appstudio', $this->kmc_appstudio_version, $this->templatePartnerId);
     //$this->confs = array_merge($this->confs, kmcUtils::getAllKMCUiconfs('appstudio', $this->kmc_appstudio_version, $this->templatePartnerId));
     $reportsSystemUiConfs = kmcUtils::getAllKMCUiconfs('reports', $this->kmc_rna_version, self::SYSTEM_DEFAULT_PARTNER);
     $reportsTemplateUiConfs = kmcUtils::getAllKMCUiconfs('reports', $this->kmc_rna_version, $this->templatePartnerId);
     //$this->confs = array_merge($this->confs, kmcUtils::getAllKMCUiconfs('reports',   $this->kmc_rna_version, $this->templatePartnerId));
     /** for each module, create separated lists of its uiconf, for each need **/
     /** content players: **/
     $this->content_uiconfs_previewembed = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_previewembed", true, $contentSystemUiConfs);
     $this->content_uiconfs_previewembed_list = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_previewembed_list", true, $contentSystemUiConfs);
     $this->content_uiconfs_moderation = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_moderation", false, $contentSystemUiConfs);
     $this->content_uiconfs_drilldown = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_drilldown", false, $contentSystemUiConfs);
     $this->content_uiconfs_flavorpreview = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_flavorpreview", false, $contentSystemUiConfs);
     $this->content_uiconfs_metadataview = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_metadataview", false, $contentSystemUiConfs);
     /** content KCW,KSE,KAE **/
     $this->content_uiconfs_upload = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_upload", false, $contentSystemUiConfs);
     $this->simple_editor = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_simpleedit", false, $contentSystemUiConfs);
     $this->advanced_editor = kmcUtils::find_confs_by_usage_tag($contentTemplateUiConfs, "content_advanceedit", false, $contentSystemUiConfs);
     /** appStudio templates uiconf **/
     $this->appstudio_uiconfs_templates = kmcUtils::find_confs_by_usage_tag($appstudioTemplateUiConfs, "appstudio_templates", false, $appstudioSystemUiConfs);
     /** reports drill-down player **/
     $this->reports_uiconfs_drilldown = kmcUtils::find_confs_by_usage_tag($reportsTemplateUiConfs, "reports_drilldown", false, $reportsSystemUiConfs);
     /** silverlight uiconfs **/
     $this->silverLightPlayerUiConfs = array();
     $this->silverLightPlaylistUiConfs = array();
     if ($partner->getKmcVersion() == self::CURRENT_KMC_VERSION && $partner->getEnableSilverLight()) {
         $this->silverLightPlayerUiConfs = kmcUtils::getSilverLightPlayerUiConfs('slp');
         $this->silverLightPlaylistUiConfs = kmcUtils::getSilverLightPlayerUiConfs('sll');
     }
     /** jw uiconfs **/
     $this->jw_uiconfs_array = kmcUtils::getJWPlayerUIConfs();
     $this->jw_uiconf_playlist = kmcUtils::getJWPlaylistUIConfs();
     /** 508 uicinfs **/
     if ($partner->getKmcVersion() == self::CURRENT_KMC_VERSION && $partner->getEnable508Players()) {
         $this->kdp508_players = kmcUtils::getKdp508PlayerUiconfs();
     }
     /** partner's preview&embed uiconfs **/
     $this->content_pne_partners_player = kmcUtils::getPartnersUiconfs($this->partner_id, 'player');
     $this->content_pne_partners_playlist = kmcUtils::getPartnersUiconfs($this->partner_id, 'playlist');
     /** appstudio: default entry and playlists **/
     $this->appStudioExampleEntry = $partner->getAppStudioExampleEntry();
     $appStudioExampleEntry = entryPeer::retrieveByPK($this->appStudioExampleEntry);
     if (!($appStudioExampleEntry && $appStudioExampleEntry->getDisplayInSearch() == mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK && $appStudioExampleEntry->getStatus() == entryStatus::READY && $appStudioExampleEntry->getType() == entryType::MEDIA_CLIP)) {
         $this->appStudioExampleEntry = "_KMCLOGO1";
     }
     $this->appStudioExamplePlayList0 = $partner->getAppStudioExamplePlayList0();
     $appStudioExamplePlayList0 = entryPeer::retrieveByPK($this->appStudioExamplePlayList0);
     if (!($appStudioExamplePlayList0 && $appStudioExamplePlayList0->getStatus() == entryStatus::READY && $appStudioExamplePlayList0->getType() == entryType::PLAYLIST)) {
         $this->appStudioExamplePlayList0 = "_KMCSPL1";
     }
     $this->appStudioExamplePlayList1 = $partner->getAppStudioExamplePlayList1();
     $appStudioExamplePlayList1 = entryPeer::retrieveByPK($this->appStudioExamplePlayList1);
     if (!($appStudioExamplePlayList1 && $appStudioExamplePlayList1->getStatus() == entryStatus::READY && $appStudioExamplePlayList1->getType() == entryType::PLAYLIST)) {
         $this->appStudioExamplePlayList1 = "_KMCSPL2";
     }
     /** END - appstudio: default entry and playlists **/
     /** END - uiconf listing work **/
     /** get templateXmlUrl for whitelabeled partners **/
     $this->appstudio_templatesXmlUrl = $this->getAppStudioTemplatePath();
 }
 private function serveRtmp()
 {
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             $duration = $this->entry->getDurationInt();
             $flavorAssets = array();
             if ($this->flavorId) {
                 $flavorAsset = flavorAssetPeer::retrieveById($this->flavorId);
                 if (!$flavorAsset->hasTag(flavorParams::TAG_WEB)) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 if (!$flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 $flavorAssets[] = $flavorAsset;
             } else {
                 $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_MBR);
                 if (!count($flavorAssets)) {
                     $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB);
                 }
             }
             $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets);
             if (!$this->storageId) {
                 $partner = $this->entry->getPartner();
                 $finalFlavors = array();
                 if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
                     foreach ($flavorAssets as $flavorAsset) {
                         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                         if ($fileSync) {
                             $finalFlavors[] = $flavorAsset;
                         }
                     }
                 }
                 if (!count($finalFlavors) && $partner->getStorageServePriority() && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
                     $storages = StorageProfilePeer::retrieveExternalByPartnerId($partner->getId());
                     if (count($storages) == 1) {
                         $this->storageId = $storages[0]->getId();
                     } elseif (count($storages)) {
                         $storagesFlavors = array();
                         foreach ($storages as $storage) {
                             $storagesFlavors[$storage->getId()] = array();
                             foreach ($flavorAssets as $flavorAsset) {
                                 $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                                 $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storage->getId());
                                 if ($fileSync) {
                                     $storagesFlavors[$storage->getId()][] = $flavorAsset;
                                 }
                             }
                         }
                         $maxCount = 0;
                         foreach ($storagesFlavors as $storageId => $storageFlavors) {
                             $count = count($storageFlavors);
                             if ($count > $maxCount) {
                                 $maxCount = $count;
                                 $this->storageId = $storageId;
                                 $finalFlavors = $storageFlavors;
                             }
                         }
                         $flavorAssets = $finalFlavors;
                     } else {
                         foreach ($flavorAssets as $flavorAsset) {
                             $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                             if ($fileSync) {
                                 $finalFlavors[] = $flavorAsset;
                             }
                         }
                     }
                 }
             }
             foreach ($flavorAssets as $flavorAsset) {
                 $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
                 if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                     $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                     $duration /= 1000;
                     break;
                 }
             }
             $baseUrl = null;
             $flavors = array();
             if ($this->storageId) {
                 $storage = StorageProfilePeer::retrieveByPK($this->storageId);
                 if (!$storage) {
                     die;
                 }
                 $baseUrl = $storage->getDeliveryRmpBaseUrl();
                 // get all flavors with external urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId);
                     if (!$fileSync) {
                         continue;
                     }
                     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc());
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFileSyncUrl($fileSync);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             } else {
                 $partnerId = $this->entry->getPartnerId();
                 $subpId = $this->entry->getSubpId();
                 $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
                 $baseUrl = myPartnerUtils::getRtmpUrl($partnerId);
                 $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost);
                 // get all flavors with kaltura urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFlavorAssetUrl($flavorAsset);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             }
             if (!count($flavors)) {
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, $flavors, 'video/x-flv', $duration, $baseUrl);
         case entryType::LIVE_STREAM:
             $streamId = $this->entry->getStreamRemoteId();
             $streamUsername = $this->entry->getStreamUsername();
             $baseUrl = $this->entry->getStreamUrl();
             $baseUrl = rtrim($baseUrl, '/');
             $flavors = $this->entry->getStreamBitrates();
             if (count($flavors)) {
                 foreach ($flavors as $index => $flavor) {
                     $brIndex = $index + 1;
                     $flavors[$index]['url'] = str_replace('%i', $brIndex, $this->entry->getStreamName());
                 }
             } else {
                 $flavors[0]['url'] = str_replace('%i', '1', $this->entry->getStreamName());
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_LIVE, $flavors, 'video/x-flv', null, $baseUrl);
     }
     KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
 }
 /**
  * @param int $duration
  * @param string $baseUrl
  * @return array
  */
 private function buildRtmpFlavorsArray(&$duration, &$baseUrl)
 {
     $flavorAssets = $this->buildRtmpFlavorAssetArray();
     $duration = $this->entry->getDurationInt();
     $flavorDuration = $this->getDurationFromFlavorAssets($flavorAssets);
     if ($flavorDuration) {
         $duration = $flavorDuration;
     }
     $flavors = array();
     if ($this->storageId) {
         $storage = StorageProfilePeer::retrieveByPK($this->storageId);
         if (!$storage) {
             die;
         }
         $baseUrl = $storage->getDeliveryRmpBaseUrl();
         $urlManager = $this->getUrlManagerByStorageProfile($this->storageId);
         // get all flavors with external urls
         foreach ($flavorAssets as $flavorAsset) {
             $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId);
             if (!$fileSync) {
                 continue;
             }
             $this->setupUrlManager($urlManager, $fileSync, $flavorAsset);
             $url = $urlManager->getFileSyncUrl($fileSync, false);
             $url = ltrim($url, "/");
             $flavors[] = $this->getFlavorAssetInfo($url, '', $flavorAsset);
         }
     }
     $partner = $this->entry->getPartner();
     if (!$this->storageId || !count($flavors) && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) {
         $partnerId = $this->entry->getPartnerId();
         $subpId = $this->entry->getSubpId();
         $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
         $baseUrl = myPartnerUtils::getRtmpUrl($partnerId);
         // allow to replace {deliveryCode} place holder with the deliveryCode parameter passed to the action
         // a publisher with a rtmpUrl set to {deliveryCode}.example.com/ondemand will be able to use different
         // cdn configuration for different sub publishers by passing a different deliveryCode to the KDP
         if ($this->deliveryCode) {
             $baseUrl = str_replace("{deliveryCode}", $this->deliveryCode, $baseUrl);
         }
         $rtmpHost = parse_url($baseUrl, PHP_URL_HOST);
         $urlManager = $this->getUrlManagerByCdn($rtmpHost);
         // get all flavors with kaltura urls
         foreach ($flavorAssets as $flavorAsset) {
             /* @var $flavorAsset flavorAsset */
             $this->setupUrlManager($urlManager, null, $flavorAsset);
             $url = $urlManager->getAssetUrl($flavorAsset, false);
             $url = ltrim($url, "/");
             $flavors[] = $this->getFlavorAssetInfo($url, '', $flavorAsset);
         }
     }
     if (strpos($this->protocol, "rtmp") === 0) {
         $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
     }
     $urlManager->finalizeUrls($baseUrl, $flavors);
     $this->tokenizer = $urlManager->getTokenizer();
     return $flavors;
 }