From 7b7e530c1a3d43b91bd6687d3e7dd5d4be81d939 Mon Sep 17 00:00:00 2001 From: Bobby Richter Date: Wed, 4 May 2011 21:14:56 -0400 Subject: [PATCH] 1. Fixed regex in youtube player plugin. 2. Regex compiled once per plugin instantiation. --- players/youtube/popcorn.youtube.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js index b416692b..009dad70 100644 --- a/players/youtube/popcorn.youtube.js +++ b/players/youtube/popcorn.youtube.js @@ -44,6 +44,9 @@ var onYouTubePlayerReady; YOUTUBE_STATE_PAUSED = 2, YOUTUBE_STATE_BUFFERING = 3, YOUTUBE_STATE_CUED = 5; + + var uriRegex = /^[^v]+v.(.{11}).*/; + var urlRegex = /^[^d]+d.(.{11}).*/; // Collection of all Youtube players var registry = {}, @@ -59,9 +62,10 @@ var onYouTubePlayerReady; return; } - var matches = url.match( /((http:\/\/)?www\.)?youtube\.[a-z]+\/watch\?v\=[a-z0-9_]+/i ); + var matches = urlRegex.exec( url ); + // Return id, which comes after first equals sign - return matches ? matches[0].split( "=" )[1] : ""; + return matches ? matches[1] : ""; } // Extract the id from a player url @@ -70,10 +74,10 @@ var onYouTubePlayerReady; return; } - var matches = url.match( /^http:\/\/?www\.youtube\.[a-z]+\/e\/[a-z0-9_]+/i ); + var matches = uriRegex.exec( url ); // Return id, which comes after first equals sign - return matches ? matches[0].split( "/e/" )[1] : ""; + return matches ? matches[1] : ""; } function getPlayerAddress( vidId, playerId ) {