private function getMediaInfoForPrefix($prefix) { $media_id = $this->getP($prefix . "_id"); if (!$media_id) { return false; } $mediaType = $this->getPM($prefix . "_type", entry::ENTRY_MEDIA_TYPE_VIDEO); $mediaSource = $this->getPM($prefix . "_source"); // echo "[$prefix]: $media_id, $mediaType, $mediaSource<br>"; // TODO - get this if we need t for flickr $kuserId = null; $media_source_provider = myMediaSourceFactory::getMediaSource($mediaSource); // echo ( "$media_source\n" ); if ($media_source_provider) { $res = $media_source_provider->getMediaInfo($mediaType, $media_id); if ($res !== null) { $this->addMsg($prefix, $res); // lets check if there were errors so we could add an error message if (@$res["status"] == "error") { if (strpos(@$res["message"], "Adult content") !== false) { $this->addError(APIErrors::ADULT_CONTENT); } else { $this->addError(APIErrors::CANNOT_IMPORT_ONE_OR_MORE_MEDIA_FILES); } } } else { $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_TYPE, $mediaType); } } else { $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_SOURCE, $media_source); } return true; }
/** the puser might not be a kuser in the system */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { self::$escape_text = true; $mediaType = $this->getPM('media_type', entry::ENTRY_MEDIA_TYPE_VIDEO); $mediaSource = $this->getPM('media_source'); $searchText = $this->getP('search'); $page = $this->getP('page', 1); $pageSize = $this->getP('page_size', 10); $authData = $this->getP('auth_data'); $extraData = $this->getP('extra_data'); // for media_commons - dont' escape the XML. // The Urls will be damaged // TODO - think of a good way to avoid this issue if ($mediaSource == entry::ENTRY_MEDIA_SOURCE_MEDIA_COMMONS) { self::$escape_text = false; } // TODO - get this if we need t for flickr $kuserId = null; $media_source_provider = myMediaSourceFactory::getMediaSource($mediaSource); // echo ( "$media_source\n" ); if ($media_source_provider) { $media_source_provider->setUserDetails($partner_id, $subp_id, $puser_id); //$res = call_user_func ( array ( $media_source , "searchMedia" ) , array ( $media_type , $searchText, $page, $pageSize, $kuserId ) ) ; // magic word - '$partner_id' to replace the parameter dynamically $extraData = str_replace('$partner_id', $partner_id, $extraData); $res = $media_source_provider->searchMedia($mediaType, $searchText, $page, $pageSize, $authData, $extraData); if ($res) { $this->addMsg("search", $res); } else { $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_TYPE, $mediaType); } } else { $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_SOURCE, $media_source); } }
/** the puser might not be a kuser in the system */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { self::$escape_text = true; $mediaSource = $this->getP('media_source'); $username = $this->getP('username'); $password = $this->getP('password'); // TODO - get this if we need t for flickr $kuserId = null; $media_source_provider = myMediaSourceFactory::getMediaSource($mediaSource); // echo ( "$media_source\n" ); if ($media_source_provider) { //$res = call_user_func ( array ( $media_source , "searchMedia" ) , array ( $media_type , $searchText, $page, $pageSize, $kuserId ) ) ; $res = $media_source_provider->getAuthData($kuserId, $username, $password, ""); //$this->ks->toSecureString()); $this->addMsg("authdata", $res); } else { $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_SOURCE, $media_source); } }
/** the puser might not be a kuser in the system */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { // set this boolean so the text will be escaped n the XML result self::$escape_text = true; $url = $this->getPM('url'); $mediaType = $this->getPM('media_type'); /* $searchText = $this->getP ( 'search' ); $page = $this->getP ( 'page' , 1 ); $pageSize = $this->getP ( 'page_size' , 10 ); $authData = $this->getP ( 'auth_data' ); */ list($media_source_provider, $obj_id) = myMediaSourceFactory::getMediaSourceAndObjectDataByUrl($mediaType, $url); // echo ( "$media_source\n" ); if ($media_source_provider) { //$res = call_user_func ( array ( $media_source , "searchMedia" ) , array ( $media_type , $searchText, $page, $pageSize, $kuserId ) ) ; $res = $media_source_provider->getMediaInfo($mediaType, $obj_id); $this->addMsg("search", $res); } else { //$this->addError( -301 , "unknown media source for url $url" ); $this->addError(APIErrors::SEARCH_UNSUPPORTED_MEDIA_SOURCE_FOR_URL, $url); } }
private static function parseVideos($url, $page, $pageSize) { $videos = array(); $status = 'ok'; $message = ''; $cache = array(); $media_source = myMediaSourceFactory::getMediaSource(entry::ENTRY_MEDIA_SOURCE_YOUTUBE); $offset = ($page - 1) * $pageSize; $objects = array(); $content = kFile::downloadUrlToString($url, 1); if (preg_match_all("/http:\\/\\/www.youtube.com\\/v\\/([a-zA-Z0-9_\\-]*)/msi", $content, $vidUrls)) { foreach ($vidUrls[1] as $vidUrl) { if (in_array($vidUrl, $cache)) { continue; } $cache[] = $vidUrl; $result = $media_source->getMediaInfo(entry::ENTRY_MEDIA_TYPE_VIDEO, $vidUrl); if (!$result) { continue; } if ($offset) { $offset--; continue; } $objects[] = $result['objectInfo']; if (count($objects) == $pageSize) { break; } } } /* else if (preg_match_all("/http:\/\/v.wordpress.com\/([a-zA-Z0-9_\-]*)/msi", $content, $vidUrls)) { foreach($vidUrls[1] as $vidUrl) { if (in_array($vidUrl, $cache)) continue; $cache[] = $vidUrl; $url = "http://v.wordpress.com/videofile/".$vidUrl."/flv"; $objectInfo = array('id' => $vidUrl, 'url' => $url, 'title' => '', 'thumb' => '', 'tags' => '', 'license' => '', 'credit' => ''); $result = $media_source->getMediaInfo( entry::ENTRY_MEDIA_TYPE_VIDEO, $vidUrl); if (!$result) continue; if ($offset) { $offset--; continue; } $objects[] = $objectInfo; if (count($objects) == $pageSize) break; } } */ return array('status' => $status, 'message' => $message, 'objects' => $objects); }
public static function getMediaServiceProviders($partner_id, $subp_id) { $provider_id_list = myMediaSourceFactory::getAllMediaSourceProvidersIds(); $result = array(); foreach ($provider_id_list as $provider_id) { $provider = myMediaSourceFactory::getMediaSource($provider_id); $res = $provider->getSearchConfig(); $result["__{$provider_id}" . "_service"] = $res; } return $result; }
/** * * @action externalLogin * @param KalturaSearchProviderType $searchSource * @param string $userName * @param string $password * @return KalturaSearchAuthData */ public function externalLoginAction($searchSource, $userName, $password) { $mediaSourceProvider = myMediaSourceFactory::getMediaSource($searchSource); if (!$mediaSourceProvider) { throw new KalturaAPIException(KalturaErrors::SEARCH_UNSUPPORTED_MEDIA_SOURCE, $searchSource); } $resultArray = $mediaSourceProvider->getAuthData($this->getKuser()->getId(), $userName, $password, ""); $result = new KalturaSearchAuthData(); $result->fromArray($resultArray); return $result; }
/** Will allow creation of multiple entries ASSUME - the prefix of the entries is entryX_ where X is the index starting at 1 */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { // $logger = sfLogger::getInstance(); self::$escape_text = true; /* if ( !$puser_kuser ) { $this->addError( "No such user ..." ); return; } */ // TODO - validate if the user can add entries to this kshow $kshow_id = $this->getP("kshow_id"); $show_entry_id = $this->getP("show_entry_id"); $conversion_quality = $this->getP("conversionquality"); // must be all lower case // for now - by default use quick_edit $partner = PartnerPeer::retrieveByPK($partner_id); for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $source = $this->getP($prefix . "source"); $filename = $this->getP($prefix . "filename"); if ($source != entry::ENTRY_MEDIA_SOURCE_WEBCAM || !$filename) { continue; } $content = myContentStorage::getFSContentRootPath(); $entryFullPath = "{$content}/content/webcam/{$filename}.flv"; if (!file_exists($entryFullPath)) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } $this->addError(APIErrors::INVALID_FILE_NAME, $filename); return; } } if (strpos($kshow_id, 'entry-') !== false && !$show_entry_id) { $show_entry_id = substr($kshow_id, 6); } $screen_name = $this->getP("screen_name"); $site_url = $this->getP("site_url"); $null_kshow = true; if ($show_entry_id) { // in this case we have the show_entry_id (of the relevant roughcut) - it suppresses the kshow_id $show_entry = entryPeer::retrieveByPK($show_entry_id); if ($show_entry) { $kshow_id = $show_entry->getKshowId(); } else { $kshow_id = null; } } if ($kshow_id === kshow::SANDBOX_ID) { $this->addError(APIErrors::SANDBOX_ALERT); return; } $default_kshow_name = $this->getP("entry_name", null); if (!$default_kshow_name) { $default_kshow_name = $this->getP("entry1_name", null); } if ($kshow_id == kshow::KSHOW_ID_USE_DEFAULT) { // see if the partner has some default kshow to add to $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, false, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } elseif ($kshow_id == kshow::KSHOW_ID_CREATE_NEW) { // if the partner allows - create a new kshow $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, true, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } else { $kshow = kshowPeer::retrieveByPK($kshow_id); } if (!$kshow) { // the partner is attempting to add an entry to some invalid or non-existing kwho $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } // find permissions from kshow $permissions = $kshow->getPermissions(); $kuser_id = $puser_kuser->getKuserId(); // TODO - once the CW $quick_edit = myPolicyMgr::getPolicyFor("allowQuickEdit", $kshow, $partner); // let the user override the quick_edit propery if ($this->getP("quick_edit") == '0' || $this->getP("quick_edit") == "false") { $quick_edit = false; } if ($quick_edit == '0' || $quick_edit === "false" || !$quick_edit || $quick_edit == false) { KalturaLog::err('$quick_edit: [' . $quick_edit . ']'); $quick_edit = false; //$quick_edit = true; } // works in one of 2 ways: // 1. get no requested name - will create a new kshow and return its details // 2. get some name - tries to fetch by name. if already exists - return it $new_entry_count = 0; $entries = array(); $notification_ids = array(); $notifications = array(); $field_level = $this->isAdmin() ? 2 : 1; $updateable_fields = null; $imported_entries_count = 0; for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $file_name = $this->getP($prefix . "realFilename"); if (!($this->getP($prefix . "name") || $file_name)) { continue; } // get the new properties for the kuser from the request $entry = new entry(); $obj_wrapper = objectWrapperBase::getWrapperClass($entry, 0); if (!$updateable_fields) { $updateable_fields = $obj_wrapper->getUpdateableFields($field_level); } // fill the entry from request $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $entry, $prefix, $updateable_fields); // check that mandatory fields were set // TODO KalturaLog::err("addentry: fields_modified: " . print_r($fields_modified, true)); $entry_source = $entry->getSource(); if (!$entry->getType()) { // this is the default for backward compatiblity $entry->setType(entryType::MEDIA_CLIP); } $token = $this->getKsUniqueString(); $entry_full_path = ""; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $entry->setSourceLink($file_name); $file_alias = $this->getP($prefix . "filename"); $file_extension = strtolower(pathinfo($this->getP($prefix . "realFilename"), PATHINFO_EXTENSION)); $entry_full_path = myUploadUtils::getUploadPath($token, $file_alias, null, $file_extension); if (!file_exists($entry_full_path)) { KalturaLog::err("Invalid UPLOAD PATH [" . $entry_full_path . "] while trying to add entry for partner id [" . $partner_id . "] with token [" . $token . "] & original name [" . $this->getP($prefix . "name") . "]"); $this->addError(APIErrors::INVALID_FILE_NAME); continue; } myEntryUtils::setEntryTypeAndMediaTypeFromFile($entry, $entry_full_path); } // No reason to rais the error // Remarked by Tan-Tan // // // when we reached this point the type and media type must be set // if ($entry->getType() == entryType::AUTOMATIC || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUTOMATIC) // { // $this->addError ( APIErrors::CANNOT_USE_ENTRY_TYPE_AUTO_IN_IMPORT ); // continue; // } // limit two kinds of media // 1. not images - video/audio which are big files // 2. media which wasnt directly uploaded by the owner (the owner real content) if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE && $entry_source != entry::ENTRY_MEDIA_SOURCE_FILE) { if ($imported_entries_count >= 4) { continue; } ++$imported_entries_count; } // the conversion_quality is set once for the whole list of entries if ($conversion_quality) { $entry->setConversionQuality($conversion_quality); } else { // HACK - if the conversion_quality was not set in the proper way - // see if the partner_data holds a hack - string that starts with conversionQuality= - this is set when the CW is opened in the KMC // the conversionQuality is of format conversionQuality=XXX;<the rest of the text> // if (kString::beginsWith($entry->getPartnerData(), "conversionQuality:")) { $partner_data_arr = explode(";", $entry->getPartnerData(), 2); $conversion_quality_arr = explode(":", $partner_data_arr[0]); $conversion_quality = @$conversion_quality_arr[1]; // the value of the conversion_quality $entry->setPartnerData(@$partner_data_arr[1]); // the rest of the string $entry->setConversionQuality($conversion_quality); } } $insert = true; $entry_modified = false; $create_entry = true; // I don't remember why we set the kshow to null every time ... // but when we fetched it automatically - hang on to it ! if ($null_kshow) { $kshow = null; } if ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS || $entry_source == "100") { if ($entry_source == "100") { $entry_id = $this->getP("media{$i}_id"); } else { $entry_id = $this->getP($prefix . "id"); } // $this->getP ( $prefix . "url" ); if ($entry_id === null) { $entry_id = $entry->getMediaId(); } if ($entry_id) { $entry = entryPeer::retrieveByPK($entry_id); if ($entry) { $create_entry = false; $insert = false; } else { $this->addError(APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix(), $entry_id); return; } } } $new_entry_count++; if ($create_entry) { $entry->setPartnerId($partner_id); $entry->setSubpId($subp_id); $entry->setKuserId($kuser_id); $entry->setCreatorKuserId($kuser_id); $entry->setKshowId($kshow_id); $entry->setSiteUrl($site_url); $entry->setScreenName($screen_name); if ($this->getGroup()) { $entry->setGroupId($this->getGroup()); } if ($entry->getPermissions() === null) { $entry->setPermissions($permissions); } // inherited from the enclosing kshow $entry->setDefaultModerationStatus(); $entry->save(); $entry_modified = true; if (!$entry->getName()) { if ($file_name) { // TODO - fix the file_name to fit $entry->setName($file_name); } else { $entry->setName($partner_prefix . $entry->getId()); } $entry_modified = true; } // TODO - decide on file naming mechanism !! // there are 3 types of insert: // 1. upload - the file is assumed to be in the upload directory and it's name is explicitly set in the fname$i param // 2. webcam - the file is assumed to be in the webcam directory and it's name is explicitly set in the fname$i param // 3. URL - the url is given in the entry_url$i param /* $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', ''); $entry_from_time = $this->getParam('entry_from_time', 0); $entry_to_time = $this->getParam('entry_to_time', 0); $should_copy = $this->getParam('should_copy' , false ); $skip_conversion = $this->getParam('skip_conversion' , false ); */ $paramsArray = array('entry_media_source' => $entry->getSource(), 'entry_media_type' => $entry->getMediaType()); // $entry_source = $entry->getSource() ; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $paramsArray["entry_full_path"] = $entry_full_path; } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $file_alias = $this->getP($prefix . "filename"); $paramsArray["webcam_suffix"] = $file_alias; $paramsArray['entry_from_time'] = $this->getP($prefix . "fromTime", 0); $paramsArray['entry_to_time'] = $this->getP($prefix . "toTime", 0); } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS) { // optimize - no need to actually go through the import and conversion phase // find the source entry_id from the url /* $entry_url = $this->getP ( $prefix . "url" ); $entry_thumb_url = $this->getP ( $prefix . "thumbUrl" ); if ( myEntryUtils::copyData( $entry_url , $entry_thumb_url , $entry ) ) */ $source_entry_id = $this->getP("media{$i}_id"); // $this->getP ( $prefix . "url" ); if ($source_entry_id === null) { $source_entry_id = $entry->getMediaId(); } if (myEntryUtils::copyData($source_entry_id, $entry)) { // copy worked ok - no need to use insertEntryHelper //$entry->setStatus ( entryStatus::READY ); // force the data to be ready even if the policy is to moderate - this is kaltura's content and was already approved // (roman) true argument removed, so kaltura's content will be moderated according to partner's moderation settings $entry->setStatusReady(); $insert = false; $entry_modified = true; $entry->save(); } } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_URL || in_array($entry_source, myMediaSourceFactory::getAllMediaSourceProvidersIds())) { // the URL is relevant $paramsArray["entry_url"] = $this->getP($prefix . "url"); $paramsArray["entry_thumb_url"] = $this->getP($prefix . "thumbUrl"); // TODO - these fields are already set in the entry - // the code in myInsertEntryHelper is redundant $paramsArray["entry_license"] = $entry->getLicenseType(); $paramsArray["entry_credit"] = $entry->getCredit(); $paramsArray["entry_source_link"] = $entry->getSourceLink(); $paramsArray["entry_tags"] = $entry->getTags(); } else { $this->addError(APIErrors::UNKNOWN_MEDIA_SOURCE, $entry->getSource()); $insert = false; } if ($insert) { KalturaLog::err("paramsArray" . print_r($paramsArray, true)); $insert_entry_helper = new myInsertEntryHelper($this, $kuser_id, $kshow_id, $paramsArray); $insert_entry_helper->setPartnerId($partner_id, $subp_id); $insert_entry_helper->insertEntry($token, $entry->getType(), $entry->getId(), $entry->getName(), $entry->getTags(), $entry); $insert_entry_helper->getEntry(); $this->addDebug("added_entry{$i}", $entry->getName()); } } // create_entry = true KalturaLog::err('id: ' . $entry->getId() . ' $quick_edit:' . $quick_edit); if ($quick_edit) { KalturaLog::info("quick edit with kshow_id [{$kshow_id}]"); if (!$kshow) { $kshow = kshowPeer::retrieveByPK($kshow_id); } // this i if (!$kshow) { // BAD - this shount not be ! $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } $metadata = $kshow->getMetadata(); if ($metadata !== null) { KalturaLog::info("Having metadata"); $relevant_kshow_version = 1 + $kshow->getVersion(); // the next metadata will be the first relevant version for this new entry $version_info = array(); $version_info["KuserId"] = $puser_kuser->getKuserId(); $version_info["PuserId"] = $puser_id; $version_info["ScreenName"] = $puser_kuser->getPuserName(); $new_metadata = myMetadataUtils::addEntryToMetadata($metadata, $entry, $relevant_kshow_version, $version_info); $entry_modified = true; if ($new_metadata) { // TODO - add thumbnail only for entries that are worthy - check they are not moderated ! $thumb_modified = myKshowUtils::updateThumbnail($kshow, $entry, false); if ($thumb_modified) { $new_metadata = myMetadataUtils::updateThumbUrlFromMetadata($new_metadata, $entry->getThumbnailUrl()); } // it is very important to increment the version count because even if the entry is deferred // it will be added on the next version if (!$kshow->getHasRoughcut()) { // make sure the kshow now does have a roughcut $kshow->setHasRoughcut(true); $kshow->save(); } $kshow->setMetadata($new_metadata, true); } // no need to save kshow - the modification of the metadata was done to the show_entry which will propagate any chages to the kshow in it's own save method } } if ($entry_modified) { $entry->save(); } $not_id = null; // send a synch notification @(list($not_id, $not, $url, $params, $serialized_params) = myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $entry, null, null)); if ($not_id) { $notification_ids[] = $not_id; $notifications[] = array("url" => $url, "params" => $serialized_params); } $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR); $entries[$prefix] = $wrapper; //$this->addMsg ( $prefix , $wrapper); // because the kshow's entrys field was changes do to this update, we have to remove object from cahce // TODO - think of some reverse way to automatically remove from the cache from within the wrapper // call some - update cache where the kshow_id plays a part in the update $wrapper->removeFromCache("kshow", $kshow_id, "entrys"); $this->addDebug("added_fields", $fields_modified, $prefix); } $this->addMsg("entries", $entries); if (count($notification_ids) > 0) { $this->addMsg("notifications", $notifications); } if ($new_entry_count < 1) { $this->addError(APIErrors::NO_ENTRIES_ADDED); $this->addDebug("no_new_entries", "You have to have at least one new entry with a field called 'entry1_name'"); } $this->addMsg("new_entry_count", $new_entry_count); }