public function uploadVideo($fileDisk, $fileUrl, $props, $private = false) { // foreach ($props as $key => $val) // { // error_log($key . " is " . $val); // } // create a new VideoEntry object $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); // create a new Zend_Gdata_App_MediaFileSource object $filesource = $this->yt->newMediaFileSource($fileDisk); $filesource->setContentType('video/quicktime'); // print_r($filesource); // set slug header $filesource->setSlug($fileUrl); // add the filesource to the video entry $myVideoEntry->setMediaSource($filesource); $myVideoEntry->setVideoTitle($props['title']); $myVideoEntry->setVideoDescription($props['description']); // The category must be a valid YouTube category! $myVideoEntry->setVideoCategory($props['category']); // Set keywords. Please note that this must be a comma-separated string // and that individual keywords cannot contain whitespace $myVideoEntry->setVideoTags($props['keywords']); if ($private) { $myVideoEntry->setVideoPrivate(); } else { $myVideoEntry->setVideoPublic(); } $access = array(); $access[] = new Zend_Gdata_YouTube_Extension_Access('comment', $props['comment']); $access[] = new Zend_Gdata_YouTube_Extension_Access('rate', $props['rate']); $access[] = new Zend_Gdata_YouTube_Extension_Access('commentVote', $props['commentVote']); $access[] = new Zend_Gdata_YouTube_Extension_Access('videoRespond', $props['videoRespond']); $access[] = new Zend_Gdata_YouTube_Extension_Access('embed', $props['embed']); $myVideoEntry->setAccess($access); // set some developer tags -- this is optional // (see Searching by Developer Tags for more details) // $myVideoEntry->setVideoDeveloperTags(array('mydevtag', 'anotherdevtag')); // set the video's location -- this is also optional // $yt->registerPackage('Zend_Gdata_Geo'); // $yt->registerPackage('Zend_Gdata_Geo_Extension'); // $where = $yt->newGeoRssWhere(); // $position = $yt->newGmlPos('37.0 -122.0'); // $where->point = $yt->newGmlPoint($position); // $myVideoEntry->setWhere($where); // upload URI for the currently authenticated user $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads'; // try to upload the video, catching a Zend_Gdata_App_HttpException, // if available, or just a regular Zend_Gdata_App_Exception otherwise /* try { */ $newEntry = $this->yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry'); $newEntry->setMajorProtocolVersion(2); //if(isset($props['playlists'])) //$this->handlePlaylists($newEntry, explode(',', $props['playlists'])); return $newEntry->getVideoId(); /* } catch (Zend_Gdata_App_HttpException $httpException) { // print_r($httpException); echo $httpException->getRawResponseBody(); return null; } catch (Zend_Gdata_App_Exception $e) { // print_r($e); echo $e->getMessage(); return null; }*/ }
/** * * @param record_adapter $record * @param array $options * @return string The new distant Id */ public function upload(record_adapter $record, array $options = []) { switch ($record->get_type()) { case 'video': $video_entry = new Zend_Gdata_YouTube_VideoEntry(); $filesource = new Zend_Gdata_App_MediaFileSource($record->get_hd_file()->getRealPath()); $filesource->setContentType($record->get_hd_file()->get_mime()); $filesource->setSlug($record->get_title()); $video_entry->setMediaSource($filesource); $video_entry->setVideoTitle($options['title']); $video_entry->setVideoDescription($options['description']); $video_entry->setVideoCategory($options['category']); $video_entry->SetVideoTags(explode(' ', $options['tags'])); $video_entry->setVideoDeveloperTags(['phraseanet']); if ($options['privacy'] == "public") { $video_entry->setVideoPublic(); } else { $video_entry->setVideoPrivate(); } $app_entry = $this->_api->insertEntry($video_entry, self::UPLOAD_URL, 'Zend_Gdata_YouTube_VideoEntry'); /* * set major protocole version to 2 otherwise you get exception when calling getVideoId * but setting setMajorProtocolVersion to 2 at the new entry introduce a new bug with getVideoState * @see http://groups.google.com/group/youtube-api-gdata/browse_thread/thread/7d86cac0d3f90e3f/d9291d7314f99be7?pli=1 */ $app_entry->setMajorProtocolVersion(2); return $app_entry->getVideoId(); break; default: throw new Bridge_Exception_InvalidRecordType('Unknown format'); break; } }