Skip to content
This repository

Parse YouTube Video ID from URL #30

Closed
wants to merge 2 commits into from

2 participants

Dylan Barlett Eduardo Cereto Carvalho
Dylan Barlett

Revised version of Pull Request #29.

Eduardo Cereto Carvalho eduardocereto closed this pull request from a commit
Eduardo Cereto Carvalho 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
Eduardo Cereto Carvalho

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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. +9 2 src/plugins/youtube.js
11 src/plugins/youtube.js
@@ -21,10 +21,17 @@ var _ytOpts;
21 21 */
22 22 var _ytPoolMaps = {};
23 23
  24 +function _ytIdFromUrl(url) {
  25 + var regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
  26 + var match = url.match(regExp);
  27 + if (match&&match[1].length==11){
  28 + return match[1];
  29 + }
  30 +}
24 31
25 32 function _ytStartPool(target) {
26 33 if (_ytTimeTriggers && _ytTimeTriggers.length) {
27   - var h = target['getVideoData']()['video_id'];
  34 + var h = _ytIdFromUrl(target['getVideoUrl']());
28 35 if (_ytPoolMaps[h]) {
29 36 _ytStopPool(target);
30 37 }else {
@@ -54,7 +61,7 @@ function _ytPool(target, hash) {
54 61 }
55 62
56 63 function _ytStopPool(target) {
57   - var h = target['getVideoData']()['video_id'];
  64 + var h = _ytIdFromUrl(target['getVideoUrl']());
58 65 if (_ytPoolMaps[h] && _ytPoolMaps[h].timer) {
59 66 _ytPool(target, h); // Pool one last time before clearing it.
60 67 clearTimeout(_ytPoolMaps[h].timer);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.