function video_cck_google_data in Embedded Media Field 5
hook emfield_PROVIDER_data
provides an array to be serialised and made available with $item elsewhere
2 calls to video_cck_google_data()
- video_cck_google_rss in contrib/
video_cck/ providers/ google.inc - video_cck_google_thumbnail in contrib/
video_cck/ providers/ google.inc
File
- contrib/
video_cck/ providers/ google.inc, line 90
Code
function video_cck_google_data($field, $item) {
$data = array();
// create some 'field' version control
//$data['video_cck_google_version'] = 1;
$rss = video_cck_google_request($item['value']);
if (is_array($rss['ITEM']) && is_array($rss['ITEM']['MEDIA:GROUP']) && is_array($rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT']) && is_array($rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT'][1])) {
$video = $rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT'][1];
$data['filepath'] = $video['URL'];
$data['filemime'] = $video['TYPE'];
$data['medium'] = $video['MEDIUM'];
$data['expression'] = $video['EXPRESSION'];
$data['duration'] = $video['DURATION'];
$data['width'] = $video['WIDTH'];
$data['height'] = $video['HEIGHT'];
}
if (is_array($rss['MEDIA:GROUP'])) {
if (is_array($rss['MEDIA:GROUP']['MEDIA:THUMBNAIL']) && is_array($rss['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1])) {
$thumbnail = $rss['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1];
$data['thumbnail']['filepath'] = $thumbnail['URL'];
$data['thumbnail']['width'] = $thumbnail['WIDTH'];
$data['thumbnail']['height'] = $thumbnail['HEIGHT'];
}
if (is_array($rss['MEDIA:GROUP']['MEDIA:PLAYER']) && is_array($rss['MEDIA:GROUP']['MEDIA:PLAYER'][1])) {
$data['player']['filepath'] = $rss['MEDIA:GROUP']['MEDIA:PLAYER'][1]['URL'];
}
}
if ($data['thumbnail']['filepath'] == '') {
// for whatever reason the thumbnail failed try the old method
// we'll parse it from the description, where it's repeated.
$desc = $rss['ITEM']['DESCRIPTION'][0];
$regex = '@<img src="([^"]*)"@';
if (preg_match($regex, $desc, $matches)) {
$data['thumbnail']['filepath'] = $matches[1];
}
}
// google rss doesn't actually have <embeded> media, just MRSS, and no size
// so not actually really really necessary or really useful but for completeness
$play = 'http://video.google.' . variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT) . '/googleplayer.swf?docId=' . check_plain($item['embed']);
$response = emfield_request_header('google', $play, FALSE, FALSE);
if ($response->code == 200) {
$data['filesize'] = $response->headers['Content-Length'];
}
return $data;
}