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

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

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


Revision 1.2 - (show annotations) (download) (as text)
Wed Jan 7 14:14:13 2009 UTC (10 months, 2 weeks ago) by alexua
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +453 -0 lines
File MIME type: text/x-php
#348419/jtsnow added support for yahoo music videos.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * This include processes Yahoo Music API media files for use by emfield.module.
7 */
8
9 define('EMVIDEO_YAHOOMUSIC_MAIN_URL', 'http://new.music.yahoo.com/');
10 define('EMVIDEO_YAHOOMUSIC_API_INFO', 'http://developer.yahoo.com/music/api_guide/');
11 define('EMVIDEO_YAHOOMUSIC_API_APPLICATION_URL', 'http://developer.yahoo.com/music/');
12 define('EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT', '#000000');
13
14 /**
15 * hook video_cck_PROVIDER_info
16 * this returns information relevant to a specific 3rd party video provider
17 * @return
18 * an array of strings requested by various admin and other forms
19 * 'name' => the translated name of the provider
20 * 'url' => the url to the main page for the provider
21 * 'settings_description' => a description of the provider that will be posted in the admin settings form
22 * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
23 * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
24 */
25 function video_cck_yahoomusic_info() {
26 $features = array(
27 array(t('Autoplay'), t('Yes'), ''),
28 array(t('Thumbnails'), t('Yes'), t('')),
29 array(t('Full screen mode'), t('Yes'), t('You may customize the player to enable or disable full screen playback. Full screen mode is enabled by default.')),
30 );
31 return array(
32 'provider' => 'yahoomusic',
33 'name' => t('Yahoo! Music'),
34 'url' => EMVIDEO_YAHOOMUSIC_MAIN_URL,
35 'settings_description' => t('These settings specifically affect videos displayed from <a href="@yahoomusic" target="_blank">Yahoo Music</a>. You can learn more about its <a href="@api" target="_blank">API</a> here.', array('@yahoomusic' => EMVIDEO_YAHOOMUSIC_MAIN_URL, '@api' => EMVIDEO_YAHOOMUSIC_API_INFO)),
36 'supported_features' => $features,
37 );
38 }
39
40 /**
41 * hook video_cck_PROVIDER_settings
42 * this should return a subform to be added to the video_cck_settings() admin settings page.
43 * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['yahoomusic'])
44 * so if you want specific provider settings within that field, you can add the elements to that form field.
45 */
46 function video_cck_yahoomusic_settings() {
47 $form['yahoomusic']['api'] = array(
48 '#type' => 'fieldset',
49 '#title' => t('Yahoo! Music API'),
50 '#description' => t('You will first need to apply for a Yahoo App ID from the <a href="@yahoomusic" target="_blank">Yahoo! Developer Network</a>.', array('@yahoomusic' => EMVIDEO_YAHOOMUSIC_API_APPLICATION_URL)),
51 '#collapsible' => TRUE,
52 '#collapsed' => TRUE,
53 );
54 $form['yahoomusic']['api']['video_cck_yahoomusic_app_id'] = array(
55 '#type' => 'textfield',
56 '#title' => t('Yahoo! App ID'),
57 '#default_value' => variable_get('video_cck_yahoomusic_app_id', ''),
58 '#description' => t('Please enter your Yahoo! App ID here.'),
59 );
60 $form['yahoomusic']['api']['video_cck_yahoomusic_locale'] = array(
61 '#type' => 'select',
62 '#title' => t('Locale'),
63 '#default_value' => variable_get('video_cck_yahoomusic_locale','us'),
64 '#options' => array(
65 'us' => t('United States'),
66 'e1' => t('United States (Espanol)'),
67 'ca' => t('Canada'),
68 'mx' => t('Mexico'),
69 'au' => t('Australia'),
70 'nz' => t('New Zealand'),
71 'uk' => t('United Kingdom'),
72 'de' => t('Germany'),
73 'es' => t('Spain'),
74 'it' => t('Italy'),
75 'fr' => t('France'),
76 ),
77 '#description' => t('If your application is designed for use by a web site or service in a particular country, Yahoo! Music requires that you use the locale for that country.'),
78 );
79 $form['yahoomusic']['player_options'] = array(
80 '#type' => 'fieldset',
81 '#title' => t('Embedded video player options'),
82 '#collapsible' => TRUE,
83 '#collapsed' => TRUE,
84 );
85 $form['yahoomusic']['player_options']['video_cck_yahoomusic_full_screen'] = array(
86 '#type' => 'checkbox',
87 '#title' => t('Allow fullscreen'),
88 '#default_value' => variable_get('video_cck_yahoomusic_full_screen', 1),
89 '#description' => t('Allow users to view video using the entire computer screen.'),
90 );
91 $form['yahoomusic']['player_options']['video_cck_yahoomusic_close_enable'] = array(
92 '#type' => 'checkbox',
93 '#title' => t('Enable Close'),
94 '#default_value' => variable_get('video_cck_yahoomusic_close_enable', 0),
95 '#description' => t('Sets visibility of the close button; button action will throw a callback event of type "close".'),
96 );
97 $form['yahoomusic']['player_options']['video_cck_yahoomusic_controls_enable'] = array(
98 '#type' => 'checkbox',
99 '#title' => t('Enable Controls'),
100 '#default_value' => variable_get('video_cck_yahoomusic_controls_enable', 1),
101 '#description' => t('Enables the player controls.'),
102 );
103 $form['yahoomusic']['player_options']['video_cck_yahoomusic_info_enable'] = array(
104 '#type' => 'checkbox',
105 '#title' => t('Enable Info'),
106 '#default_value' => variable_get('video_cck_yahoomusic_info_enable', 1),
107 '#description' => t('Sets visibility of the "more info" button.'),
108 );
109 $form['yahoomusic']['player_options']['video_cck_yahoomusic_now_playing_enable'] = array(
110 '#type' => 'checkbox',
111 '#title' => t('Enable Intro'),
112 '#default_value' => variable_get('video_cck_yahoomusic_now_playing_enable', 1),
113 '#description' => t('Enables the intro "Now Playing: ..." component during the first few seconds of playback.'),
114 );
115 $form['yahoomusic']['player_options']['video_cck_yahoomusic_post_panel_enable'] = array(
116 '#type' => 'checkbox',
117 '#title' => t('Enable Post Panel'),
118 '#default_value' => variable_get('video_cck_yahoomusic_post_panel_enable', 1),
119 '#description' => t('Enables the post panel; displayed after a clip completes playback.'),
120 );
121 $form['yahoomusic']['player_options']['video_cck_yahoomusic_pre_panel_enable'] = array(
122 '#type' => 'checkbox',
123 '#title' => t('Enable Pre Panel'),
124 '#default_value' => variable_get('video_cck_yahoomusic_pre_panel_enable', 1),
125 '#description' => t('Enables the pre meta panel on player initialization when autoStart is disabled and a valid id has been passed into the player.'),
126 );
127 $form['yahoomusic']['player_options']['video_cck_yahoomusic_share_enable'] = array(
128 '#type' => 'checkbox',
129 '#title' => t('Enable Share'),
130 '#default_value' => variable_get('video_cck_yahoomusic_share_enable', 1),
131 '#description' => t('Enables the Share panel.'),
132 );
133 $form['yahoomusic']['player_options']['video_cck_yahoomusic_bgcolor'] = array(
134 '#type' => 'textfield',
135 '#title' => t('Background Color'),
136 '#default_value' => variable_get('video_cck_yahoomusic_bgcolor', EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT),
137 );
138 $form['yahoomusic']['player_options']['video_cck_yahoomusic_bandwidth'] = array(
139 '#type' => 'textfield',
140 '#title' => t('Bandwidth'),
141 '#default_value' => variable_get('video_cck_yahoomusic_bandwidth', ''),
142 '#description' => t('Used to force a bandwidth; if bw is not specified the player will attempt to determine the best video bitrate quality for the user.'),
143 );
144 $form['yahoomusic']['player_options']['video_cck_yahoomusic_event_handler'] = array(
145 '#type' => 'textfield',
146 '#title' => t('Event Handler'),
147 '#default_value' => variable_get('video_cck_yahoomusic_event_handler', ''),
148 '#description' => t('Callback event handler that the player should make calls to.'),
149 );
150
151 return $form;
152 }
153
154 /**
155 * hook emfield_PROVIDER_data
156 *
157 * provides an array to be serialised and made available with $item elsewhere
158 */
159 function video_cck_yahoomusic_data($field, $item) {
160 $data = array();
161 // create some 'field' version control
162 $data['video_cck_yahoomusic_version'] = 1;
163 return $data;
164 }
165
166
167 /**
168 * hook video_cck_PROVIDER_extract
169 * this is called to extract the video code from a pasted URL or embed code.
170 * @param $embed
171 * an optional string with the pasted URL or embed code
172 * @return
173 * either an array of regex expressions to be tested, or a string with the video code to be used
174 * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
175 * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
176 */
177 function video_cck_yahoomusic_extract($embed = '') {
178 // http://new.music.yahoo.com/videos/--205781579
179 // http://new.uk.music.yahoo.com/videos/Coldplay/Violet-Hill--60339090;_ylt=ApVMaK9zo0I8Fb03YCMv5qz1ECYv
180 // http://new.music.yahoo.com/T-I-/videos/view/Whatever-You-Like--184525308
181 if ($embed && preg_match('@(.*)yahoo.com(.*)--([0-9]+)@i', $embed, $matches)) {
182 return $matches[3];
183 }
184 // <param name='flashvars' value='id=v205781579&shareEnable=1&infoEnable=1' />
185 else if ($embed && preg_match('@id=v([^"\&]+)@i', $embed, $matches)) {
186 return $matches[1];
187 }
188
189 return FALSE;
190
191 }
192
193 /**
194 * hook video_cck_PROVIDER_embedded_link($video_code)
195 * returns a link to view the video at the provider's site
196 * @param $video_code
197 * the string containing the video to watch
198 * @return
199 * a string containing the URL to view the video at the original provider's site
200 */
201 function video_cck_yahoomusic_embedded_link($video_code) {
202 $locale = _video_cck_yahoomusic_locale_lookup();
203 return 'http://new.' . $locale . '.music.yahoo.com/videos/--' . $video_code;
204 }
205
206 function _video_cck_yahoomusic_locale_lookup($value = 'code') {
207 // Taken from http://developer.yahoo.com/music/api_guide/GettingStartedLocales.html
208 // Locale API Hostname eID ympsc lang
209 // United States us.music.yahooapis.com 1301797 4195351 en
210 // United States (Español) e1.music.yahooapis.com 1307666 559940629 es
211 // Canada ca.music.yahooapis.com 1307409 642778131 en
212 // Mexico mx.music.yahooapis.com 8257040 640680961 es
213 // Australia au.music.yahooapis.com 1307669 638583826 en
214 // New Zealand nz.music.yahooapis.com 5300947 638583833 en
215 // United Kingdom uk.music.yahooapis.com 1301655 529531933 uk
216 // Germany de.music.yahooapis.com 1307668 535823380 de
217 // Spain es.music.yahooapis.com 1307660 534774806 es
218 // Italy it.music.yahooapis.com 1307667 533726232 it
219 // France fr.music.yahooapis.com 1307665 536871959 fr
220
221 static $locales = array();
222
223 $code = variable_get('video_cck_yahoomusic_locale','us');
224
225 switch ($code) {
226 case 'us':
227 $locales[$code] = array('name' => 'United States', 'eid' => 1301797, 'ympsc' => 4195351, 'lang' => 'en');
228 break;
229 case 'e1':
230 $locales[$code] = array('name' => 'United States (Espanol)', 'eid' => 1307666, 'ympsc' => 559940629, 'lang' => 'es');
231 break;
232 case 'ca':
233 $locales[$code] = array('name' => 'Canada', 'eid' => 1307409, 'ympsc' => 642778131, 'lang' => 'en');
234 break;
235 case 'mx':
236 $locales[$code] = array('name' => 'Mexico', 'eid' => 8257040, 'ympsc' => 640680961, 'lang' => 'es');
237 break;
238 case 'au':
239 $locales[$code] = array('name' => 'Australia', 'eid' => 1307669, 'ympsc' => 638583826, 'lang' => 'en');
240 break;
241 case 'nz':
242 $locales[$code] = array('name' => 'New Zealand', 'eid' => 5300947, 'ympsc' => 638583833, 'lang' => 'en');
243 break;
244 case 'uk':
245 $locales[$code] = array('name' => 'United Kingdom', 'eid' => 1301655, 'ympsc' => 529531933, 'lang' => 'uk');
246 break;
247 case 'de':
248 $locales[$code] = array('name' => 'Germany', 'eid' => 1307668, 'ympsc' => 535823380, 'lang' => 'de');
249 break;
250 case 'es':
251 $locales[$code] = array('name' => 'Spain', 'eid' => 1307660, 'ympsc' => 534774806, 'lang' => 'es');
252 break;
253 case 'it':
254 $locales[$code] = array('name' => 'Italy', 'eid' => 1307667, 'ympsc' => 533726232, 'lang' => 'it');
255 break;
256 case 'fr':
257 $locales[$code] = array('name' => 'France', 'eid' => 1307665, 'ympsc' => 536871959, 'lang' => 'fr');
258 break;
259 default:
260 $code = 'us';
261 $locales[$code] = array('name' => 'United States', 'eid' => 1301797, 'ympsc' => 4195351, 'lang' => 'en');
262 }
263 $locales[$code]['hostname'] = $code . '.music.yahooapis.com';
264
265 switch ($value) {
266 case 'code':
267 return $code;
268 break;
269 case 'name':
270 return $locales[$code]['name'];
271 break;
272 case 'hostname':
273 return $locales[$code]['hostname'];
274 break;
275 case 'eid':
276 return $locales[$code]['eid'];
277 break;
278 case 'ympsc':
279 return $locales[$code]['ympsc'];
280 break;
281 case 'lang':
282 return $locales[$code]['lang'];
283 break;
284 default:
285 drupal_set_message(t('Bad locale lookup request.'), 'warning');
286 return '';
287 }
288 }
289
290 /**
291 * The embedded flash displaying the yahoomusic video.
292 */
293 function theme_video_cck_yahoomusic_flash($embed, $width, $height, $autoplay, $options = array()) {
294 static $count;
295 if ($embed) {
296
297 $variables = array();
298 $variables['id'] = 'v' . $embed;
299 $variables['eID'] = _video_cck_yahoomusic_locale_lookup('eid');
300 $variables['ympsc'] = _video_cck_yahoomusic_locale_lookup('ympsc');
301 $variables['lang'] = _video_cck_yahoomusic_locale_lookup('lang');
302
303 $fullscreen = variable_get('video_cck_yahoomusic_full_screen', 1);
304 $fullscreen_value = $fullscreen ? "true" : "false";
305 $variables['enableFullScreen'] = $fullscreen ? "1" : "0";
306 $variables['autoStart'] = $autoplay ? '1' : '0';
307
308 $variables['bw'] = variable_get('video_cck_yahoomusic_bandwidth', '');
309 $variables['eh'] = variable_get('video_cck_yahoomusic_event_handler', '');
310 $variables['closeEnable'] = variable_get('video_cck_yahoomusic_close_enable', 0);
311 $variables['controlsEnable'] = variable_get('video_cck_yahoomusic_controls_enable', 1);
312 $variables['infoEnable'] = variable_get('video_cck_yahoomusic_info_enable', 1);
313
314 $variables['nowplayingEnable'] = variable_get('video_cck_yahoomusic_now_playing_enable', 1);
315 $variables['postpanelEnable'] = variable_get('video_cck_yahoomusic_post_panel_enable', 1);
316 $variables['prepanelEnable'] = variable_get('video_cck_yahoomusic_pre_panel_enable', 1);
317 $variables['shareEnable'] = variable_get('video_cck_yahoomusic_share_enable', 1);
318 $bgcolor = variable_get('video_cck_yahoomusic_bgcolor', EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT);
319
320 foreach ($variables as $name => $value) {
321 if ($value !== '') {
322 // Add to flashvars string.
323 if ($name == 'id') {
324 $flash_vars = $name . '=' . $value;
325 }
326 else {
327 $flash_vars .= '&' . $name . '=' . $value;
328 }
329 }
330 else {
331 // Remove from variables array
332 unset($variables[$name]);
333 }
334 }
335
336 $id = isset($options['id']) ? $options['id'] : 'video-cck-yahoomusic-flash-'. (++$count);
337 $div_id = isset($options['div_id']) ? $options['div_id'] : 'video-cck-yahoomusic-flash-wrapper-'. $count;
338 $url = "http://d.yimg.com/cosmos.bcst.yahoo.com/up/fop/embedflv/swf/fop.swf";
339
340 if (variable_get('emfield_swfobject', FALSE) && (module_exists('swfobject_api') || variable_get('emfield_swfobject_location', ''))) {
341 if (module_exists('swfobject_api')) {
342 $params['width'] = $width;
343 $params['height'] = $height;
344 $params['div_id'] = $id;
345 $params['allowFullScreen'] = $fullscreen_value;
346 $params['bgcolor'] = $bgcolor;
347 $output .= theme('swfobject_api', $url, $params, $variables, $id);
348 }
349 else {
350 drupal_add_js(variable_get('emfield_swfobject_location', ''));
351 $output .= <<<FLASH
352 <div id="$div_id">
353 Sorry, you need to install flash to see this content.
354 </div>
355 <script type="text/javascript">
356 var so = new SWFObject('$url', '$id', '$width', '$height', '9', '#ffffff');
357
358 FLASH;
359 foreach ($variables as $name => $value) {
360 $output .= "so.addVariable($name, '$value');\n";
361 }
362 $output .= <<<FLASH
363 so.addParam("allowFullScreen", "$fullscreen_value");
364 so.addParam("bgcolor", "$bgcolor");
365 so.addParam("allowScriptAccess", "always"); // for scripting access
366 so.write("$div_id");
367 </script>
368 FLASH;
369 }
370 }
371 else {
372 $output .= <<<FLASH
373 <div id="$div_id">
374 <object height="$height" width="$width" type="application/x-shockwave-flash" data="$url" id="$id" style="visibility: visible;">
375 <param name="div_id" value="$div_id"/>
376 <param name="allowFullScreen" value="$fullscreen_value"/>
377 <param name="type" value="movie"/>
378 <param name="flashvars" value="$flash_vars"/>
379 <param name="bgcolor" value="$bgcolor"/>
380 </object>
381 </div>
382 FLASH;
383 }
384 }
385 return $output;
386 }
387
388 /**
389 * hook video_cck_PROVIDER_thumbnail
390 * returns the external url for a thumbnail of a specific video
391 * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
392 * @param $field
393 * the field of the requesting node
394 * @param $item
395 * the actual content of the field from the requesting node
396 * @return
397 * a URL pointing to the thumbnail
398 */
399 function video_cck_yahoomusic_thumbnail($field, $item, $formatter, $node, $width, $height) {
400 $yahoomusic_id = $item['value'];
401
402 $locale = _video_cck_yahoomusic_locale_lookup();
403 $tn = "http://d.yimg.com/img.music.yahoo.com/image/v1/video/$yahoomusic_id;encoding=jpg;size=" . $width . 'x' .$height . ";locale=$locale;";
404
405 // if we have a large thumbnail size, then get the largest version available.
406 if ($width > 385 || $height > 231) {
407 $tn = "http://d.yimg.com/img.music.yahoo.com/image/v1/video/$yahoomusic_id;encoding=jpg;locale=$locale;";
408 }
409
410 return $tn;
411 }
412
413 /**
414 * hook video_cck_PROVIDER_video
415 * this actually displays the full/normal-sized video we want, usually on the default page view
416 * @param $embed
417 * the video code for the video to embed
418 * @param $width
419 * the width to display the video
420 * @param $height
421 * the height to display the video
422 * @param $field
423 * the field info from the requesting node
424 * @param $item
425 * the actual content from the field
426 * @return
427 * the html of the embedded video
428 */
429 function video_cck_yahoomusic_video($embed, $width, $height, $field, $item, $autoplay) {
430 $output = theme('video_cck_yahoomusic_flash', $embed, $width, $height, $autoplay);
431 return $output;
432 }
433
434 /**
435 * hook video_cck_PROVIDER_video
436 * this actually displays the preview-sized video we want, commonly for the teaser
437 * @param $embed
438 * the video code for the video to embed
439 * @param $width
440 * the width to display the video
441 * @param $height
442 * the height to display the video
443 * @param $field
444 * the field info from the requesting node
445 * @param $item
446 * the actual content from the field
447 * @return
448 * the html of the embedded video
449 */
450 function video_cck_yahoomusic_preview($embed, $width, $height, $field, $item, $autoplay) {
451 $output = theme('video_cck_yahoomusic_flash', $embed, $width, $height, $autoplay);
452 return $output;
453 }

  ViewVC Help
Powered by ViewVC 1.1.2