]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
1. Scott's greedy regex.
authorBobby Richter <secretrobotron@gmail.com>
Mon, 9 May 2011 15:10:29 +0000 (11:10 -0400)
committerBobby Richter <secretrobotron@gmail.com>
Mon, 9 May 2011 15:10:29 +0000 (11:10 -0400)
2. Added /v/ to tests.

players/youtube/popcorn.youtube.js
players/youtube/popcorn.youtube.unit.js

index fff547320e594e5cd158a4508876f2952fc3b889..f77c77c1f70c7953250a594d6c27425974262c39 100644 (file)
@@ -45,7 +45,7 @@ var onYouTubePlayerReady;
       YOUTUBE_STATE_BUFFERING = 3,
       YOUTUBE_STATE_CUED = 5;
 
-  var urlRegex = /(\/e\/|be\/|\/embed\/|\/watch\?v=)([a-zA-Z0-9_]{11})/;
+  var urlRegex = /^.*[\/=](.{11})/;
   
   // Collection of all Youtube players
   var registry = {},
@@ -64,7 +64,7 @@ var onYouTubePlayerReady;
     var matches = urlRegex.exec( url ); 
 
     // Return id, which comes after first equals sign
-    return matches ? matches[2] : "";
+    return matches ? matches[1] : "";
   }
   
   // Extract the id from a player url
@@ -76,7 +76,7 @@ var onYouTubePlayerReady;
     var matches = urlRegex.exec( url ); 
     
     // Return id, which comes after first equals sign
-    return matches ? matches[2] : "";
+    return matches ? matches[1] : "";
   }
   
   function getPlayerAddress( vidId, playerId ) {
index 5db19be5a86893e3b00e8260ac3bf6a9faeb3885..127024d460e9bc43e37f749a2d0fb105dccc3237 100644 (file)
@@ -200,9 +200,12 @@ test( "Popcorn YouTube Plugin Url Regex Test", function() {
     { name: 'long embed',
       url: 'http://www.youtube.com/embed/9oar9glUCL0',
     },
-    { name: 'short embed',
+    { name: 'short embed 1 (e)',
       url: 'http://www.youtube.com/e/9oar9glUCL0',
     },
+    { name: 'short embed 2 (v)',
+      url: 'http://www.youtube.com/v/9oar9glUCL0',
+    },
   ];
 
   expect( urlTests.length );
@@ -213,7 +216,7 @@ test( "Popcorn YouTube Plugin Url Regex Test", function() {
     var urlTest = urlTests[t],
         popcorn = Popcorn( Popcorn.youtube( 'video3', urlTest.url ) );
 
-    equals( popcorn.video.vidId, '9oar9glUCL0', 'Video id is correct for ' + urlTest.name );
+    equals( popcorn.video.vidId, '9oar9glUCL0', 'Video id is correct for ' + urlTest.name + ': ' + urlTest.url );
     popcorn.pause();
 
     // Get rid of the youtube object inside the video3, to keep things simple