Respect Timestamps in YouTube Embeds
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:
(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
code tags. In fact any fancy-formatting thing should do that. Vanilla shouldn't try to change URLs inside of
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
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.
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.