1 | <?php
|
---|
2 |
|
---|
3 | /*
|
---|
4 | Author: Edgar de León - edeleon
|
---|
5 | Author URI: http://www.sinctrl.com/edeleon
|
---|
6 | 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
|
---|
7 | License: GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html)
|
---|
8 | */
|
---|
9 |
|
---|
10 | function bliptv_settings() {
|
---|
11 | $service_config = Array(
|
---|
12 | 'service' => "bliptv", //File with actions must be named like $service
|
---|
13 | 'service_url' => "blip.tv",
|
---|
14 | 'username' => "username",
|
---|
15 | 'password' => "passwd",
|
---|
16 | 'enabled' => false
|
---|
17 | );
|
---|
18 | return $service_config;
|
---|
19 | }
|
---|
20 |
|
---|
21 | function bliptv_extras() {
|
---|
22 | //ini_get('max_execution_time'); // to Retrieve execution time
|
---|
23 | //set_time_limit(60); // to set time limit
|
---|
24 |
|
---|
25 | $c = curl_init("http://www.blip.tv/?section=categories&cmd=view&skin=api");
|
---|
26 | curl_setopt($c, CURLOPT_HEADER, 0);
|
---|
27 | curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
|
---|
28 | $data = curl_exec($c);
|
---|
29 | $xml = simplexml_load_string($data);
|
---|
30 | curl_close($c);
|
---|
31 | $category = array();
|
---|
32 | if ($xml->status == "OK") {
|
---|
33 | foreach ($xml->payload->category as $categorydata) {
|
---|
34 | $id = intval($categorydata->id);
|
---|
35 | $category[$id] = (string)$categorydata->name;
|
---|
36 | }
|
---|
37 |
|
---|
38 | } else {
|
---|
39 | $category = array();
|
---|
40 | }
|
---|
41 |
|
---|
42 | $c = curl_init("http://www.blip.tv/?section=licenses&cmd=view&skin=api");
|
---|
43 | curl_setopt($c, CURLOPT_HEADER, 0);
|
---|
44 | curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
|
---|
45 | $data = curl_exec($c);
|
---|
46 | $xml = simplexml_load_string($data);
|
---|
47 | curl_close($c);
|
---|
48 | $license = array();
|
---|
49 | if ($xml->status == "OK") {
|
---|
50 | foreach ($xml->payload->license as $licensedata) {
|
---|
51 | $id = intval($licensedata->id);
|
---|
52 | $license[$id] = (string)$licensedata->name;
|
---|
53 | }
|
---|
54 |
|
---|
55 | } else {
|
---|
56 | $license = array();
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (empty($category) && empty($license)) {
|
---|
60 | $extras = array();
|
---|
61 | } else {
|
---|
62 | $extras = array('category' => $category, 'license' => $license);
|
---|
63 | }
|
---|
64 |
|
---|
65 | return $extras;
|
---|
66 | }
|
---|
67 |
|
---|
68 | function upload_bliptv($settings,$entry) {
|
---|
69 | //ini_get('max_execution_time'); // to Retrieve execution time
|
---|
70 | //set_time_limit(60*10);
|
---|
71 | $username = $settings['username'];
|
---|
72 | $password = $settings['password'];
|
---|
73 | $license = intval($settings['license']);
|
---|
74 | $category = intval($settings['category']);
|
---|
75 |
|
---|
76 | $upload_status = '';
|
---|
77 | $error = false;
|
---|
78 | $file = $entry['fileinfo'];
|
---|
79 |
|
---|
80 | $postfields = array(
|
---|
81 | 'section' => 'file',
|
---|
82 | 'cmd' => 'post',
|
---|
83 | 'post' => 1,
|
---|
84 | 'userlogin' => $username,
|
---|
85 | 'password' => $password,
|
---|
86 | 'title' => htmlspecialchars(stripslashes($entry['titulo'])),
|
---|
87 | 'description' => htmlspecialchars(stripslashes($entry['desc'])),
|
---|
88 | 'topics' => htmlspecialchars(stripslashes($entry['tags'])),
|
---|
89 | 'license' => $license,
|
---|
90 | 'categories_id' => $category,
|
---|
91 | 'file' => '@'.$file,
|
---|
92 | );
|
---|
93 |
|
---|
94 | $c = curl_init("http://uploads.blip.tv?skin=api");
|
---|
95 | curl_setopt($c, CURLOPT_POST, TRUE);
|
---|
96 | curl_setopt($c, CURLOPT_HEADER, 0);
|
---|
97 | curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
|
---|
98 | curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
|
---|
99 | $data = curl_exec($c);
|
---|
100 | $xml = simplexml_load_string($data);
|
---|
101 | curl_close($c);
|
---|
102 |
|
---|
103 | if ($xml->status == "OK") {
|
---|
104 | $videoid = (string)$xml->payload->asset->item_id;
|
---|
105 | $upload_status_desc = 'processing';
|
---|
106 | $retry = false;
|
---|
107 | } else {
|
---|
108 | $upload_status = 'error';
|
---|
109 | $error = true;
|
---|
110 | $upload_status_desc = (string)$error_desc = $xml->error->code ."-". $xml->error->message;
|
---|
111 | $retry = true;
|
---|
112 | }
|
---|
113 |
|
---|
114 | //Preparar la respuesta
|
---|
115 | $service_response = array();
|
---|
116 | $service_response['service'] = 'bliptv';
|
---|
117 | $service_response['video_id'] = $videoid;
|
---|
118 | $service_response['status'] = $upload_status;
|
---|
119 | $service_response['status_description'] = $upload_status_desc;
|
---|
120 | $service_response['error'] = $error;
|
---|
121 | $service_response['error_description'] = $error_desc;
|
---|
122 | $service_response['retry'] = $retry;
|
---|
123 | return $service_response;
|
---|
124 | }
|
---|
125 |
|
---|
126 | function getembed_bliptv($settings,$videodata) {
|
---|
127 | $error = false; $embed_code = ''; $retry = true;
|
---|
128 | //ini_get('max_execution_time'); // to Retrieve execution time
|
---|
129 | //set_time_limit(60*5); // to set time limit
|
---|
130 | $id = $videodata['video_id'];
|
---|
131 |
|
---|
132 | $c = curl_init("http://www.blip.tv/file/$id?skin=api");
|
---|
133 | curl_setopt($c, CURLOPT_HEADER, 0);
|
---|
134 | curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
|
---|
135 | $data = curl_exec($c);
|
---|
136 | $xml = simplexml_load_string($data);
|
---|
137 | curl_close($c);
|
---|
138 |
|
---|
139 | if ($xml->status == "OK") {
|
---|
140 | $videoid = $xml->payload->asset->item_id;
|
---|
141 | if ($xml->payload->asset->deleted == "true") {
|
---|
142 | $upload_status = 'error';
|
---|
143 | $upload_status_desc = $error_desc = _("Video deleted");
|
---|
144 | $error = true;
|
---|
145 | $retry = false;
|
---|
146 | } else {
|
---|
147 | $views = $xml->payload->asset->views;
|
---|
148 | $title = $xml->payload->asset->title;
|
---|
149 | $license = $xml->payload->asset->license->name;
|
---|
150 | $i = 0;
|
---|
151 | foreach ($xml->payload->asset->mediaList->media as $media) {
|
---|
152 | foreach($media as $detail => $data) {
|
---|
153 | if ($detail == 'link') {
|
---|
154 | $attr = $data->Attributes();
|
---|
155 | foreach ($attr as $type => $value) {
|
---|
156 | $video_role[$i][$type] = (string)$value;
|
---|
157 | }
|
---|
158 | //echo $xml->payload->asset->mediaList->media->link->@attributes->href;
|
---|
159 | } else {
|
---|
160 | $video_role[$i][$detail] = (string)$data;
|
---|
161 | }
|
---|
162 | }
|
---|
163 | $i++;
|
---|
164 | }
|
---|
165 | $conversion = $xml->payload->asset->conversions->conversion;
|
---|
166 | $upload_status_desc = $conversion->status."-".$conversion->target."-".$conversion->role;
|
---|
167 | $embed_id = (string)$xml->payload->asset->embedLookup;
|
---|
168 | $embed_url = (string)$xml->payload->asset->embedUrl;
|
---|
169 | $embed_code = (string)$xml->payload->asset->embedCode;
|
---|
170 | $video_url = "http://www.blip.tv/file/$id";
|
---|
171 | $retry = false;
|
---|
172 | }
|
---|
173 | } else {
|
---|
174 | $error_desc = (string)$xml->notice;
|
---|
175 | $error = false; //File not found - video uploaded but cannot get the id
|
---|
176 | $retry = false;
|
---|
177 | }
|
---|
178 |
|
---|
179 | //Preparar la respuesta
|
---|
180 | $service_response = array();
|
---|
181 | $service_response['service'] = 'bliptv';
|
---|
182 | $service_response['status'] = $upload_status;
|
---|
183 | $service_response['status_description'] = $upload_status_desc;
|
---|
184 | $service_response['error'] = $error;
|
---|
185 | $service_response['error_description'] = $error_desc;
|
---|
186 | $service_response['embed'] = $embed_code;
|
---|
187 | $service_response['watch_url'] = $video_url;
|
---|
188 | $service_response['retry'] = $retry;
|
---|
189 | $service_response['video_id'] = $videodata['video_id'];
|
---|
190 | //Optional data
|
---|
191 | $service_response['flv_source'] = $embed_url;
|
---|
192 | $role_options = array('href','duration','size');
|
---|
193 | foreach ($video_role as $item => $role) {
|
---|
194 | $rolename = $role['role'];
|
---|
195 | if (!empty($rolename)) {
|
---|
196 | foreach ($role as $data => $value) {
|
---|
197 | if (in_array($data,$role_options))
|
---|
198 | $service_response[$rolename."_".$data] = $value;
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 | return $service_response;
|
---|
203 |
|
---|
204 | }
|
---|
205 | ?> |
---|