forked from sonichy/VideoGrab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcctv.js
80 lines (77 loc) · 2.3 KB
/
cctv.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
71
72
73
74
75
76
77
78
79
80
console.clear();
var domain = location.host;
console.info(domain);
var dialog = document.getElementById('dialog');
if (dialog == null) {
dialog = document.createElement('dialog');
dialog.setAttribute('id', 'dialog');
dialog.setAttribute('open', 'open');
dialog.style.margin = '0px';
dialog.style.top = '100px';
dialog.style.left = '0px';
dialog.style.zIndex = 10000;
document.body.appendChild(dialog);
}
dialog.style.display = 'block';
dialog.innerHTML = '';
var button = document.createElement('button');
button.textContent=' X ';
dialog.appendChild(button);
button.onclick = function(){
dialog.style.display = 'none';
}
var br = document.createElement('br');
dialog.appendChild(br);
function xmlHttpRequest(url) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
//console.info(url);
//console.info(xhr.responseText);
var data = JSON.parse(xhr.responseText);
var video = data.video;
for(var obj in video){
//console.log(video[obj] + ' ' + Array.isArray(video[obj]));
if(Array.isArray(video[obj])){
var s='';
for(i=0; i<video[obj].length; i++){
s += video[obj][i].url;
if(i<video[obj].length-1)s+=';';
}
var a = document.createElement('a');
a.textContent = obj;
a.href = s;
dialog.appendChild(a);
var br = document.createElement('br');
dialog.appendChild(br);
//console.log(obj+': '+s);
}
}
}
} else {
console.error(url);
console.error(xhr.responseText);
}
}
xhr.open('GET', url, false);
xhr.send();
}
var url;
var videoId;
var embed = document.getElementsByTagName('embed');
var flashvars = embed[0].getAttribute('flashvars');
var vars = new Array();
vars = flashvars.split('&');
var keyword = 'videoCenterId=';
for (i = 0; i < vars.length; i++) {
//console.info(vars[i]);
if (vars[i].indexOf(keyword) != -1) {
videoId = vars[i].substring(keyword.length);
break;
}
}
url = 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=' + videoId;
xmlHttpRequest(url);
console.info(url);
//window.open(url);