diff --git a/includes/media_youtube.admin.inc b/includes/media_youtube.admin.inc index 5149c75..70e68f0 100644 --- a/includes/media_youtube.admin.inc +++ b/includes/media_youtube.admin.inc @@ -117,6 +117,20 @@ function media_youtube_admin_form() { '#description' => t("If checked, additional info, such as title and rating, will NOT be displayed on the YouTube player."), ); + $form['player']['player_options'][media_youtube_variable_name('https_enabled')] = array( + '#type' => 'checkbox', + '#title' => t('Enable HTTPS'), + '#default_value' => media_youtube_variable_get('https_enabled'), + '#description' => t("If checked, the embedded video player will encrypt the video playback."), + ); + + $form['player']['player_options'][media_youtube_variable_name('privacy_enabled')] = array( + '#type' => 'checkbox', + '#title' => t('Enable privacy-enhanced mode'), + '#default_value' => media_youtube_variable_get('privacy_enabled'), + '#description' => t("If checked, the embedded video player will not set a cookie on the users computer."), + ); + $form['player']['player_options'][media_youtube_variable_name('html5_player')] = array( '#type' => 'checkbox', '#title' => t('Use the HTML5 player instead of the Flash-based'), diff --git a/includes/media_youtube.variables.inc b/includes/media_youtube.variables.inc index 0490cda..ba5cb8a 100644 --- a/includes/media_youtube.variables.inc +++ b/includes/media_youtube.variables.inc @@ -15,6 +15,16 @@ define('MEDIA_YOUTUBE_NAMESPACE', 'media_youtube__'); define('MEDIA_YOUTUBE_MAIN_URL', 'http://youtube.com/'); /** + * This is the main playback URL for YouTube. + */ +define('MEDIA_YOUTUBE_PLAYBACK_HOST', 'www.youtube.com/'); + +/** + * This is the main privacy playback URL for YouTube. + */ +define('MEDIA_YOUTUBE_PRIVACY_HOST', 'www.youtube-nocookie.com/'); + +/** * This is the URL to the API of YouTube. */ define('MEDIA_YOUTUBE_API_INFO', 'http://code.google.com/apis/youtube/getting_started.html'); diff --git a/media_youtube.module b/media_youtube.module index 7409737..65cc846 100644 --- a/media_youtube.module +++ b/media_youtube.module @@ -248,12 +248,28 @@ function media_youtube_media_mover($op = NULL, $action = NULL, $configuration = * @return string * The direct URL to the video in question. */ -function media_youtube_video_url($id) { +function media_youtube_video_url($id, $fallback = FALSE) { + if (media_youtube_variable_get('https_enabled')) { + $protocol = 'https://'; + } + else { + $protocol = 'http://'; + } + if (strpos($id, 'PLAYLIST_') === 0) { // This is a youtube playlist. - return 'http://youtube.com/p/'. substr($id, 9); + return $protocol . MEDIA_YOUTUBE_PLAYBACK_HOST . 'p/'. substr($id, 9); + } + if (media_youtube_variable_get('privacy_enabled') == TRUE) { + $domain = $protocol . MEDIA_YOUTUBE_PRIVACY_HOST; + $watch = ''; } - return url('http://www.youtube.com/watch', array('query' => 'v='. $id)); + else { + $domain = $protocol . MEDIA_YOUTUBE_PLAYBACK_HOST; + $watch = 'watch'; + } + $url = $fallback?$domain . "v/$id":url($domain . $watch, array('query' => 'v='. $id)); + return $url; } /** @@ -536,13 +552,20 @@ function media_youtube_emfield_data($video_id) { // Store the video's duration. $data['duration'] = intval($raw['MEDIA:GROUP']['YT:DURATION'][1]['SECONDS']); + if (media_youtube_variable_get('https_enabled')) { + $protocol = 'https://'; + } + else { + $protocol = 'http://'; + } + // Gather info about the item's raw flash video. // RSS / MRSS feeds with the item would have enough info. // Alternatively try getting the minimum from an HTTP get. // Get info from a youtube playlist. if (strpos($video_id, 'PLAYLIST_') === 0) { $playlist_id = substr($video_id, 9); - $url = 'http://youtube.com/p/'. $playlist_id; + $url = $protocol . MEDIA_YOUTUBE_PLAYBACK_HOST . 'p/'. $playlist_id; $data['playlist'] = 1; // Get the large thumbnail of the first video. @@ -567,7 +590,9 @@ function media_youtube_emfield_data($video_id) { } // Get info from a single video. else { - $url = 'http://youtube.com/v/'. $video_id; + $url = $protocol; + $url .= media_youtube_variable_get('privacy_enabled') ? MEDIA_YOUTUBE_PRIVACY_HOST : MEDIA_YOUTUBE_PLAYBACK_HOST; + $url .= 'v/'. $video_id; $data['playlist'] = 0; // Get the large thumbnail. $data['thumbnail']['url'] = 'http://img.youtube.com/vi/'. $video_id .'/0.jpg'; diff --git a/providers/emvideo/youtube.inc b/providers/emvideo/youtube.inc index 8f365b1..e008886 100644 --- a/providers/emvideo/youtube.inc +++ b/providers/emvideo/youtube.inc @@ -26,6 +26,8 @@ function emvideo_youtube_info() { array(t('Status'), t('Yes'), t('Stores video status (available and unavailable).')), array(t('Custom player colors'), t('Yes'), t("You may customize the player's skin by choosing your own colors, and/or border in that setting field set.")), 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.')), + array(t('HTTPS mode'), t('Yes'), t('Use HTTPS in embed code. It is important to note that while embed components are all supported using HTTPS and do not generate the mixed content error, we do not yet support video streams over HTTPS.')), + array(t('Privacy-enhanced mode'), t('Yes'), t('You may disable player-set cookies. Additionally, any personally-identifiable data will not be stored by YouTube. Privacy-enhanced mode is disabled by default.')), array(t('Use JW FLV Media Player'), t('Yes'), t("You may opt to use the !flvplayer to play YouTube videos if it's installed on your server.", array('!flvplayer' => l(t('JW FLV Media Player'), 'http://www.longtailvideo.com/players/jw-flv-player/')))), ); return array( @@ -33,7 +35,7 @@ function emvideo_youtube_info() { 'provides' => array('emvideo'), 'provider' => 'youtube', 'name' => t('YouTube'), - 'url' => MEDIA_YOUTUBE_MAIN_URL, + 'url' => media_youtube_variable_get('privacy_enabled') ? MEDIA_YOUTUBE_PRIVACY_HOST : MEDIA_YOUTUBE_PLAYBACK_HOST, 'settings_description' => t('These settings specifically affect videos displayed from YouTube. You can learn more about its API here.', array('@youtube' => MEDIA_YOUTUBE_MAIN_URL, '@api' => MEDIA_YOUTUBE_API_INFO)), 'supported_features' => $features, ); @@ -119,11 +121,18 @@ function emvideo_youtube_extract($video_id = '') { // http://www.youtube.com/watch?v=YzFCA-xUc8w&feature=dir // src="http://www.youtube.com/embed/kge8zlJfwQQ" // http://youtu.be/bh-BwFNNAGc + // and the privacy options + // src="http://www.youtube-nocookie.com/v/nvbQQnvxXDk" + // http://youtube-nocookie.com/watch?v=nvbQQnvxXDk + // http://www.youtube-nocookie.com/watch?v=YzFCA-xUc8w&feature=dir return array( '@youtube\.com/(?:v|embed)/([^"\&\? ]+)@i', '@youtube\.com/watch\?v=([^"\& ]+)@i', '@youtube\.com/\?v=([^"\& ]+)@i', '@youtu.be/([^"\& ]+)@i', + '@youtube-nocookie\.com/v/([^"\&\? ]+)@i', + '@youtube-nocookie\.com/watch\?v=([^"\& ]+)@i', + '@youtube-nocookie\.com/\?v=([^"\& ]+)@i', ); } diff --git a/themes/media_youtube.theme.inc b/themes/media_youtube.theme.inc index b7829f4..8f4e900 100644 --- a/themes/media_youtube.theme.inc +++ b/themes/media_youtube.theme.inc @@ -49,7 +49,7 @@ function template_preprocess_media_youtube_html5(&$variables) { $variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_youtube_variable_get('autoplay'); $variables['autoplay'] = $variables['autoplay'] ? '1' : '0'; - $variables['url'] = "http://www.youtube.com/embed/{$variables['video_id']}"; + $variables['url'] = media_youtube_video_url($variables['video_id']); $variables['query_defaults'] = array( 'autoplay' => $variables['autoplay'], 'rel' => $variables['related'], @@ -69,12 +69,12 @@ function template_preprocess_media_youtube_default_external(&$variables) { $variables['flashvars'] = drupal_query_string_encode(array('playerMode' => 'embedded')); $video_id = $variables['video_id']; - $variables['url'] = isset($variables['url']) ? $variables['url'] : "http://www.youtube.com/v/$video_id"; + $variables['url'] = isset($variables['url']) ? $variables['url'] : media_youtube_video_url($video_id, TRUE); $variables['url'] = check_plain($variables['url']); $variables['width'] = check_plain($variables['width']); $variables['height'] = check_plain($variables['height']); $variables['fullscreen_value'] = check_plain($variables['fullscreen_value']); - $variables['thumbnail'] = isset($variables['thumbnail']) ? $variables['thumbnail'] : theme('emvideo_video_thumbnail', $variables['field'], array('value' => $video_id, 'provider' => 'youtube'), 'thumbnail', $variables['node'], FALSE, array('width' => $variables['width'], 'height' => $variables['height'], 'link_url' => media_youtube_video_url($video_id))); + $variables['thumbnail'] = isset($variables['thumbnail']) ? $variables['thumbnail'] : theme('emvideo_video_thumbnail', $variables['field'], array('value' => $video_id, 'provider' => 'youtube'), 'thumbnail', $variables['node'], FALSE, array('width' => $variables['width'], 'height' => $variables['height'], 'link_url' => media_youtube_video_url($video_id, TRUE))); } /** @@ -182,12 +182,12 @@ function template_preprocess_media_youtube_flash(&$variables) { // Create a URL from our options. if ($variables['item']['data']['playlist']) { $video_id = substr($video_id, 9); - $url = check_plain("http://www.youtube.com/p/$video_id&$related$autoplay_value$colors$border$high_quality$display_info$enablejsapi$fs"); + $url = check_plain(media_youtube_video_url($video_id) . "&$related$autoplay_value$colors$border$high_quality$display_info$enablejsapi$fs"); // FLV Player doesn't support playlists, so we need to fall back. $variables['use_flv'] = FALSE; } else { - $url = check_plain("http://www.youtube.com/v/$video_id&$related$autoplay_value$colors$border$high_quality$display_info$enablejsapi$fs"); + $url = check_plain(media_youtube_video_url($video_id, TRUE) . "&$related$autoplay_value$colors$border$high_quality$display_info$enablejsapi$fs"); } // Find the path to the JW FLV Media Player.