-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcid-sql.js
213 lines (170 loc) · 4.3 KB
/
cid-sql.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
var DOMParser = require('xmldom').DOMParser;
var fs = require('fs');
var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database:'bilibili',
port: 3306
});
conn.connect();
var cid;
function saveCid(data) {
var ele
var cid,aid,pid
var suggest_comment
var maxlimit
var vtype
var typeid
var click
var favourites
var credits
var coins
var fw_click
var arctype
var danmu
var bottom
var sinapi
var acceptguest
var acceptaccel
var oriurl
data = '<xml>'+data+'</xml>';
var doc = new DOMParser().parseFromString(data)
try {
ele = doc.getElementsByTagName('chatid')[0]
if(ele == undefined)
{
console.log('found file without cid ')
throw 'cid is null error'
}
cid = ele.textContent
} catch (error) {
throw error
}
try {
ele = doc.getElementsByTagName('aid')[0]
aid = (ele == undefined)?'0':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('pid')[0]
pid = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('suggest_comment')[0]
suggest_comment = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('maxlimit')[0]
maxlimit = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('vtype')[0]
vtype = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('typeid')[0]
typeid = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('click')[0]
click = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('favourites')[0]
favourites = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('credits')[0]
credits = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('coins')[0]
coins = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('fw_click')[0]
fw_click = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('arctype')[0]
arctype = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('danmu')[0]
danmu = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('bottom')[0]
bottom = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('sinapi')[0]
sinapi = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('acceptguest')[0]
acceptguest = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('acceptaccel')[0]
acceptaccel = (ele == undefined)?'':ele.textContent
} catch (error) {}
try {
ele = doc.getElementsByTagName('oriurl')[0]
oriurl = (ele == undefined)?'':ele.textContent
} catch (error) {}
console.log('cid:'+cid)
conn.query('INSERT INTO cid SET ?', {
'cid': cid,
'aid': aid,
'pid': pid,
'suggest_comment': suggest_comment,
'maxlimit': maxlimit,
'vtype': vtype,
'click': click,
'favourites': favourites,
'credits': credits,
'coins': coins,
'fw_click': fw_click,
'arctype': arctype,
'danmu': danmu,
'bottom': bottom,
'sinapi': sinapi,
'acceptguest': acceptguest,
'acceptaccel': acceptaccel,
'oriurl': oriurl
}, function(err, result) {
if (err && err.errno!=1062) console.log(err);
});
}
function loadTheCid(Cid){
var cid = Cid;
return function(){
var bucket = Math.floor(cid/10000)
var path = './data/'+bucket+'/'+cid+'.xml'
if(cid%1000==0)
console.log(cid);
try{
var data = fs.readFileSync(path, 'utf8');
saveCid(data)
}catch(error){
fs.appendFileSync('cid-lost-list.txt',cid+'\r\n');
console.error(error)
console.error('cid = ' + cid)
}
}
};
function loadCid() {
if(cid>3900000)
return;
cid++;
setTimeout(loadCid,2);
setTimeout(loadTheCid(cid),0);
}
function init(){
cid = 3400000
fs.writeFileSync('cid-lost-list.txt','');
loadCid();
};
init();