Hello!
As you know there is the feature for YT videos to embed clips with time marker to start from exact moment.
The syntax is:
<iframe width="560" height="315" src="//www.youtube.com/embed/aJorITEWCWk?start=250" frameborder="0" allowfullscreen></iframe>
Where ?start=250 - seconds from the beginning.

So i made some changes in video_filter.codecs.inc

for the codec:

 $codecs['youtube'] = array(
    'name' => t('YouTube'),
    'sample_url' => 'http://www.youtube.com/uN1qUeId/250',
    'callback' => 'video_filter_youtube',
    'html5_callback' => 'video_filter_youtube_html5',
    'regexp' => array(
      '/youtube\.com\/watch\?v=([a-z0-9\-_]+)(\/([a-z0-9]+))/i',
      '/youtu.be\/([a-z0-9\-_]+)/i',
      '/youtube\.com\/v\/([a-z0-9\-_]+)/i',
    ),
    'ratio' => 16 / 9,
    'control_bar_height' => 25,
  );

and callback example

function video_filter_youtube_html5($video) {
  $attributes = array(
    'rel' => $video['related'] ? 'rel=1' : 'rel=0',
    'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
    'start' => $video['codec']['matches'][2]  ? 'start='.$video['codec']['matches'][2] : '',
    'wmode' => 'wmode=opaque',
  );
  $video['source'] = 'http://www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);

  return video_filter_iframe($video);
}

Now i can add code like this:
[video:https://www.youtube.com/watch?v=aJorITEWCWk/250]
and it working

But if i use [video:https://www.youtube.com/watch?v=aJorITEWCWk] (without /250) - it is not working of course.
So this is the problem because it is not very comfortable to use "/1" all the time an change all existing videos.

Please help.

Comments

tvalimaa’s picture

My fast fix for this. This is not perfect but it work. I use youtube share link t= param to this example https://youtu.be/xxxxxx?t=2m20s

function video_filter_youtube_html5($video) {
$attributes = array(
'rel' => $video['related'] ? 'rel=1' : 'rel=0',
'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
'wmode' => 'wmode=opaque',
);
preg_match('/t=((\d+m)?(\d+[s]?)?)/', $video['source'], $matches);
if(sizeOf($matches) > 0) {
$attributes['start'] = 'start='.(preg_replace("/[^0-9]/","",$matches[2]) * 60 + (preg_replace("/[^0-9]/","",$matches[3])));
}
$video['source'] = '//www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&', $attributes);

return video_filter_iframe($video);
}

  • minnur committed 9595dfa on 8.x-1.x
    Issue #2361429: Add support for time markers in Youtube plugin.
    

  • minnur committed 8e5b0f9 on 8.x-1.x
    Issue #2361429 by errand, tvalimaa: Add support for time markers in...
minnur’s picture

Status: Active » Needs work

I manually added this to D8 version. Creating a patch for D7 would be great.

DamienMcKenna’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Needs work » Patch (to be ported)

This needs to be ported to the 7.x-3.x branch.

  • minnur committed 4c0ef06 on 7.x-3.x
    Issue #2361429 by errand, tvalimaa: Add time marker support.
    
minnur’s picture

Status: Patch (to be ported) » Fixed
minnur’s picture

Status: Fixed » Closed (fixed)