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('&', $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
Comment #1
tvalimaa CreditAttribution: tvalimaa commentedMy 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);
}
Comment #4
minnur CreditAttribution: minnur at Chapter Three commentedI manually added this to D8 version. Creating a patch for D7 would be great.
Comment #5
DamienMcKennaThis needs to be ported to the 7.x-3.x branch.
Comment #7
minnur CreditAttribution: minnur at Chapter Three commentedComment #8
minnur CreditAttribution: minnur at Chapter Three commented