forked from hoyois/plugin-to-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vimeo.js
70 lines (62 loc) · 2.18 KB
/
Vimeo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
addKiller("Vimeo", {
"canKill": function(data) {
return data.src.indexOf("vimeo.com/moogaloop") !== -1 || data.src.indexOf("vimeocdn.com/p/flash/moogalo") !== -1;
},
"process": function(data, callback) {
var videoID;
if(data.params.flashvars) videoID = parseFlashVariables(data.params.flashvars).clip_id;
if(!videoID) {
var match = /clip_id=([^&]+)/.exec(data.src);
if(match) videoID = match[1];
}
if(!videoID) return;
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://vimeo.com/" + videoID, true);
xhr.onload = function() {
var s = xhr.responseText.substring(xhr.responseText.lastIndexOf("<script>"));
s = s.substring(s.indexOf("config:{") + 7);
s = s.substring(0, s.indexOf(",assets:"));
var config = JSON.parse(s.replace(/\\\//g, "/"));
var sources = [];
var addSource = function(codec, quality) {
var source = {"url": "http://player.vimeo.com/play_redirect?quality=" + quality + "&codecs=" + codec + "&clip_id=" + videoID + "&sig=" + config.request.signature + "&time=" + config.request.timestamp, "isNative": codec === "h264"};
switch(quality) {
case "hd":
if(config.video.height === 1080) source.format = "1080p";
else source.format = "720p";
source.height = 720;
break;
case "sd":
source.format = "360p";
source.height = 360;
break;
case "mobile":
source.format = "Mobile";
source.height = 240;
break;
}
source.format += codec === "h264" ? " MP4" : " FLV";
sources.push(source);
};
if(config.video.files.h264) {
for(var i = 0; i < config.video.files.h264.length; i++) {
addSource("h264", config.video.files.h264[i]);
}
}
if(canPlayFLV && config.video.files.vp6) {
for(var i = 0; i < config.video.files.vp6.length; i++) {
addSource("vp6", config.video.files.vp6[i]);
}
}
var siteInfo;
if(data.location.indexOf("vimeo.com/") === -1 || /^https?:\/\/vimeo\.com\/$/.test(data.location) || data.location.indexOf("player.vimeo.com/") !== -1) siteInfo = {"name": "Vimeo", "url": "http://vimeo.com/" + videoID};
callback({"playlist": [{
"siteInfo": siteInfo,
"title": config.video.title,
"poster": config.video.thumbnail,
"sources": sources
}]});
};
xhr.send(null);
}
});