/[drupal]/contributions/modules/emfield/contrib/video_cck/providers/bliptv.inc
ViewVC logotype

Contents of /contributions/modules/emfield/contrib/video_cck/providers/bliptv.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Mon May 12 04:10:54 2008 UTC (18 months, 2 weeks ago) by alexua
Branch: MAIN
CVS Tags: DRUPAL-5--1-3, HEAD
Changes since 1.9: +5 -5 lines
File MIME type: text/x-php
Corrected all errors registered by Coder module in preperation for D6 port
1 <?php
2 // $Id: bliptv.inc,v 1.9 2008/05/11 03:56:54 alexua Exp $
3 define('VIDEO_CCK_BLIPTV_MAIN_URL', 'http://blip.tv/');
4 define('VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE', 'flv');
5
6 function video_cck_bliptv_info() {
7 $name = t('Blip.tv');
8 $features = array(
9 array(t('Autoplay'), t('Yes'), ''),
10 array(t('RSS attachment'), t('Yes'), t('When displaying in an RSS feed, these videos will be attached to the feed. (The feed reader or aggregator must support enclosure tags.)')),
11 array(t('Thumbnails'), t('Yes'), ''),
12 );
13 return array(
14 'provider' => 'bliptv',
15 'name' => $name,
16 'url' => VIDEO_CCK_BLIPTV_MAIN_URL,
17 'settings_description' => t('These settings specifically affect videos displayed from !provider.', array('!provider' => l($name, VIDEO_CCK_BLIPTV_MAIN_URL, array('target' => '_blank')))),
18 'supported_features' => $features,
19 );
20 }
21
22 function video_cck_bliptv_settings() {
23 $tags = array('none' => t('No video'), 'flv' => t('Flash Video'), 'override' => t('Override tag'), 'web' => t('Web'), 'Web High Resolution' => t('Web High Resolution'), 'Portable (iPod)' => t('Portable (iPod)'), 'Portable (other)' => t('Portable (other)'), 'Television' => t('Television'), 'HDTV' => t('HDTV'), 'Cell Phone' => t('Cell Phone'), 'Source' => t('Source'));
24 $formats = array('none' => t('No video'), 'flv' => t('Flash video (flv)'), 'mov' => t('Quicktime Movie (mov)'), 'mp3' => t('MP3'), 'm4a' => t('m4a'), 'mpg' => t('MPEG'), 'mp4' => t('mp4'), 'm4v' => t('m4v'), 'wmv' => t('Windows Media (wmv)'));
25
26 $form = array();
27 $form['video_formats'] = array(
28 '#type' => 'fieldset',
29 '#title' => t('Video formats'),
30 '#description' => t("Blip.TV allows users to upload videos of various formats, sizes, and qualities. These options will allow the administrator to choose the default video formats to display. Blip.TV uses 'tags' to determine this, such as 'Web' for a standard web resolution, and 'HDTV' for a high definition. If you select a tag, then the video format provided by Blip.TV for that tag will be displayed. If you select 'Override tag', then you may specify that the first available video of the given format will be displayed instead, which may or may not have your desired resolution. If a tag or format is not available for a specific video, the module will display the Flash video format instead, which is always present."),
31 '#collapsible' => true,
32 '#collapsed' => false,
33 );
34 $form['video_formats']['rss'] = array(
35 '#type' => 'fieldset',
36 '#title' => t('RSS'),
37 '#description' => t("This will determine the preferred video format for RSS feeds."),
38 '#collapsible' => true,
39 '#collapsed' => true,
40 );
41
42 $form['video_formats']['rss']['video_cck_bliptv_rss_tag'] = array(
43 '#type' => 'select',
44 '#title' => t('RSS full page tag'),
45 '#description' => t("When RSS feeds are displayed, and this tag is available for a video, then the clip for that tag will be displayed as an enclosure tag in the feed. Select 'Override tag' if you wish to control the format displayed. Select 'No video' if you do not wish a video to be displayed in RSS feeds."),
46 '#options' => $tags,
47 '#default_value' => variable_get('video_cck_bliptv_rss_tag', array(VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE => VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE)),
48 );
49 $form['video_formats']['rss']['video_cck_bliptv_rss_format'] = array(
50 '#type' => 'select',
51 '#title' => t('RSS full page format override'),
52 '#description' => t("When RSS feeds are displayed, and the 'Override tag' option is selected above, then this format will be displayed as an enclosure tag in the feed."),
53 '#options' => $formats,
54 '#default_value' => variable_get('video_cck_bliptv_rss_format', array(VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE => VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE)),
55 );
56 return $form;
57 }
58
59 function video_cck_bliptv_data($field, $item) {
60 $data = array();
61
62 // we added new data fields to keep from having to reload the api/rss
63 // because the data is only stored on update/insert, however, we have to know which data type we're using
64 // this will just be an integer, increased when we make a change to data
65 $data['video_cck_bliptv_data_version'] = 2;
66
67 // use the page id, since we'll have that in most cases (except in embed pastes, which gets parsed during extraction)
68 // we use this to get an rss feed w/ all the info for the video. interesting reading ;)
69 // some of our data we'll get from the api, like available files
70 $rss = video_cck_bliptv_request($item['value'], TRUE, 'rss');
71 $api = video_cck_bliptv_request($item['value'], TRUE, 'api');
72
73 // special handling for show/feature pages
74 // TODO: this is disabled for now.
75 // if (empty($rss) && empty($api) && preg_match('@http\://([^\.]+)\.blip\.tv/@i', $item['embed'], $matches)) {
76 // $show_rss = video_cck_bliptv_request($item['value'], TRUE, 'rss', TRUE);
77 // $data['thumbnail']['url'] = $rss['IMAGE']['URL'][0];
78 // $data['flv'] = array();
79 // $data['showpage'] = "http://{$item['value']}.blip.tv/";
80 // $data['is_show'] = TRUE;
81 // return $data;
82 // }
83
84 $data['is_show'] = FALSE;
85
86 // get our thumbnail url
87 $data['thumbnail']['url'] = $rss['ITEM']['MEDIA:THUMBNAIL'][1]['URL'];
88
89 // this gets sent to the player
90 foreach ((array)$api['MEDIA']['LINK'] as $x => $link) {
91 $x--;
92 $video_type = '';
93 switch ($link['TYPE']) {
94 case 'video/x-flv':
95 $video_type = 'flv';
96 break;
97 case 'video/x-m4v':
98 $video_type = 'm4v';
99 break;
100 case 'video/quicktime':
101 $video_type = 'mov';
102 break;
103 }
104 if ($video_type) {
105 $video_info = array();
106 $video_info['url'] = $link['HREF'];
107 $video_info['width'] = $api['MEDIA']['WIDTH'][$x];
108 $video_info['height'] = $api['MEDIA']['HEIGHT'][$x];
109 $video_info['duration'] = $api['MEDIA']['DURATION'][$x];
110 $video_info['size'] = $api['MEDIA']['SIZE'][$x];
111 $video_info['mime'] = $link['TYPE'];
112
113 // we only store the last video of a particular type, for instance if two roles use .mov
114 $data[$video_type] = $video_info;
115
116 // however, we store the whole thing under role, so the information is still saved
117 // but our arrays may be out of synch...
118 $y = $x + 1;
119 if ($api['MEDIA']['ROLE'][$y]) {
120 $data[$video_type]['role'] = $api['MEDIA']['ROLE'][$y];
121 $data[$api['MEDIA']['ROLE'][$y]] = $video_info;
122 $data[$api['MEDIA']['ROLE'][$y]]['role'] = $api['MEDIA']['ROLE'][$y];
123 }
124 }
125 }
126 if (!$data['flv']) {
127 $data['flv'] = array();
128 }
129 if (!$data['flv']['url']) {
130 $data['flv']['url'] = $rss['ITEM']['ENCLOSURE'][1]['URL'];
131 }
132 $data['title'] = $api['en']['TITLE'][0] ? $api['en']['TITLE'][0] : $rss['2.0']['CHANNEL']['TITLE'][0];
133 $data['description'] = $api['en']['DESCRIPTION'][0] ? $api['en']['DESCRIPTION'][0] : $rss['ITEM']['BLIP:PUREDESCRIPTION'][0];
134 $data['blip_user']['uid'] = $api['CREATEDBY']['UID'][0] ? $api['CREATEDBY']['UID'][0] : $rss['ITEM']['BLIP:USERID'][0];
135 $data['blip_user']['username'] = $api['CREATEDBY']['LOGIN'][0] ? $api['CREATEDBY']['LOGIN'][0] : $rss['ITEM']['BLIP:USER'][0];
136 $data['blip_user']['url'] = $api['CREATEDBY']['LINKS']['LINK'][1] ? $api['CREATEDBY']['LINKS']['LINK'][1] : 'http://blip.tv/users/view/'. $data['blip_user']['username'];
137
138 $data['showpage'] = $rss['ITEM']['BLIP:SHOWPAGE'][0];
139
140 // this is the code actually used by the player, even though it's different than for the page
141 if ($rss['ITEM']['BLIP:POSTS_ID'][0]) {
142 $data['post_id'] = $rss['ITEM']['BLIP:POSTS_ID'][0];
143 }
144
145 return $data;
146 }
147
148 function video_cck_bliptv_request($code, $cacheable = TRUE, $skin = 'rss', $show = FALSE) {
149 $args = array();
150 $file = $show ? "http://$code.blip.tv/file/?skin=" . $skin : "http://blip.tv/file/$code?skin=" . $skin;
151 return module_invoke('emfield', 'request_xml', 'bliptv', $file, $args, $cacheable, false, $code .':'. $skin . ($show ? ':show' : ':post'));
152 }
153
154 function video_cck_bliptv_extract($embed) {
155 return array(
156 '@blip\.tv/rss/flash/([^"\&\?]+)@i',
157 '@blip\.tv/file/view/([^"\&\?]+)@i',
158 '@blip\.tv/file/([^"\&\?]+)@i',
159
160 // test handling for featured shows. disabled for now.
161 // '@http\://([^\.]+)\.blip\.tv/@i',
162 );
163 }
164
165 function video_cck_bliptv_video_link($video_code) {
166 return 'http://blip.tv/file/'. $video_code;
167 }
168
169 function _video_cck_bliptv_get_video_info_from_preferred_tag($data, $var) {
170 $preferred_tags = (array)variable_get($var, array(VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE => VIDEO_CCK_BLIPTV_DEFAULT_RSS_TYPE));
171
172 foreach ($preferred_tags as $test_tag) {
173 // if we override the tag with a type, then break so it can be handled
174 if ($test_tag == 'override') {
175 $video_info = 'override';
176 break;
177 }
178
179 // if we have a clip of that format type, then return it
180 if ($data[$test_tag]['url']) {
181 $video_info = $data[$test_tag];
182 break;
183 }
184 }
185
186 return $video_info;
187 }
188
189 /**
190 * providers may supply an enclosure for rss feeds. this expects something in a file format, so would be an object
191 * in the format of $file->filepath, $file->filesize, and $file->filemime. calls the providers hook video_cck_PROVIDER_rss
192 */
193 function video_cck_bliptv_rss($item, $teaser = NULL) {
194 if ($item['value']) {
195 if ($item['data']['video_cck_bliptv_data_version'] >= 1) {
196 $data = $item['data'];
197 }
198 else {
199 $data = video_cck_bliptv_data(NULL, $item);
200 }
201
202 // get the preferred type for the rss feed
203 $var = 'video_cck_bliptv_rss_tag';
204 $video_info = _video_cck_bliptv_get_video_info_from_preferred_tag($data, $var);
205
206 // grab the preferred filetype rather than tag, so .mov rather than 'web'
207 if ($video_info == 'override') {
208 $var = 'video_cck_bliptv_rss_format';
209 $video_info = _video_cck_bliptv_get_video_info_from_preferred_tag($data, $var);
210 }
211
212 // default to flv if there's no available clip format
213 if (is_null($video_info) || ($video_info == 'override') && $video_info != 'none') {
214 $video_info = $data['flv'];
215 }
216
217 if (is_array($video_info)) {
218 // Begin building file object.
219 $file = array();
220 // Create temporary name/path for newly uploaded files.
221 $file['filepath'] = $video_info['url'];
222 $file['filesize'] = $video_info['size'];
223 $file['filemime'] = $video_info['mime'];
224
225 // additional data for Y! MRSS
226 $file['thumbnail']['filepath'] = $data['thumbnail']['url'];
227 $file['width'] = ($video_info['width']) ? $video_info['width'] : 0;
228 $file['height'] = ($video_info['height']) ? $video_info['height'] : 0;
229 $file['duration'] = ($video_info['duration']) ? $video_info['duration'] : FALSE;
230 // @todo media:credit role="author" ...
231
232 return $file;
233 }
234 }
235 }
236
237 function theme_video_cck_bliptv_flash($code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail, $options = array()) {
238 static $count;
239 if ($code) {
240 $count++;
241 $id = isset($options['id']) ? $options['id'] : "emfield_videocck_player_bliptv_$count";
242 $autoplay = $autoplay ? 'autoStart=true' : 'autoStart=false';
243
244 $rss = $item['data']['showpage'] ? "&feedurl={$item['data']['showpage']}/rss" : '';
245
246 $post_id = $item['data']['post_id'];
247 // if/when we allow featured shows to be embedded, this will handle that.
248 // $file = $item['data']['is_show'] ? "http://$code.blip.tv/rss/flash/" : 'http://blip.tv/rss/flash/'. $item['data']['post_id'];
249
250 $file = 'http://blip.tv/rss/flash/'. $item['data']['post_id'];
251 $embed_file = 'http://blip.tv/scripts/flash/showplayer.swf?enablejs=true'. $rss .'&file='. $file .'&showplayerpath=http://blip.tv/scripts/flash/showplayer.swf';
252
253 $output .= '<object type="application/x-shockwave-flash" data="'. $embed_file .'" width="'. $width .'" height="'. $height .'" allowfullscreen="true" id="'. $id .'"><param name="movie" value="'. $embed_file .'" /><param name="quality" value="best" /><embed src="'. $embed_file .'" quality="best" width="'. $width .'" height="'. $height .'" name="'. $id .'" type="application/x-shockwave-flash"></embed></object>';
254 }
255 return $output;
256 }
257
258 function video_cck_bliptv_thumbnail($field, $item, $formatter, $node, $width, $height, $options = array()) {
259 if ($item['data']['video_cck_bliptv_data_version'] >= 1) {
260 $tn = $item['data']['thumbnail']['url'];
261 }
262 else {
263 $tn = $item['data']['thumbnail'];
264 }
265 return $tn;
266 }
267
268 function video_cck_bliptv_video($code, $width, $height, $field, $item, $autoplay, $options = array()) {
269 if ($item['data']['video_cck_bliptv_data_version'] >= 1) {
270 $flv = $item['data']['flv']['url'];
271 $thumbnail = $item['data']['thumbnail']['url'];
272 }
273 else {
274 $flv = $item['data']['flv'];
275 $thumbnail = $item['data']['thumbnail'];
276 }
277
278 $output = theme('video_cck_bliptv_flash', $code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail);
279 return $output;
280 }
281
282 function video_cck_bliptv_preview($code, $width, $height, $field, $item, $autoplay, $options = array()) {
283 if ($item['data']['video_cck_bliptv_data_version'] >= 1) {
284 $flv = $item['data']['flv']['url'];
285 $thumbnail = $item['data']['thumbnail']['url'];
286 }
287 else {
288 $flv = $item['data']['flv'];
289 $thumbnail = $item['data']['thumbnail'];
290 }
291 $output = theme('video_cck_bliptv_flash', $code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail);
292 return $output;
293 }
294

  ViewVC Help
Powered by ViewVC 1.1.2