Hi all, could someone help to add the youtu.be domain?
Considering the new code for the new features of the 7.x-2.x version, should we add a new regex+embed section or create a new structure?


fenda’s picture

It would be cool if there was a easy UI way to add custom video embed URLs.

For example:

1) Admin adds a regexp for their video URL (e.g. youtu.be/[video_id]) etc
2) Admin adds the code used for embedding (e.g.

) This way admins can add video embed compatibility for any website easily.
Luch’s picture

What is Youtu.be?
When I type www.youtu.be is the addressbar of my browser the only thing that happens is a link to "http://www.youtube.com/index?feature=youtu.be".

fenda’s picture

Take a look at the share URL beneath a youtube video.

alexandreracine’s picture

Watch this video : http://www.youtube.com/watch?v=bNB9Mepi1VI&feature=youtu.be
Hit the Share button and youtube will suggest : http://youtu.be/bNB9Mepi1VI


I think #1 drupaljoe could be an interesting solution. It could be simply a list of video formats, containing 3 fields : "Online video service name", "regex source", "embeded code".

On the user side, he would see nothing more and no annoying tags, witch is my #1 concern.

On the admin side, he would have all videos by default that we would add to the core of googtube (Youtube, vimeo, youtu.be, etc) but could add more, and best, share the solution in the feature request so we could add it to the googtube filter if it is a good online video website.

Programming the thing, the code already have some tags now thanks to Luch with the video size.
But this would require some database upgrade for our module if I am not mistaken.

If someone post something, I could test the new 7.x module.

benlotter’s picture

I had already worked out the regex for youtu.be some time ago and I posted my solution here (http://drupal.org/node/1331380#comment-5556654). Unfortunately, I had posted it alongside a solution to add iFrame capability which was implemented and closed. I'll go ahead repost the solution here, though I have not modified it or tested it for the newer versions. Mine solution was for 6.x.1.

benlotter’s picture

From my comment (http://drupal.org/node/1331380#comment-5556654), here is my regex for the new youtube links. Be sure to read the whole comment to see the other changes I made at that time, but I think this is all you would need.

        //youtube shortened regex
      $text = preg_replace_callback('#(((http://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)(?![^<]*</a>)#i', 'googtube_youtube_short', $text);
alexandreracine’s picture

Title: New youtube url to youtu.be » Adding urls one by one or changing the infrastructure for flexibility? Was ((New youtube url to youtu.be))

Changed the title.

Thanks benlotter, we will look at that.

Nathaniel’s picture

Using these snippets for now (note - I am using the Drupal 6 version, it looks like 7 is similar though):

Added around line 47 (D7 around 141).

      //youtu.be regex
      if (preg_match_all('#(((http://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)(?![^<]*</a>)#i', $text, $matches)) {
        foreach ($matches[9] as $mi => $match) {
          $replace = googtube_youtube($match, $filter, $match);
          $text = str_replace($matches[0][0], $replace, $text);

And updated around line 160 - 164 (D7 around 153).

function googtube_youtube($match, $format, $youtube_id = NULL) {
  if (empty($youtube_id)) {
    // extract id from complete url
    $parsed_url = parse_url($match);
    parse_str(decode_entities($parsed_url['query']), $parsed_query);
    $youtube_id = $parsed_query['v'];

Needs further testing.

benlotter’s picture

By the way, I've now switched to using the Shortcode module because it give me flexibility to insert videos, images, tables, buttons, etc. with a short code snippet and integrate them into my theme exactly how I want.

In addition to Shortcode (which has limited video support), I'm using the custom code below which gives me control over every aspect of the video display.

function mytheme_helper_tags_youtube( $attrs, $text = null ) {
	'url' 		=> false,
	'width' 	=> '',
	'height' 	=> '',
	'autohide'  => '1',
	'autoplay'  => '0',
	'controls'  => '1',
	'disablekb' => '1',
	'fs'        => '0',
	'hd'        => '0',
	'loop'      => '0',
	'modestbranding'	=> '1',
	'rel'       => '0',
	'showsearch'=> '0',
	'showinfo'  => '',
	'style'  		=> false,// @todo
	'theme'		=> 'light',
	'title'		=> '',
	'vq'		=> '',
	'responsive' => true,
	'class'  		=> '',
	), $attrs));
	if(!$url) {
		return t( 'Please enter the url to a YouTube video.');

	$classes = !empty($class) && !empty($class) ? explode(' ', $class) : array();
	$classes[] = 'video_frame';
	$classes[] = $responsive ? 'responsive' : null;
	$classes = trim(implode(' ', $classes));
	if (preg_match( '/^http\:\/\/(?:(?:[a-zA-Z0-9\-\_\.]+\.|)youtube\.com\/watch\?v\=|youtu\.be\/)([a-zA-Z0-9\-\_]+)/i', $url, $matches ) > 0) {
		$video_id = $matches[1];
	} elseif (preg_match('/^([a-zA-Z0-9\-\_]+)$/i', $url, $matches ) > 0) {
		$video_id = $matches[1];

	if(!isset($video_id)) {
		return t('There was an error retrieving the YouTube video ID for the url you entered, please verify that the url is correct.');

	$width = ( !empty( $width ) ) ? trim(str_replace(' ', '', str_replace('px', '', $width ) ) ) : glossy_helper_get_theme_setting('default_vid_width', '866');
	$height = ( !empty( $height ) ) ? trim(str_replace(' ', '', str_replace('px', '', $height ) ) ) : glossy_helper_get_theme_setting('default_vid_height', '480');;

	$_video_id = gen_unique_id(10);
	$allowfullscreen = ($fs=='1') ? 'allowfullscreen' : '';
	return "<div class='$classes'><iframe id='youtube_video_$_video_id' class='youtube_video' src='http://www.youtube.com/embed/{$video_id}?modestbranding={$modestbranding}&amp;rel={$rel}&amp;autohide={$autohide}&amp;autoplay={$autoplay}&amp;controls={$controls}&amp;disablekb={$disablekb}&amp;fs={$fs}&amp;hd={$hd}&amp;vq={$vq}&amp;loop={$loop}&amp;showinfo={$showinfo}&amp;showsearch={$showsearch}&amp;title={$title}&amp;theme={$theme}&amp;wmode=transparent&amp;enablejsapi=1' width='{$width}' height='{$height}' frameborder='0' {$allowfullscreen}></iframe></div>";


You can see that I set everything to a default so I only have to passing in the parameters that I want to override.
Here's what I do in the teaser,
[youtube url="http://www.youtube.com/watch?v=rVjohTx4L4E" vq="large"][/youtube]
and here's what I do in the full node.
[youtube url="http://www.youtube.com/watch?v=rVjohTx4L4E" autoplay="1" vq="hd720"][/youtube]

Notice I could up the quality and have it autoplay when someone clicks on the node. Also my theme is responsive so it will automatically change the width and height of the video depending on the size of the browser or screen.

Since I'm abandoning this module, I will no longer be following this issue. If you wish to contact regarding more specifics of my solution, please use the contact link on my profile. Also, here is link to the working solution on my site. Benjamin Lotter - demo videos

ky_metro’s picture

Will Googtube be supporting youtu.be links then? The snippets above are not working for me.

Alexandreracine said "we will look into it" back in September - did anything come of it?

alexandreracine’s picture

benlotter : The goal of googtube is to embed WITHOUT tags, not with tags. Hate those tags.

ky_metro : I need at least two persons that tells me "the code in comment #X works for me" and I'll create a new version with this functionnality. Thanks!

jalves’s picture

Tested #8 in D6 without success.. is it working Nathaniel?

Laura Davila’s picture

Hah. I love being kind of smart sometimes.

Here's what worked for me, at least with Drupal 7:

At around line 141 in function _googtube_process, I added something similar to what Nathaniel added...

//youtu.be regex
  if (preg_match_all('#(((http://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)(?![^<]*</a>)#i', $text, $matches)); {
    foreach ($matches[0] as $mi => $match) {
      $replace = googtube_youtube($match, $filter);
      $text = str_replace($match, $replace, $text);

But I was having trouble with his second part. So, my workaround in affecting the googtube_youtube function was this addition at what becomes line 164, just under the $parsed_url delcaration. I put the code in context, but I'll add a comment line above and below my addition

function googtube_youtube($match, $filter) {
  // extract id from complete url
  $parsed_url = parse_url(check_url($match));
	 $youtube_id = str_replace('/', '', $parsed_url['path']);
  parse_str($parsed_url['query'], $parsed_query);
  $youtube_id = $parsed_query['v'];
//Rest of the code is the same
  $headers = get_headers("http://gdata.youtube.com/feeds/api/videos/" . $youtube_id);

Hope this helps some of you :)

ky_metro’s picture

The code in #13 works great for me, running 7.19 on a test site. Thanks Laura Davila!

Can someone else confirm this too so alexandreracine can add it to the module?

ky_metro’s picture

Issue summary: View changes

It's been a year now, and my patched implementation is still working great. Please, I need someone to confirm this patch, anybody?