예제 #1
0
 /**
  *
  * @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;
     }
 }
예제 #2
0
 public function upload()
 {
     if (isset($this->httpClient)) {
         $response = "No Response From Server";
         $this->yt = new Zend_Gdata_YouTube($this->httpClient, $this->applicationId, $this->clientId, $this->developerKey);
         $this->yt->setMajorProtocolVersion(2);
         // create a new VideoEntry object
         $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
         // create a new Zend_Gdata_App_MediaFileSource object
         //$filesource = $this->yt->newMediaFileSource ( $this->video->path );
         $filesource = new Zend_Gdata_App_MediaFileSource($this->video->path);
         //echo ("Media Source Path " . $this->video->path . "<br>\n");
         $filesource->setContentType('video/mpeg');
         // set slug header
         $filesource->setSlug($this->video->slug);
         // add the filesource to the video entry
         $myVideoEntry->setMediaSource($filesource);
         //echo ("Media Source Set<br>\n");
         $myVideoEntry->setVideoTitle($this->getWebTitle());
         //echo ("Video Title Set<br>\n");
         $myVideoEntry->setVideoDescription($this->getWebDescription());
         //echo ("Description Set<br>\n");
         //TODO: Figure out how to set video response access as allowed
         // The category must be a valid YouTube category!
         $relevantVideosFeed = $this->getRelevantVideos($this->getWebTitle());
         $category = "Entertainment";
         if (isset($relevantVideosFeed)) {
             $categoryMap = $this->getRelevantYoutubeCategories($relevantVideosFeed);
             if (count($categoryMap) > 0) {
                 $category = $this->getRelevantCategoryFromCategoryMap($categoryMap);
             }
         }
         // Check to see if category is deprecated then use Category Chooser to find best category
         if (!$this->isValidCategory($category)) {
             //echo ("$category Is not valid. Looking for another valid category");
             $categorizer = new Categorizer($this->video->pid);
             $categorizer->chooseCategory($this->getPossibleCategories());
             $category = $categorizer->getPossCategoryName();
         }
         //echo ("Choosen Category: $category<br>");
         $myVideoEntry->setVideoCategory($category);
         //echo ("Category Set<br>\n");
         // Set keywords. Please note that this must be a comma-separated string
         // and that individual keywords cannot contain whitespace
         //$keywords = $this->getWebKeywords ();
         //echo ("Web Keywords: $keywords<br>\n");
         $keywords = $this->getYoutubeModifiedKeywords();
         //echo ( "Mod Keywords: $keywords<br>\n" );
         if (strlen($keywords) > 0) {
             $myVideoEntry->SetVideoTags($keywords);
         }
         //echo ("Tags Set<br>\n");
         // 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 {
             //echo ("Inserting Video Entry<br>\n");
             $newEntry = $this->yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
             $response = $this->getVideoState($newEntry);
             $this->uploadLocation = $newEntry->getVideoWatchPageUrl();
         } catch (Exception $except) {
             //echo ("Exception Thrown<br>\n");
             $response = $except->getMessage();
         }
     } else {
         $response = "No Http Client to upload video for user: "******"| Youtube HttpClient Response: " . $this->httpException;
         //echo ($response . "<br>");
     }
     return $response;
 }