function video_cck_livestream_data in Embedded Media Field 5
hook emfield_PROVIDER_data
provides an array to be serialised and made available with $item elsewhere
1 call to video_cck_livestream_data()
- video_cck_livestream_rss in contrib/
video_cck/ providers/ livestream.inc
File
- contrib/
video_cck/ providers/ livestream.inc, line 97 - This include processes livestream.com media files for use by emfield.module.
Code
function video_cck_livestream_data($field, $item) {
$data = array();
// create some 'field' version control
$data['video_cck_livestream_version'] = 2;
// Thumbnail creation
// The links from the RSS 2.0 API contain ondemand in the video string
// So we need to handle that seperatly
// Explodes mychannel?..&clip=videoID into parts
$boom = explode('?', $item['value']);
$channel = $boom[0];
if (strpos(strtolower($item['value']), 'clip') !== false) {
preg_match('/clip=([^&]+)/', $item['value'], $matches);
// Example API 2.0 call : http://xMYCHANNELNAMEx.channel-api.livestream-api.com/2.0/thumbnail?id=VIDEOID
$api_url = 'http://x' . $channel . 'x.channel-api.livestream-api.com/2.0/clipdetails?id=' . $matches[1];
// Get the thumbnail via an API 2.0 call
$result = drupal_http_request($api_url);
if ($result->code == 200) {
$parser = drupal_xml_parser_create($result->data);
$vals = array();
$index = array();
xml_parse_into_struct($parser, $result->data, $vals);
xml_parser_free($parser);
if (count($vals)) {
foreach ($vals as $val) {
if ($val['tag'] == 'MEDIA:THUMBNAIL') {
$data['thumbnail']['url'] = $val['attributes']['URL'];
}
elseif ($val['tag'] == 'MEDIA:CONTENT') {
$data['duration'] = $val['attributes']['DURATION'];
}
}
}
}
}
else {
// live URL (thumbnail will change while stream progresses)
$data['thumbnail']['url'] = 'http://thumbnail.api.livestream.com/thumbnail?name=' . $channel;
}
// gather info about the item
// RSS / MRSS feeds with the item would have enough info
// alternative try getting the minimum from an http get
$url = 'http://www.livestream.com/' . $item['value'];
$response = emfield_request_header('livestream', $url);
if ($response->code == 200) {
// probably shouldn't give the 303 path
$data['flash']['url'] = $url;
$data['flash']['size'] = $response->headers['Content-Length'];
$data['flash']['mime'] = $response->headers['Content-Type'];
}
return $data;
}