A Better YouTube custom BBcode

page_php_128A forum that I consult to ( SimHQ ), recently informed me that YouTube has changed the URL format for when you click the “Share” Link below the video. It no longer matches the URL in the address bar and this was causing some confusion.

The URL in the address bar is the still the familiar one that links to youtube.com, adding the ?v=xxxx parameter as always, but the Share link has gone a different way now.

Namely, YouTube decided to use “http://youtu.be/kXRSZSxXB9g” for example.

This, of course broke any existing BBcode regexes that UBB.Threads had in place and simply didn’t parse if the user used the URL generated from the “Share” button.

Quandary, you say?

I looked at the resulting embed code and it is the same as before, so the regex simply needs to be updated to handle both cases; old and new.

For UBB.threads forum admins, go to your Control Panel, Content Tools and Custom Tag Editor ( shown below ):

Click to see Full size

The only line that needs to be modified is the Matching regex:


(|.*youtu\.be/|.*v=)([a-zA-Z0-9_-]{8,12})(|&.*)

and you are good to go.

You can double click on the regex above and the line will be automatically selected. You can then copy it and paste it into your UBB.threads admin BBcode edit window.

Just a note on the regex. It actually parses three different types:

  • YouTube URL from address bar: http://www.youtube.com/watch?v=JOddp-nlNvQ&feature=grec_index
  • YouTube from “Share”: http://youtu.be/JOddp-nlNvQ
  • YouTube ID: JOddp-nlNvQ

All three produce the same embed code and a case in point would be:

[yt]http://youtu.be/JOddp-nlNvQ[/yt]

produces:

You can also just download the entire custom text file below and import it, so as to play with it separately before enabling. I used the ‘yt’ tag, instead of what you may be more familiar with ‘video:youtube‘. Typing [yt] seems much easier for my forum members anyway! ;)

txtYoutube Custom BBcode for Import - v1.1 - Downloaded 1060 times

Enjoy

Comments are closed.