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; }
public function getPreviewVideoAction() { $asset = Asset::getById($this->_getParam("id")); $this->view->asset = $asset; $youtubeSettings = $asset->getCustomSetting("youtube"); if (!Asset_Video_Youtube::getYoutubeCredentials()) { $this->view->configError = true; $this->render("get-preview-video-error"); } else { if (!is_array($youtubeSettings)) { $this->view->asset = $asset; if (Asset_Video_Youtube::upload($asset)) { $this->render("get-preview-video-display"); } else { $this->render("get-preview-video-error"); } } else { if ($youtubeSettings["failed"]) { $this->render("get-preview-video-error"); } else { $this->render("get-preview-video-display"); } } } }