From 3c61e384ac799af93a3448cf94ed3369c8d3f428 Mon Sep 17 00:00:00 2001
From: Bobby Richter
Date: Fri, 6 May 2011 22:54:26 -0400
Subject: [PATCH] 1. Assimilated youtube regex's 2. Added youtube regex tests
---
players/youtube/popcorn.youtube.js | 11 +++----
players/youtube/popcorn.youtube.unit.html | 1 +
players/youtube/popcorn.youtube.unit.js | 39 +++++++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js
index c9b7085..fff5473 100644
--- a/players/youtube/popcorn.youtube.js
+++ b/players/youtube/popcorn.youtube.js
@@ -45,8 +45,7 @@ var onYouTubePlayerReady;
YOUTUBE_STATE_BUFFERING = 3,
YOUTUBE_STATE_CUED = 5;
- var uriRegex = /^[^v]+v.(.{11}).*/,
- urlRegex = /^[^d]+d.(.{11}).*/;
+ var urlRegex = /(\/e\/|be\/|\/embed\/|\/watch\?v=)([a-zA-Z0-9_]{11})/;
// Collection of all Youtube players
var registry = {},
@@ -65,7 +64,7 @@ var onYouTubePlayerReady;
var matches = urlRegex.exec( url );
// Return id, which comes after first equals sign
- return matches ? matches[1] : "";
+ return matches ? matches[2] : "";
}
// Extract the id from a player url
@@ -74,10 +73,10 @@ var onYouTubePlayerReady;
return;
}
- var matches = uriRegex.exec( url );
+ var matches = urlRegex.exec( url );
// Return id, which comes after first equals sign
- return matches ? matches[1] : "";
+ return matches ? matches[2] : "";
}
function getPlayerAddress( vidId, playerId ) {
@@ -196,7 +195,7 @@ var onYouTubePlayerReady;
this.duration = 0;
this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url );
-
+
if ( !this.vidId ) {
throw "Could not find video id";
}
diff --git a/players/youtube/popcorn.youtube.unit.html b/players/youtube/popcorn.youtube.unit.html
index ce0a83c..405821f 100644
--- a/players/youtube/popcorn.youtube.unit.html
+++ b/players/youtube/popcorn.youtube.unit.html
@@ -30,6 +30,7 @@
+