-
Notifications
You must be signed in to change notification settings - Fork 8
/
recent.js
64 lines (60 loc) · 2.97 KB
/
recent.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
// Import frameworks
const axios = require('axios')
const xpath = require('xpath'), dom = require('xmldom').DOMParser
module.exports = async token => {
// Get cookie token from database
// Node: write the error feedback in catch
// Get game data
let networkrequest = await axios.get('https://maimai.wahlap.com/maimai-mobile/record/', {
headers: {
Cookie: `_t=${token.ult}; userId=${token.userId}`
}
})
// Get token
let cookieori = networkrequest.headers['set-cookie']
let cookie = {}
for (let i in cookieori) {
cookie[cookieori[i].split('; ')[0].split('=')[0]] = cookieori[i].split('; ')[0].split('=')[1]
}
if (!cookie.userId) {
let doc = new dom().parseFromString(networkrequest.data)
throw new Error(`The server return an error: ${xpath.select(`string(//div[@class='p_5 f_12 gray break'])`, doc)}`)
}
// Parse webpage content
let doc = new dom().parseFromString(networkrequest.data)
// Game logs
let logs_row
try { logs_row = await xpath.select(`//div[@class='p_10 t_l f_0 v_b']`, doc) } catch(e) { throw new Error('Expired or incorrect token pair') }
let logs = []
try {
for (let i in logs_row) {
logs[i] = new dom().parseFromString(logs_row[i].toString())
let result = {}
result.tracknum = (xpath.select(`string(//span[@class='red f_b v_b'])`, logs[i])).split(' 0')[1]
result.date = (xpath.select(`string(//span[@class='v_b'])`, logs[i]))
let grade = (xpath.select1(`//img[@class='playlog_scorerank']/@src`, logs[i]).value).split('/')
let difficulty = xpath.select1(`//img[@class='playlog_diff v_b']/@src`, doc).value
difficulty = (difficulty.split('diff_')[1]).split('.')[0]
result.id = xpath.select1(`//form/input/@value`, logs[i]).value
result.track = {
title: (xpath.select(`string(//div[@class='basic_block m_5 p_5 p_l_10 f_13 break'])`, logs[i])),
dx: (xpath.select1(`//img[@class='playlog_music_kind_icon']/@src`, logs[i]).value) === 'https://maimai.wahlap.com/maimai-mobile/img/music_dx.png',
coverart: xpath.select1(`//img[@class='music_img m_5 m_r_0 f_l']/@src`, logs[i]).value,
difficulty
}
result.grade = {
achivement: parseFloat((xpath.select(`string(//div[@class='playlog_achievement_txt t_r'])`, logs[i])).split('%')[0]),
dxscore: parseInt(xpath.select(`string(//div[@class='white p_r_5 f_15 f_r'])`, logs[i])),
fullcombo: xpath.select1(`//div[@class='playlog_result_innerblock basic_block p_5 f_13']/img[@class='h_35 m_5 f_l']/@src`, logs[i]).value === 'https://maimai.wahlap.com/maimai-mobile/img/playlog/fc.png',
fullsync: !(xpath.select(`//img[@src='https://maimai.wahlap.com/maimai-mobile/img/playlog/fs_dummy.png']`, logs[i]))[0],
rank: (grade[grade.length - 1]).split('.')[0]
}
logs[i] = result
}
} catch (e) {
console.log('mainetcn has an unexpected error!')
console.log(e)
}
let result = logs
return {result, token: {ult: cookie['_t'], userId: cookie['userId']}}
}