HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Respect Timestamps in YouTube Embeds

edited February 2012 in Feedback

I think the YouTube embed feature of Vanilla is pretty cool. The problem is that it doesn't respect timestamps at all. If someone posts a YouTube URL with a specific video time in it, Vanilla embeds it like a normal video, which causes the viewer to start playing from the beginning. That defeats the purpose of posting a link with a particular time in it.

YouTube URLs with timestamps look like this:

https://www.youtube .com/watch?v=GokKUqLcvD8#t=1m19s

(I'm not sure what the best way is to make Vanilla ignore a YouTube URL. I just added a space between "youtube" and ".com" to do it here. But this also raises another point: the embed thingy should ignore all YouTube URLs inside of pre or code tags. In fact any fancy-formatting thing should do that. Vanilla shouldn't try to change URLs inside of pre or code tags into links.)

A sort of lame, but acceptable, behaviour would be to change the replacement code to ignore all YouTube links with #t in them anywhere. This is actually what I did on my Vanilla forum. I accomplished this by adding a negative look ahead to the regex pattern on line 831 in library/core/class.format.php.

preg_match('`(?!.+#t.+)(?:https?|ftp)://www\.youtube\.com\/watch\?v=([^&]+)`', $Url, $Matches)

Apparently you can specify a start time on embedded videos. This would be a much better approach.

http://www.mattcutts.com/blog/start-youtube-video-minutes-seconds/

PHP is not my language of choice, so I'm not sure what the cleanest way would be to get 1m19s out of the URL, convert it to seconds, and add it to the embed src. Hopefully some Vanilla dev could add this to the next release.

Sign In or Register to comment.