forked from hoyois/plugin-to-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNaverVideo.js
58 lines (51 loc) · 1.74 KB
/
NaverVideo.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("NaverVideo", {
"canKill": function(data) {
if(data.src.indexOf("inKey") !== -1) data.onsite = true;
else data.onsite = false;
if(data.src.indexOf("serviceapi.nmv.naver.com/flash/NFPlayer.swf") !== -1) return true;
return false;
},
"process": function(data, callback) {
// in & out
var match = data.src.match(/vid=([0-9A-F]+)&(in|out)Key=([0-9a-fV]+)/);
if(match) {
var videoid = match[1];
var key = match[3];
var inout = (data.onsite) ? "in" : "out";
var videoxml = "http://serviceapi.nmv.naver.com/flash/play.nhn?vid=" + videoid + "&"+ inout +"Key=" + key;
var infoxml = "http://serviceapi.nmv.naver.com/flash/videoInfo.nhn?vid=" + videoid + "&"+ inout +"Key=" + key;
var xhr = new XMLHttpRequest();
xhr.open('GET', videoxml, false);
xhr.send(null);
var videoUrl = xhr.responseXML.getElementsByTagName("Result")[0].getElementsByTagName("FlvUrl")[0].textContent;
this.processVideoInfo(videoUrl, infoxml, callback);
}
},
"processVideoInfo": function(videoUrl, infoxml, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', infoxml, true);
xhr.onload = function(event) {
var result = event.target.responseXML.getElementsByTagName("Result")[0];
var link = result.getElementsByTagName("Link")[0].textContent;
var title = result.getElementsByTagName("Subject")[0].textContent;
var posterurl = result.getElementsByTagName("CoverImage")[0].textContent;
var type = result.getElementsByTagName("VideoType")[0].textContent;
callback({
"playlist": [{
"siteinfo": [{
"name": "Naver",
"url": link
}],
"title": title,
"poster": posterurl,
"sources": [{
"url": videoUrl,
"format": type,
"isNative": (type == "MP4") ? true : false
}]
}]
});
};
xhr.send(null);
}
});