Exemplo n.º 1
0
 public static function upload($asset)
 {
     try {
         $credentials = Asset_Video_Youtube::getYoutubeCredentials();
         if (!$credentials) {
             return;
         }
         $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = $credentials["username"], $password = $credentials["password"], $service = 'youtube', $client = Pimcore_Tool::getHttpClient("Zend_Gdata_HttpClient"), $source = 'Pimcore', $loginToken = null, $loginCaptcha = null, 'https://www.google.com/youtube/accounts/ClientLogin');
         $httpClient->setConfig(array("timeout" => 3600));
         $apikey = $credentials["apiKey"];
         $httpClient->setHeaders('X-GData-Key', "key={$apikey}");
         $yt = new Zend_Gdata_YouTube($httpClient);
         $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
         $filesource = $yt->newMediaFileSource($asset->getFileSystemPath());
         $filesource->setContentType($asset->getMimetype());
         $filesource->setSlug($asset->getFilename());
         $myVideoEntry->setMediaSource($filesource);
         $myVideoEntry->setVideoTitle($asset->getFullPath());
         $myVideoEntry->setVideoDescription($asset->getFullPath());
         $myVideoEntry->setVideoCategory('Comedy');
         // Set keywords, note that this must be a comma separated string
         // and that each keyword cannot contain whitespace
         $myVideoEntry->SetVideoTags('---, ---');
         // Optionally set some developer tags
         $myVideoEntry->setVideoDeveloperTags(array('mydevelopertag', 'anotherdevelopertag'));
         // Upload URI for the currently authenticated user
         $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
         try {
             $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
             $asset->setCustomSetting("youtube", array("id" => strval($newEntry->getVideoId())));
             $asset->save();
             return true;
         } catch (Exception $e) {
             $asset->setCustomSetting("youtube", array("failed" => true));
             $asset->save();
         }
     } catch (Exception $e) {
         Logger::error($e);
     }
     return false;
 }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
0
    function for_youtube($file_convert_for_youtube, $id_row)
    {
        $db = Zend_Db_Table::getDefaultAdapter();
        $films_info = $db->fetchRow("SELECT f.id, f.name, m.id as menu_activ, f.for_youtube, f.text, f.year\n\t\t\t, ( SELECT GROUP_CONCAT( s.name  ORDER BY fj.id SEPARATOR ', ') FROM film_janr fj join spravochnik s on s.id = fj.id_janr WHERE fj.films_id = f.id) as janr\n\t\t\t\t\t\tFROM menu m\n\t\t\t\t\t\tjoin films f on f.page_id = m.id\n\t\t\t\t\t\tWHERE m.type = 'films' and f.id = " . $id_row);
        $films_info['translit_url'] = $this->translitUrlName($films_info['name']);
        if ($films_info['for_youtube'] == 1) {
            $authenticationURL = 'https://www.google.com/accounts/ClientLogin';
            try {
                $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = '******', $password = '******', $service = 'youtube', $client = null, $source = 'MySource', $loginToken = null, $loginCaptcha = null, $authenticationURL);
            } catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
                echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
                echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
            } catch (Zend_Gdata_App_AuthException $ae) {
                echo 'Problem authenticating: ' . $ae->exception() . "\n";
            }
            $applicationId = "causal-rite-634";
            $clientId = "748030821368-ddkt4brpcq7623jii6l2bhc6ujfi08e9.apps.googleusercontent.com";
            //"11588627092-akui7d8un28eerombrt8784j4fpn1p12.apps.googleusercontent.com";
            $developerKey = "AI39si7LpRb8zR-_eP9tR-TPRAuBTBdM1gBHFssCCnc1sGCyJozLbYYPmlHW7lBSYxBYC4VKYmOp1mXMKQveeyXgOjsLNF0oQA";
            $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
            $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
            $filesource = $yt->newMediaFileSource($file_convert_for_youtube);
            $filesource->setContentType('video/quicktime');
            $filesource->setSlug($file_convert_for_youtube);
            $myVideoEntry->setMediaSource($filesource);
            ///названиефильма/ - Русский трейлер /год
            $name_trayler = $films_info['name'] . ' - Русский трейлер ' . $films_info['year'];
            if (mb_strlen($name_trayler) >= 60) {
                $temp_name_trayler = mb_substr($name_trayler, 0, 60, 'utf-8');
                $name_trayler = mb_substr($temp_name_trayler, 0, mb_strrpos($temp_name_trayler, ' '), 'utf-8');
            }
            $myVideoEntry->setVideoTitle($name_trayler);
            $myVideoEntry->setVideoDescription('Смотреть онлайн или скачать полную версию: http://tree.tv/film/' . $id_row . '-' . $films_info['translit_url'] . '
			' . $films_info['text']);
            // Note that category must be a valid YouTube category !
            $myVideoEntry->setVideoCategory('Film');
            // Set keywords, note that this must be a comma separated string
            // and that each keyword cannot contain whitespace
            $myVideoEntry->SetVideoTags('русский трейлер, смотреть, русский, онлайн, ' . date("Y") . ', фильм, кино, бесплатно, трейлер, trailer, тизер,' . $films_info['janr']);
            //('cars, funny');
            // Optionally set some developer tags
            $myVideoEntry->setVideoDeveloperTags(array('mydevelopertag', 'anotherdevelopertag'));
            // Optionally set the video's location
            $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/users/default/uploads';
            // Try to upload the video, catching a Zend_Gdata_App_HttpException
            // if availableor just a regular Zend_Gdata_App_Exception
            try {
                $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
            } catch (Zend_Gdata_App_HttpException $httpException) {
                echo $httpException->getRawResponseBody();
            } catch (Zend_Gdata_App_Exception $e) {
                echo $e->getMessage();
            }
            $db->query("update films SET for_youtube = '0' \n\t\t\t\t\t\t\tWHERE id = " . $id_row);
        }
    }
Exemplo n.º 4
0
 public function uploadVideo($Dailyop = false, $videoFile = false)
 {
     //if(!$Dailyop) throw new Exception("Invalid Dailyops ID");
     //let's get the video that needs to be uploaded
     $DailyopsShareParameter = ClassRegistry::init("DailyopsShareParameter");
     $MediaFile = ClassRegistry::init("MediaFile");
     //download the file to tmp
     $tmpFile = $MediaFile->downloadVideoToTmp($videoFile['MediaFile']['id']);
     //start the yt uploading processes
     Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoEntry');
     $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
     $src = $this->youtube->newMediaFileSource($tmpFile);
     $src->setContentType('video/mp4');
     $src->setSlug($videoFile['MediaFile']['limelight_file']);
     $videoEntry->setMediaSource($src);
     //make the video title
     $videoTitle = $Dailyop['Dailyop']['name'];
     if (!empty($Dailyop['Dailyop']['sub_title'])) {
         $videoTitle .= " - " . $Dailyop['Dailyop']['sub_title'];
     }
     $videoEntry->setVideoTitle($videoTitle);
     //now make the video description
     ///////Make the links for the top of the posting
     $videoDescription = "http://theberrics.com \n";
     //////make the link to the post
     $videoDescription .= "Original Post: http://theberrics.com/" . $Dailyop['DailyopSection']['uri'] . "/" . $Dailyop['Dailyop']['uri'] . "\n";
     //////make a link to the section of the video
     $videoDescription .= "More Like This: http://theberrics.com/" . $Dailyop['DailyopSection']['uri'] . "\n\n";
     //////now stuff in the text description if any
     if (!empty($Dailyop['Dailyop']['text_content'])) {
         $videoDescription .= Sanitize::html($Dailyop['Dailyop']['text_content'], array("remove" => true));
     }
     $videoEntry->setVideoDescription($videoDescription);
     //now lets set the tags for the post
     $tags = Set::extract("/Tag/name", $Dailyop);
     $tag_len = 0;
     foreach ($tags as $k => $v) {
         if (strlen($v) > 30) {
             unset($tags[$k]);
         } else {
             $tag_len += strlen($v);
         }
         if ($tag_len >= 470) {
             unset($tags[$k]);
         }
     }
     $tags[] = "Skateboarding";
     $tags[] = "The Berrics";
     $tags = implode(",", $tags);
     $videoEntry->setVideoTags($tags);
     //set the category
     $videoEntry->setVideoCategory('Sports');
     //set some dev tags
     $videoEntry->setVideoDeveloperTags(array("berricsapi", "berricsupload"));
     //start the upload processes
     $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
     try {
         $newEntry = $this->youtube->insertEntry($videoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
     } catch (Zend_Gdata_App_HttpException $httpException) {
         echo $httpException->getRawResponseBody();
     } catch (Zend_Gdata_App_Exception $e) {
         echo $e->getMessage();
     }
     $newEntry->setMajorProtocolVersion(2);
     $videoid = $newEntry->getVideoId();
     //get some additional info that we will need later
     $params = serialize(array("editHref" => $newEntry->getEditLink()->getHref()));
     //now create a share parameter entry for the post
     $DailyopsShareParameter->create();
     $DailyopsShareParameter->save(array("service" => "youtube", "dailyop_id" => $Dailyop['Dailyop']['id'], "foreign_key" => $videoid, "parameters" => $params));
     return $DailyopsShareParameter->read();
 }
Exemplo n.º 5
0
		function uploadAction()
		{
			//echo $this->user.' - '.$this->pass.' - '.$this->gallery;
			$this->view->headTitle('UNC - Admin website');
			$this->view->headLink()->appendStylesheet($this->view->baseUrl().'/application/templates/admin/css/layout.css');
			$this->view->headScript()->appendFile($this->view->baseUrl().'/application/templates/admin/js/jquery-1.7.2.min.js','text/javascript');
			$this->view->headScript()->appendFile($this->view->baseUrl().'/application/templates/admin/js/hideshow.js','text/javascript');

			$form = $this->setForm();
			$this->view->form = $form;
			
			if($this->_request->isPost())
			{	
				if($form->isValid($_POST))
				{
					$title =  $this->_request->getPost('title');
					$description = $this->_request->getPost('description');
					//echo $title.$description;die();
					if ($_FILES["file"]["name"]!='')
					{
						$dir = dirname($_FILES["file"]["tmp_name"]);
						$destination = $dir . DIRECTORY_SEPARATOR . $_FILES["file"]["name"];
						rename($_FILES["file"]["tmp_name"], $destination);
						
						$httpClient = $this->_httpClient();
									   
						Zend_Loader::loadClass('Zend_Gdata_YouTube');
					 	$yt = new Zend_Gdata_YouTube($httpClient, 'NIW-App-1.0', '661085061264.apps.googleusercontent.com', 'AI39si4UPUxw1FE5hqSi0Z-B-5z3PIVovbBWKmqiMI3cXJ7lhvjJcABV-eqimb2EeSiuedWK8N9OGOdB1namX1CqqYki8jEfSQ');
						$yt->setMajorProtocolVersion(2);
						$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
						
						$filesource = $yt->newMediaFileSource($destination);
					    $filesource->setContentType('video/quicktime');
					    $filesource->setSlug($destination);
						
						$myVideoEntry->setMediaSource($filesource);
						$myVideoEntry->setVideoTitle($title);
						$myVideoEntry->setVideoDescription($description);
						
						$myVideoEntry->setVideoCategory('Autos');
						$myVideoEntry->SetVideoTags('cars, funny');
						$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);
						
						$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
						try {
						  	$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
						} catch (Zend_Gdata_App_HttpException $httpException) {
						  echo $httpException->getRawResponseBody();
						} catch (Zend_Gdata_App_Exception $e) {
						    echo $e->getMessage();
						}
						
						if(file_exists($destination))
							unlink($destination);
						
						echo '<script type="text/javascript">
							alert("Video đang được upload trên YOUTUBE !");
						</script>';
						$this->_redirect($this->view->baseUrl().'/../admin/uploadvideo');
						
						//
					}
					else echo '<script type="text/javascript">alert("Vui lòng chọn file !");</script>';
				}
				
			//}
			$this->view->title = 'Tải lên video';
			}
		}