зеркало из https://github.com/mozilla/popcorn-js.git
Merge remote branch 'bobby/493' into 0.6
This commit is contained in:
Коммит
43438e8990
|
@ -44,6 +44,8 @@ var onYouTubePlayerReady;
|
|||
YOUTUBE_STATE_PAUSED = 2,
|
||||
YOUTUBE_STATE_BUFFERING = 3,
|
||||
YOUTUBE_STATE_CUED = 5;
|
||||
|
||||
var urlRegex = /^.*[\/=](.{11})/;
|
||||
|
||||
// Collection of all Youtube players
|
||||
var registry = {},
|
||||
|
@ -59,9 +61,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 +73,10 @@ var onYouTubePlayerReady;
|
|||
return;
|
||||
}
|
||||
|
||||
var matches = url.match( /^http:\/\/?www\.youtube\.[a-z]+\/e\/[a-z0-9]+/i );
|
||||
var matches = urlRegex.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 ) {
|
||||
|
@ -192,7 +195,7 @@ var onYouTubePlayerReady;
|
|||
this.duration = 0;
|
||||
|
||||
this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url );
|
||||
|
||||
|
||||
if ( !this.vidId ) {
|
||||
throw "Could not find video id";
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
</p>
|
||||
<div id="video" style="width: 360px; height: 300px" ></div>
|
||||
<div id="video2" style="width: 360px; height: 300px" ></div>
|
||||
<div id="video3" style="width: 360px; height: 300px" ></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -185,3 +185,54 @@ test( "Popcorn YouTube Plugin Url and Duration Tests", function() {
|
|||
|
||||
popcorn.play();
|
||||
});
|
||||
|
||||
test( "Popcorn YouTube Plugin Url Regex Test", function() {
|
||||
|
||||
QUnit.reset();
|
||||
|
||||
var urlTests = [
|
||||
{ name: 'standard',
|
||||
url: 'http://www.youtube.com/watch?v=9oar9glUCL0',
|
||||
expected: '9oar9glUCL0',
|
||||
},
|
||||
{ name: 'share url',
|
||||
url: 'http://youtu.be/9oar9glUCL0',
|
||||
expected: '9oar9glUCL0',
|
||||
},
|
||||
{ name: 'long embed',
|
||||
url: 'http://www.youtube.com/embed/9oar9glUCL0',
|
||||
expected: '9oar9glUCL0',
|
||||
},
|
||||
{ name: 'short embed 1 (e)',
|
||||
url: 'http://www.youtube.com/e/9oar9glUCL0',
|
||||
expected: '9oar9glUCL0',
|
||||
},
|
||||
{ name: 'short embed 2 (v)',
|
||||
url: 'http://www.youtube.com/v/9oar9glUCL0',
|
||||
expected: '9oar9glUCL0',
|
||||
},
|
||||
{ name: 'contains underscore',
|
||||
url: 'http://www.youtube.com/v/GP53b__h4ew',
|
||||
expected: 'GP53b__h4ew',
|
||||
},
|
||||
];
|
||||
|
||||
expect( urlTests.length );
|
||||
stop( 10000 );
|
||||
|
||||
for ( var t in urlTests ) {
|
||||
|
||||
var urlTest = urlTests[t],
|
||||
popcorn = Popcorn( Popcorn.youtube( 'video3', urlTest.url ) );
|
||||
|
||||
equals( popcorn.video.vidId, urlTest.expected, 'Video id is correct for ' + urlTest.name + ': ' + urlTest.url );
|
||||
popcorn.pause();
|
||||
|
||||
// Get rid of the youtube object inside the video3, to keep things simple
|
||||
var div = document.getElementById('video3');
|
||||
div.removeChild(div.firstChild);
|
||||
}
|
||||
|
||||
start();
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче