Index: contrib/emvideo/providers/livestream.inc =================================================================== --- contrib/emvideo/providers/livestream.inc (revision 0) +++ contrib/emvideo/providers/livestream.inc (revision 1872) @@ -0,0 +1,317 @@ + the translated name of the provider + * 'url' => the url to the main page for the provider + * 'settings_description' => a description of the provider that will be posted in the admin settings form + * 'supported_features' => an array of rows describing the state of certain supported features by the provider. + * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'. + */ +function emvideo_livestream_info() { + $features = array( + array(t('Autoplay'), t('Yes'), ''), + array(t('RSS Attachment'), t('No'), ''), + array(t('Show related videos'), t('No'), ''), + array(t('Thumbnails'), t('Yes'), t('')), + array(t('Custom player colors'), t('No'), ''), + 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.')), + ); + return array( + 'provider' => 'livestream', + 'name' => t('Livestream'), + 'url' => EMVIDEO_LIVESTREAM_MAIN_URL, + 'settings_description' => t('These settings specifically affect videos displayed from Livestream. You can learn more about its API here.', array('@livestream' => EMVIDEO_LIVESTREAM_MAIN_URL, '@api' => EMVIDEO_LIVESTREAM_API_INFO)), + 'supported_features' => $features, + ); +} + +/* +id=livestreamPlayer +channel=nysenate +width +height +autoPlay=true +mute=false +allowFullScreen=true +*/ + +/** + * hook emvideo_PROVIDER_settings + * this should return a subform to be added to the emvideo_settings() admin settings page. + * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['livestream']) + * so if you want specific provider settings within that field, you can add the elements to that form field. + */ +function emvideo_livestream_settings() { + $form['livestream']['api'] = array( + '#type' => 'fieldset', + '#title' => t('Livestream API'), + '#description' => t('You will first need to apply for an API Developer Key from the Livestream Developer Profile page. Note that you do not need this key to display Livestream videos or their thumbnails.', array('@livestream' => EMVIDEO_LIVESTREAM_API_APPLICATION_URL)), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['livestream']['api']['emvideo_livestream_api_key'] = array( + '#type' => 'textfield', + '#title' => t('Livestream API Key'), + '#default_value' => variable_get('emvideo_livestream_api_key', ''), + '#description' => t('Please enter your Livestream Developer Key here.'), + ); + + $form['livestream']['player_options'] = array( + '#type' => 'fieldset', + '#title' => t('Embedded video player options'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['livestream']['player_options']['emvideo_livestream_full_screen'] = array( + '#type' => 'checkbox', + '#title' => t('Allow fullscreen'), + '#default_value' => variable_get('emvideo_livestream_full_screen', 1), + '#description' => t('Allow users to view video using the entire computer screen.'), + ); + $form['livestream']['player_options']['emvideo_livestream_autoplay'] = array( + '#type' => 'checkbox', + '#title' => t('Auto play'), + '#default_value' => variable_get('emvideo_livestream_autoplay', 1), + '#description' => t('Automatically play the video when users visit its page.'), + ); + return $form; +} + +/** + * hook emfield_PROVIDER_data + * + * provides an array to be serialised and made available with $item elsewhere + */ +function emvideo_livestream_data($field, $item) { + $data = array(); + // create some 'field' version control + $data['emvideo_livestream_version'] = 1; + + // be nice to make this an array for changing media:thumbnail + // or, better yet, to retrieve it using the Livestream API + $data['thumbnail']['url'] = 'http://mogulus-channel-logos.s3.amazonaws.com/36e32d27-6ab8-998a-9644-301f39a15533-small.jpg'; + + // 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; +} + +/** + * + */ +function emvideo_livestream_rss($item, $teaser = NULL) { + if ($item['value']) { + if (!empty($item['data']['emvideo_livestream_data_version']) && $item['data']['emvideo_livestream_data_version'] >= 1) { + $data = $item['data']; + } + else { + $data = emvideo_livestream_data(NULL, $item); + } + + $file = array(); + if (is_array($data['flash'])) { + $file['filepath'] = $data['flash']['url']; + $file['filesize'] = $data['flash']['size']; + $file['filemime'] = $data['flash']['mime']; + } + $file['thumbnail']['filepath'] = $data['thumbnail']['url']; + + return $file; + } +} + +/** + * this is a wrapper for emvideo_request_xml that includes livestream's api key + */ +function emvideo_livestream_request($method, $args = array(), $cached = TRUE) { + $args['dev_id'] = trim(variable_get('emvideo_livestream_api_key', '')); + $args['method'] = $method; + $request = module_invoke('emfield', 'request_xml', 'livestream', EMVIDEO_LIVESTREAM_REST_ENDPOINT, $args, $cached); + return $request; +} + +/** + * hook emvideo_PROVIDER_extract + * this is called to extract the video code from a pasted URL or embed code. + * @param $embed + * an optional string with the pasted URL or embed code + * @return + * either an array of regex expressions to be tested, or a string with the video code to be used + * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array. + * otherwise, the calling function will handle testing the embed code against each regex string in the returned array. + */ +function emvideo_livestream_extract($embed = '') { + // http://channel.api.livestream.com/1.0/embed?channel=proshowcase + // http://www.livestream.com/proshowcase + return array( + '@livestream\.com/1.0/embed\?channel=([^"\&]+)@i', + '@www\.livestream\.com/([^"\&]+)@i', + ); +} + + +/** + * hook emvideo_PROVIDER_embedded_link($video_code) + * returns a link to view the video at the provider's site + * @param $video_code + * the string containing the video to watch + * @return + * a string containing the URL to view the video at the original provider's site + */ +function emvideo_livestream_embedded_link($video_code) { + return 'http://www.livestream.com/'. $video_code; +} + +/** + * The embedded flash displaying the livestream video. + */ +function theme_emvideo_livestream_flash($embed, $width, $height, $autoplay=TRUE, $options = array()) { + static $count; + $output = ''; + if ($embed) { + $fullscreen = isset($options['fullscreen']) ? $options['fullscreen'] : variable_get('emvideo_livestream_full_screen', 1); + $fullscreen_value = $fullscreen ? "true" : "false"; + + // This is a little funky. Essentially it ignores whatever is passed in to $autoplay and retrieves the setting or + // takes a value from the options array. Also, don't I need to convert the & into &? + $autoplay = isset($options['autoplay']) ? $options['autoplay'] : variable_get('emvideo_livestream_autoplay', 1); + $autoplay_value = $autoplay ? 'true' : 'false'; + +// $id = isset($options['id']) ? $options['id'] : 'emvideo-livestream-flash-'. (++$count); + $div_id = isset($options['div_id']) ? $options['div_id'] : 'emvideo-livestream-flash-wrapper-'. $count; + + $output .= << + + + + + + +
+ Watch + live streaming video + from + $embed + at livestream.com +
+FLASH; + } + return $output; +} + +/** + * hook emvideo_PROVIDER_thumbnail + * returns the external url for a thumbnail of a specific video + * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things + * @param $field + * the field of the requesting node + * @param $item + * the actual content of the field from the requesting node + * @return + * a URL pointing to the thumbnail + */ +function emvideo_livestream_thumbnail($field, $item, $formatter, $node, $width, $height) { + $livestream_id = $item['value']; + // Old code to grab thumbnail via API. +//$request = emvideo_livestream_request('livestream.videos.get_details', array('video_id' => $livestream_id)); +//$tn = $request['THUMBNAIL_URL'][0]; + + // For now, I've just hard-coded the URL. This should be fixed to actually retrieve the thumbnail using Livestream's API. + $tn = "http://mogulus-channel-logos.s3.amazonaws.com/36e32d27-6ab8-998a-9644-301f39a15533-small.jpg"; + + return $tn; +} + +/** + * hook emvideo_PROVIDER_video + * this actually displays the full/normal-sized video we want, usually on the default page view + * @param $embed + * the video code for the video to embed + * @param $width + * the width to display the video + * @param $height + * the height to display the video + * @param $field + * the field info from the requesting node + * @param $item + * the actual content from the field + * @return + * the html of the embedded video + */ +function emvideo_livestream_video($embed, $width, $height, $field, $item, &$node, $autoplay) { + $output = theme('emvideo_livestream_flash', $embed, $width, $height, $autoplay); + return $output; +} + +/** + * hook emvideo_PROVIDER_preview + * this actually displays the preview-sized video we want, commonly for the teaser + * @param $embed + * the video code for the video to embed + * @param $width + * the width to display the video + * @param $height + * the height to display the video + * @param $field + * the field info from the requesting node + * @param $item + * the actual content from the field + * @return + * the html of the embedded video + */ +function emvideo_livestream_preview($embed, $width, $height, $field, $item, &$node, $autoplay) { + $output = theme('emvideo_livestream_flash', $embed, $width, $height, $autoplay); + return $output; +} + +/** + * Implementation of hook_emfield_subtheme. + */ +function emvideo_livestream_emfield_subtheme() { + return array( + 'emvideo_livestream_flash' => array( + 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL), + 'file' => 'providers/livestream.inc' + ) + ); +}