forked from hoyois/plugin-to-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollegeHumor.js
58 lines (49 loc) · 1.41 KB
/
CollegeHumor.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
addKiller("CollegeHumor", {
"canKill": function(data) {
return data.src.indexOf("collegehumor.cvcdn.com/moogaloop/") !== -1;
},
"process": function(data, callback) {
var videoID = parseFlashVariables(data.params.flashvars).clip_id;
if(!videoID) {
var match = /[?&]clip_id=([^&]*)/.exec(data.src);
if(match) videoID = match[1];
else return;
}
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.collegehumor.com/moogaloop/video/" + videoID, true);
xhr.addEventListener("load", function() {
var video = xhr.responseXML.querySelector("video");
// YouTube redirection
var provider = video.querySelector("provider");
if(provider) {
if(provider.textContent === "youtube" && hasKiller("YouTube")) {
getKiller("YouTube").processVideoID(video.querySelector("youtubeID").textContent, callback);
}
return;
}
var videoURL = video.querySelector("file").textContent;
if(!/\.mp4$/.test(videoURL)) return;
var sources = [{
"url": videoURL,
"format": "360p MP4",
"height": 360,
"isNative": true
}];
var hq = video.querySelector("hq");
if(hq) {
sources.unshift({
"url": hq.textContent,
"format": "HQ MP4",
"height": 480,
"isNative": true
});
}
callback({"playlist": [{
"title": video.querySelector("caption").textContent,
"poster": video.querySelector("thumbnail").textContent,
"sources": sources
}]});
}, false);
xhr.send(null);
}
});