function emvideo_google_data in Embedded Media Field 6
Same name and namespace in other branches
- 6.3 contrib/emvideo/providers/google.inc \emvideo_google_data()
hook emfield_PROVIDER_data
provides an array to be serialised and made available with $item elsewhere
3 calls to emvideo_google_data()
- emvideo_google_duration in contrib/
emvideo/ providers/ google.inc - hook emvideo_PROVIDER_duration($item) Returns the duration of the video in seconds.
- emvideo_google_rss in contrib/
emvideo/ providers/ google.inc - emvideo_google_thumbnail in contrib/
emvideo/ providers/ google.inc
File
- contrib/
emvideo/ providers/ google.inc, line 103 - This include processes Google.com media files for use by emfield.module
Code
function emvideo_google_data($field, $item) {
$data = array();
// Create some 'field' version control.
$data['emvideo_data_version'] = EMVIDEO_GOOGLE_DATA_VERSION;
$rss = emvideo_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'] == '' && is_array($rss['ITEM'])) {
// 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('emvideo_google_domain', EMVIDEO_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;
}