-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite of youtube embed code #32
base: master
Are you sure you want to change the base?
Conversation
Followed the information in the latest youtube docs on embedding: https://developers.google.com/youtube/player_parameters?hl=en Wrote a set of regexps to parse the various formats of youtube URLs from the location bar, the share button, and the embed src under the share options, as well as some legacy URLs from the docs site. The regexps extract the video id and a string of all the other URL parameters. If the URL was for a single video the params are split out and processed to remove autoplay and to convert the &t param into the embed's &start version. They're then splatted back into a string. If the URL was for a playlist from the location bar or share button then it's split into a playlist id and params with autoplay stripped out. If the URL was a more advanced URL from the playlist embed src then it's passed through because it's already the right format, just the autoplay is removed if present. (playist embed url, user uploads list, and videos matching a search query) After all of the above the URL is then built at the end based on those various sources and stuck into an <iframe> tag that has the appropriate other settings to do the new embeds. It defaults to HTML5 player, but will fallback and handle older platforms and mobile automatically.
for ( $i = 0; $i < count($params); $i++ ) { | ||
|
||
// convert regular video URLs that use &t=200 to start at 200sec into embed url style that uses &start=200 or &start=3m20s | ||
$params[$i] = preg_replace("/\At=/i", "start=", $params[$i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Thanks Chris! I'm going to deploy this on BCO for a bit to see how things shake out before we land it. Do you want to make an issue announcing this feature? |
Tried to deploy this and ran into some trouble that I don't have time to debug right now. I'll try to dig in during the evening this week to see what's up. The board is running PHP 5.3.8, just FYI. I really need to get an Ansible dev/deployment setup rolling for this thing. |
Thanks for trying it out, I'll make a copy of my dev VM when I have a chance and try to downgrade to PHP 5.3.8 to see if I can see what the issue is |
Say, did you have any luck? |
Unfortunately I haven't had time to try to setup an alternate dev environment with the older PHP yet. Thanks for pinging on this though |
Followed the information in the latest youtube docs on embedding:
https://developers.google.com/youtube/player_parameters?hl=en
Wrote a set of regexps to parse the various formats of youtube
URLs from the location bar, the share button, and the embed src
under the share options, as well as some legacy URLs from the docs
site.
The regexps extract the video id and a string of all the other
URL parameters.
If the URL was for a single video the params are split out and
processed to remove autoplay and to convert the &t param into the
embed's &start version. They're then splatted back into a string.
If the URL was for a playlist from the location bar or share button
then it's split into a playlist id and params with autoplay stripped
out.
If the URL was a more advanced URL from the playlist embed src then
it's passed through because it's already the right format, just the
autoplay is removed if present. (playist embed url, user uploads
list, and videos matching a search query)
After all of the above the URL is then built at the end based on
those various sources and stuck into an <iframe> tag that has the
appropriate other settings to do the new embeds. It defaults to
HTML5 player, but will fallback and handle older platforms and
mobile automatically.