Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Parse YouTube Video ID from URL #30

Closed
wants to merge 2 commits into from

2 participants

@dbarlett

Revised version of Pull Request #29.

@eduardocereto eduardocereto closed this pull request from a commit
@eduardocereto eduardocereto Merge branch 'iss30' into develop
Fixes #30. Merges remote branch into develop.

Fixes issue with youtube API. We were using an unstageupported API
version before and that started to cause problems.
9d11fd1
@eduardocereto

We don't really need the id, we can use the full url as a key to the maps. So I managed to simplify it a bit.

The downside is that the old video_id was not the same as the video_id you get from the url, it was really a unique id for any video in the page. So before you could have the same video multiple times on the page and not anymore. I guess it's not a big issue, at least it works now. I merged into the develop branch and I'll merge back into the master branch later this week when I'll probably do a release for v 1.10.

But thanks for looking into this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 6, 2012
  1. @dbarlett
Commits on Aug 7, 2012
  1. @dbarlett
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/plugins/youtube.js
View
11 src/plugins/youtube.js
@@ -21,10 +21,17 @@ var _ytOpts;
*/
var _ytPoolMaps = {};
+function _ytIdFromUrl(url) {
+ var regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
+ var match = url.match(regExp);
+ if (match&&match[1].length==11){
+ return match[1];
+ }
+}
function _ytStartPool(target) {
if (_ytTimeTriggers && _ytTimeTriggers.length) {
- var h = target['getVideoData']()['video_id'];
+ var h = _ytIdFromUrl(target['getVideoUrl']());
if (_ytPoolMaps[h]) {
_ytStopPool(target);
}else {
@@ -54,7 +61,7 @@ function _ytPool(target, hash) {
}
function _ytStopPool(target) {
- var h = target['getVideoData']()['video_id'];
+ var h = _ytIdFromUrl(target['getVideoUrl']());
if (_ytPoolMaps[h] && _ytPoolMaps[h].timer) {
_ytPool(target, h); // Pool one last time before clearing it.
clearTimeout(_ytPoolMaps[h].timer);
Something went wrong with that request. Please try again.