[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | /*
|
---|
| 4 | Description: Lets you attach a video to a post and upload to most popular video distribution sites like YouTube, Vimeo and Blip.tv, after video is uploaded and processed get and inserts the embed code from the sites into custom fields on the post. The plugin has de possibility to extend any other distribution site creating extra drivers
|
---|
| 5 | License: GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html)
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | $path = dirname(__FILE__);
|
---|
| 9 | set_include_path(get_include_path() . PATH_SEPARATOR . $path);
|
---|
| 10 | require_once $path.'/Zend/Loader.php';
|
---|
| 11 |
|
---|
| 12 | function youtube_settings() {
|
---|
| 13 | $service_config = Array(
|
---|
| 14 | 'service' => "youtube", //File with actions must be named like $service
|
---|
| 15 | 'service_url' => "youtube.com",
|
---|
| 16 | 'username' => "username",
|
---|
| 17 | 'password' => "passwd",
|
---|
| 18 | 'devkey' => "devkey",
|
---|
| 19 | 'enabled' => false
|
---|
| 20 | );
|
---|
| 21 | return $service_config;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | function youtube_extras() {
|
---|
| 25 | $extras = array('category'=> array( 'Autos'=>'Autos & Vehicles',
|
---|
| 26 | 'Music'=>'Music',
|
---|
| 27 | 'Animals'=>'Pets & Animals',
|
---|
| 28 | 'Sports'=>'Sports',
|
---|
| 29 | 'Travel'=>'Travel & Events',
|
---|
| 30 | 'Games'=>'Gadgets & Games',
|
---|
| 31 | 'Comedy'=>'Comedy',
|
---|
| 32 | 'People'=>'People & Blogs',
|
---|
| 33 | 'News'=>'News & Politics',
|
---|
| 34 | 'Entertainment'=>'Entertainment',
|
---|
| 35 | 'Education'=>'Education',
|
---|
| 36 | 'Howto'=>'Howto',
|
---|
| 37 | 'Nonprofit'=>'Nonprofit & Activism',
|
---|
| 38 | 'Tech'=>'Science & Technology')
|
---|
| 39 | );
|
---|
| 40 | return $extras;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | function upload_youtube($settings,$entry) {
|
---|
| 44 | Zend_Loader::loadClass('Zend_Gdata_AuthSub');
|
---|
| 45 | Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
|
---|
| 46 | Zend_Loader::loadClass('Zend_Gdata_YouTube');
|
---|
| 47 | Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoEntry');
|
---|
| 48 | $error = false; $retry = 0;
|
---|
| 49 | if (!isset($settings['username']) || (empty($settings['username']))) {
|
---|
| 50 | $error = true;
|
---|
| 51 | $error_desc = _("Please fill username field at webtv WordPress settings");
|
---|
| 52 | $retry = 1;
|
---|
| 53 | }
|
---|
| 54 | if (!isset($settings['password']) || (empty($settings['password']))) {
|
---|
| 55 | $error = true;
|
---|
| 56 | $error_desc = _("Please fill password field at webtv WordPress settings");
|
---|
| 57 | $retry = 1;
|
---|
| 58 | }
|
---|
| 59 | if (!isset($settings['devkey']) || (empty($settings['devkey']))) {
|
---|
| 60 | $error = true;
|
---|
| 61 | $error_desc = _("Please insert your Developer Key at webtv WordPress settings");
|
---|
| 62 | $retry = 1;
|
---|
| 63 | }
|
---|
| 64 | if (!isset($settings['category']) || (empty($settings['category']))) {
|
---|
| 65 | $error = true;
|
---|
| 66 | $error_desc = _("Please select a default category at webtv WordPress settings");
|
---|
| 67 | $retry = 1;
|
---|
| 68 | }
|
---|
| 69 | //set_time_limit(60*5);
|
---|
| 70 |
|
---|
| 71 | $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
|
---|
| 72 | $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
|
---|
| 73 | $username = $settings['username'],
|
---|
| 74 | $password = $settings['password'],
|
---|
| 75 | $service = 'youtube',
|
---|
| 76 | $client = null,
|
---|
| 77 | $source = 'WebTV Vlogger Wordpress Plugin', // identifying application
|
---|
| 78 | $loginToken = null,
|
---|
| 79 | $loginCaptcha = null,
|
---|
| 80 | $authenticationURL);
|
---|
| 81 |
|
---|
| 82 | $config_timeout = array('timeout' => 120); //Maybe you will need to raise this parameter if you are working with large files.
|
---|
| 83 | $httpClient->setConfig($config_timeout);
|
---|
| 84 | $myDeveloperKey = $settings['devkey'];
|
---|
| 85 | $httpClient->setHeaders('X-GData-Key', "key=${myDeveloperKey}");
|
---|
| 86 |
|
---|
| 87 | $yt = new Zend_Gdata_YouTube($httpClient);
|
---|
| 88 | // create a new Zend_Gdata_YouTube_VideoEntry object
|
---|
| 89 | $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
|
---|
| 90 | // create a new Zend_Gdata_App_MediaFileSource object
|
---|
| 91 | $filesource = $yt->newMediaFileSource($entry['fileinfo']);
|
---|
| 92 | $filesource->setContentType($entry['content_type']);
|
---|
| 93 | // set slug header
|
---|
| 94 | $filesource->setSlug($entry['fileinfo']);
|
---|
| 95 | // add the filesource to the video entry
|
---|
| 96 | $myVideoEntry->setMediaSource($filesource);
|
---|
| 97 | // create a new Zend_Gdata_YouTube_MediaGroup object
|
---|
| 98 | $mediaGroup = $yt->newMediaGroup();
|
---|
| 99 | $mediaGroup->title = $yt->newMediaTitle()->setText($entry['titulo']);
|
---|
| 100 | $mediaGroup->description = $yt->newMediaDescription()->setText($entry['desc']);
|
---|
| 101 | // the category must be a valid YouTube category
|
---|
| 102 | // optionally set some developer tags (see Searching by Developer Tags for more details)
|
---|
| 103 | $mediaGroup->category = array(
|
---|
| 104 | $yt->newMediaCategory()->setText($settings['category'])->setScheme('http://gdata.youtube.com/schemas/2007/categories.cat'),
|
---|
| 105 | $yt->newMediaCategory()->setText('webtv_plugin')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat'),
|
---|
| 106 | $yt->newMediaCategory()->setText('wordpress')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat')
|
---|
| 107 | );
|
---|
| 108 | // set keywords
|
---|
| 109 | $mediaGroup->keywords = $yt->newMediaKeywords()->setText($entry['tags']); //Linea con error, solucionado cambiando a $yt
|
---|
| 110 |
|
---|
| 111 | $myVideoEntry->mediaGroup = $mediaGroup;
|
---|
| 112 | // set video location
|
---|
| 113 | /*$yt->registerPackage('Zend_Gdata_Geo');
|
---|
| 114 | $yt->registerPackage('Zend_Gdata_Geo_Extension');
|
---|
| 115 | $where = $yt->newGeoRssWhere();
|
---|
| 116 | $position = $yt->newGmlPos('37.0 -122.0');
|
---|
| 117 | $where->point = $yt->newGmlPoint($position);
|
---|
| 118 | $entry->setWhere($where);
|
---|
| 119 | */
|
---|
| 120 |
|
---|
| 121 | // upload URL for the currently authenticated user
|
---|
| 122 | $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
|
---|
| 123 |
|
---|
| 124 | try {
|
---|
| 125 | $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
|
---|
| 126 |
|
---|
| 127 | } catch (Zend_Gdata_App_HttpException $httpException) {
|
---|
| 128 | $error_desc[] = $httpException->getRawResponseBody();
|
---|
| 129 | $error = true;
|
---|
| 130 | $retry = 1;
|
---|
| 131 | } catch (Zend_Gdata_App_Exception $e) {
|
---|
| 132 | $error_desc[] = $e->getMessage();
|
---|
| 133 | $error = true;
|
---|
| 134 | $retry = 1;
|
---|
| 135 | }
|
---|
| 136 | if (!$error) {
|
---|
| 137 | $videoid = $newEntry->getVideoId();
|
---|
| 138 | }
|
---|
| 139 | if (empty($videoid)) {
|
---|
| 140 | $error_desc[] = _("Can't get ID from YouTube, please verify if the video has been published and check the max_execution_time on your php.ini");
|
---|
| 141 | $error = true;
|
---|
| 142 | $retry = 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | // check if video is in draft status
|
---|
| 146 | try {
|
---|
| 147 | $control = $newEntry->getControl();
|
---|
| 148 | } catch (Zend_Gdata_App_Exception $e) {
|
---|
| 149 | $error_desc[] = $e->getMessage();
|
---|
| 150 | $error = true;
|
---|
| 151 | }
|
---|
| 152 | if ($control instanceof Zend_Gdata_App_Extension_Control) {
|
---|
| 153 | if ($control->getDraft() != null && $control->getDraft()->getText() == 'yes') {
|
---|
| 154 | $state = $newEntry->getVideoState();
|
---|
| 155 | if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
|
---|
| 156 | $upload_status = $state->getName();
|
---|
| 157 | $upload_status_desc = $state->getText();
|
---|
| 158 | } else {
|
---|
| 159 | $upload_status_desc = _("Can't get video status from YouTube, try again later");
|
---|
| 160 | $retry = 0;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | //Preparar la respuesta
|
---|
| 166 | $service_response = array();
|
---|
| 167 | $service_response['service'] = 'youtube';
|
---|
| 168 | $service_response['video_id'] = $videoid;
|
---|
| 169 | $service_response['status'] = $upload_status;
|
---|
| 170 | $service_response['status_description'] = $upload_status_desc;
|
---|
| 171 | $service_response['error'] = $error;
|
---|
| 172 | $service_response['error_description'] = $error_desc;
|
---|
| 173 | $service_response['retry'] = $retry;
|
---|
| 174 | return $service_response;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | function getembed_youtube($settings,$videodata) {
|
---|
| 178 | $error = false; $embed_code = ''; $retry = false;
|
---|
| 179 | Zend_Loader::loadClass('Zend_Gdata_AuthSub');
|
---|
| 180 | Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
|
---|
| 181 | Zend_Loader::loadClass('Zend_Gdata_YouTube');
|
---|
| 182 | Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoEntry');
|
---|
| 183 | $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
|
---|
| 184 | $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
|
---|
| 185 | $username = $settings['username'],
|
---|
| 186 | $password = $settings['password'],
|
---|
| 187 | $service = 'youtube',
|
---|
| 188 | $client = null,
|
---|
| 189 | $source = 'WebTV Wordpress Plugin', // identifying application
|
---|
| 190 | $loginToken = null,
|
---|
| 191 | $loginCaptcha = null,
|
---|
| 192 | $authenticationURL);
|
---|
| 193 |
|
---|
| 194 | $myDeveloperKey = $settings['devkey'];
|
---|
| 195 | $httpClient->setHeaders('X-GData-Key', "key=${myDeveloperKey}");
|
---|
| 196 |
|
---|
| 197 | $yt = new Zend_Gdata_YouTube($httpClient);
|
---|
| 198 | $upload_status = '';
|
---|
| 199 |
|
---|
| 200 | $videoEntry = $yt->getVideoEntry($videodata['video_id'], null, true);
|
---|
| 201 |
|
---|
| 202 | try {
|
---|
| 203 | $control = $videoEntry->getControl();
|
---|
| 204 | } catch (Zend_Gdata_App_Exception $e) {
|
---|
| 205 | $error_desc[] = $e->getMessage();
|
---|
| 206 | $error = true;
|
---|
| 207 | }
|
---|
| 208 | if ($control instanceof Zend_Gdata_App_Extension_Control) {
|
---|
| 209 | if ($control->getDraft() != null && $control->getDraft()->getText() == 'yes') {
|
---|
| 210 | $state = $videoEntry->getVideoState();
|
---|
| 211 | if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
|
---|
| 212 | $upload_status = $state->getName();
|
---|
| 213 | $upload_status_desc = $state->getText();
|
---|
| 214 | if ($upload_status != 'processing') { $error = true; $retry = false; } else { $error = false; $retry = true; }
|
---|
| 215 | } else {
|
---|
| 216 | $upload_status_desc = _("Can't get video status from YouTube, try again later");
|
---|
| 217 | $retry = true;
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | //Si no es empty, el video esta procesado y publicado en YouTube
|
---|
| 223 | if (empty($upload_status)) {
|
---|
| 224 | $flv_source = $videoEntry->getFlashPlayerUrl();
|
---|
| 225 | if (!empty($flv_source)) {
|
---|
| 226 | $embed_code = '<object width="425" height="344"><param name="movie" value="'.$flv_source.
|
---|
| 227 | '"></param><param name="allowFullScreen" value="true"></param>'.
|
---|
| 228 | '<param name="allowscriptaccess" value="always"></param><embed src="'.$flv_source.
|
---|
| 229 | '" type="application/x-shockwave-flash" allowscriptaccess="always"'.
|
---|
| 230 | ' allowfullscreen="true" width="425" height="344"></embed></object>';
|
---|
| 231 | $retry = false;
|
---|
| 232 | }
|
---|
| 233 | $video_url = $videoEntry->getVideoWatchPageUrl();
|
---|
| 234 | $duration = $videoEntry->getVideoDuration();
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | //Preparar la respuesta
|
---|
| 239 | $service_response = array();
|
---|
| 240 | $service_response['service'] = 'youtube';
|
---|
| 241 | $service_response['status'] = $upload_status;
|
---|
| 242 | $service_response['status_description'] = $upload_status_desc;
|
---|
| 243 | $service_response['error'] = $error;
|
---|
| 244 | $service_response['error_description'] = $error_desc;
|
---|
| 245 | $service_response['embed'] = $embed_code;
|
---|
| 246 | $service_response['watch_url'] = $video_url;
|
---|
| 247 | $service_response['retry'] = $retry;
|
---|
| 248 | $service_response['video_id'] = $videodata['video_id'];
|
---|
| 249 | //Optional data
|
---|
| 250 | $service_response['flv_source'] = $flv_source;
|
---|
| 251 | $service_response['duration'] = $duration;
|
---|
| 252 | return $service_response;
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | //restore_include_path();
|
---|
| 256 | ?>
|
---|