-
Notifications
You must be signed in to change notification settings - Fork 6
/
check.js
executable file
·126 lines (116 loc) · 3.42 KB
/
check.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env node
const CHECK_URL = [
"http://kv.zwc365.com/tvlive",
"https://raw.githubusercontent.com/dxawi/0/main/tvlive.txt",
"https://raw.githubusercontent.com/qist/tvbox/master/list.txt",
];
const PROXY_ENV = 'http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890';
const fetch = require('node-fetch');
var exec = require('child_process').exec;
async function verifyurl(url){
try{
var res = await fetch(url, {
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0'
},
responseType: 'stream',
timeout: 3000,
});
return true;
}catch(e){
// console.log(e);
return false;
}
}
async function geturlcontent(url){
try{
var res = await execmd(PROXY_ENV + ' ' + 'curl -s -L \"' + url + '\"');
if(res[0]){
return '';
}
return res[1];
}catch(e){
console.log(e);
return '';
}
}
async function execmd(cmd){
console.log(cmd);
var over = false;
var waitcall = null;
var _err, _stdout, _stderr = null;
exec(cmd, async function(err,stdout,stderr){
_err = err;
_stdout = stdout;
_stderr = stderr;
if (! over){
over = true;
if(waitcall){
waitcall();
waitcall = null;
}
}
});
if (! over){
await new Promise(r => {waitcall = r});
}
return [_err, _stdout, _stderr];
}
async function pushgit(){
console.log('exec over');
var gitstatu = await execmd('git add .');
if (gitstatu[0]){
console.log('git 提交出错:', gitstatu);
return;
}
var gitstatu = await execmd('git commit -m \"' + '自动提交: $(date)'+ '\"');
if (gitstatu[0]){
console.log('git 提交出错:', gitstatu);
return;
}
var gitstatu = await execmd('git push origin master');
if (gitstatu[0]){
console.log('git 提交出错:', gitstatu);
return;
}
}
async function checkallurl(data){
var listsplit = data.split('\n');
await listsplit.reduce(async (memo, ise) => {
await memo;
if (! ise || ise == ''){ return 0; }
var isesplit = ise.trim().split(',');
if(isesplit.length >= 2){
if(isesplit[1].trim().indexOf('http')==0){
if(await verifyurl(isesplit[1].trim())){
console.log('append:', ise);
await execmd('printf -- \"\n' + ise + '\"' + ' >>live.txt');
} else {
console.log('过滤无法访问的源:', ise);
}
return;
}
}
await execmd('printf -- \"\n' + ise + '\"' + ' >>live.txt');
}, '');
}
async function loadexturl(){
// const loadlist='https://raw.githubusercontent.com/qist/tvbox/master/list.txt'
await execmd('printf -- \"' + '\"' + ' >live.txt');
await CHECK_URL.reduce(async (memo, url) => {
await memo;
if (! url || url == ''){ return 0; }
var content = await geturlcontent(url);
// console.log(content);
if(content){
await checkallurl(content);
}
}, '');
await pushgit();
console.log('状态:', 'over');
process.exit(0);
}
console.log('开始测试live地址并保存');
loadexturl();
// pushgit();