2022-09-24 01:06:57 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import cheerio from 'cheerio'
|
|
|
|
import fetch from 'node-fetch'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-10-12 17:24:34 +00:00
|
|
|
import lodash from 'lodash'
|
|
|
|
import request from 'request'
|
2023-03-03 22:01:11 +00:00
|
|
|
import HttpsProxyAgent from 'https-proxy-agent'
|
|
|
|
|
|
|
|
let agent = new HttpsProxyAgent('http://localhost:4780')
|
2022-09-24 01:06:57 +00:00
|
|
|
|
|
|
|
const artiIdx = {
|
|
|
|
Flower: 1,
|
|
|
|
Plume: 2,
|
|
|
|
Sands: 3,
|
|
|
|
Goblet: 4,
|
|
|
|
Circlet: 5
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getSets (id) {
|
|
|
|
const url = `https://genshin.honeyhunterworld.com/i_${id}/?lang=CHS`
|
2023-03-03 22:01:11 +00:00
|
|
|
let req = await fetch(url, { agent })
|
2022-09-24 01:06:57 +00:00
|
|
|
let txt = await req.text()
|
2023-04-12 19:44:56 +00:00
|
|
|
let sTxt = /sortable_data.push\((\[\[.*?\]\])[\n\s]*\)/.exec(txt)
|
2022-09-24 01:06:57 +00:00
|
|
|
let ret = {}
|
|
|
|
|
|
|
|
if (sTxt && sTxt[1]) {
|
2022-10-12 17:24:34 +00:00
|
|
|
// eslint-disable-next-line no-eval
|
2022-09-24 01:06:57 +00:00
|
|
|
let arrs = eval(sTxt[1])
|
|
|
|
lodash.forEach(arrs, (ds) => {
|
|
|
|
let $ = cheerio.load(ds.join(''))
|
|
|
|
let a = $('a:eq(1)')
|
|
|
|
let idRet = /i_(.+)\//.exec(a.attr('href'))
|
|
|
|
let nRet = /^(\w+)\s/.exec($('a:last').text())
|
|
|
|
if (nRet && idRet) {
|
|
|
|
ret[artiIdx[nRet[1]]] = {
|
|
|
|
id: idRet[1],
|
|
|
|
name: a.text()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-11-03 17:31:11 +00:00
|
|
|
async function down (sets = '') {
|
2022-09-24 01:06:57 +00:00
|
|
|
const url = 'https://genshin.honeyhunterworld.com/fam_art_set/?lang=CHS'
|
2023-03-03 22:01:11 +00:00
|
|
|
let req = await fetch(url, { agent })
|
2022-09-24 01:06:57 +00:00
|
|
|
let txt = await req.text()
|
2022-11-03 17:31:11 +00:00
|
|
|
if (sets) {
|
|
|
|
sets = sets.split(',')
|
|
|
|
}
|
2022-09-24 01:06:57 +00:00
|
|
|
|
2023-04-12 19:44:56 +00:00
|
|
|
let ret = Data.readJSON('resources/meta/artifact/data.json', 'miao')
|
2022-09-24 01:06:57 +00:00
|
|
|
|
2023-04-12 19:44:56 +00:00
|
|
|
let sTxt = /sortable_data.push\((\[\[.*?\]\])\)/.exec(txt)
|
2022-09-24 01:06:57 +00:00
|
|
|
if (sTxt && sTxt[1]) {
|
2022-10-12 17:24:34 +00:00
|
|
|
// eslint-disable-next-line no-eval
|
2023-03-03 22:01:11 +00:00
|
|
|
let txt = sTxt[1]
|
|
|
|
txt = txt.replace(/<script>.+<\/script>/g, '')
|
|
|
|
let tmp
|
|
|
|
try {
|
|
|
|
tmp = eval(txt)
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
2022-09-24 01:06:57 +00:00
|
|
|
lodash.forEach(tmp, (ds) => {
|
|
|
|
let na = cheerio.load(ds[0])('a:last')
|
|
|
|
let idRet = /i_(\w+)\//.exec(na.attr('href'))
|
|
|
|
if (idRet && idRet[1]) {
|
|
|
|
let effect = {}
|
|
|
|
let $ = cheerio.load(`<div>${ds[2]}</div>`)
|
|
|
|
|
|
|
|
$('span').each(function () {
|
|
|
|
let setRet = /(\d)-Piece:\s*(.*)。?$/.exec($(this).text())
|
|
|
|
if (setRet && setRet[1]) {
|
|
|
|
effect[setRet[1]] = setRet[2]
|
|
|
|
}
|
|
|
|
})
|
2023-04-12 19:44:56 +00:00
|
|
|
if (idRet[1]) {
|
|
|
|
let id = idRet[1]
|
|
|
|
ret[id] = ret[id] || {
|
|
|
|
id,
|
|
|
|
name: na.find('img').attr('alt'),
|
|
|
|
sets: {},
|
|
|
|
effect
|
|
|
|
}
|
2022-09-24 01:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let imgs = []
|
|
|
|
for (let idx in ret) {
|
|
|
|
let ds = ret[idx]
|
2022-11-03 17:31:11 +00:00
|
|
|
if (sets) {
|
|
|
|
if (!sets.includes(ds.name)) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2022-09-24 01:06:57 +00:00
|
|
|
ds.sets = await getSets(ds.id)
|
|
|
|
console.log(`arti ${ds.id}:${ds.name} Done`)
|
2023-03-07 17:52:11 +00:00
|
|
|
Data.createDir(`resources/meta/artifact/imgs/${ds.name}`, 'miao')
|
2022-09-24 01:06:57 +00:00
|
|
|
|
|
|
|
lodash.forEach(ds.sets, (s, idx) => {
|
|
|
|
imgs.push({
|
|
|
|
url: `img/i_${s.id}.webp`,
|
|
|
|
file: `${ds.name}/${idx}.webp`
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-03-07 17:52:11 +00:00
|
|
|
Data.createDir('resources/meta/artifact', 'miao')
|
|
|
|
Data.writeJSON('resources/meta/artifact/data.json', ret, 'miao')
|
2022-09-24 01:06:57 +00:00
|
|
|
|
|
|
|
const _path = process.cwd()
|
|
|
|
const _root = _path + '/plugins/miao-plugin/'
|
2022-11-24 08:25:04 +00:00
|
|
|
const _aRoot = _root + 'resources/meta/artifact/imgs/'
|
2022-09-24 01:06:57 +00:00
|
|
|
await Data.asyncPool(5, imgs, async function (ds) {
|
|
|
|
if (fs.existsSync(`${_aRoot}/${ds.file}`)) {
|
|
|
|
// console.log(`已存在,跳过 ${ds.file}`)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let stream = fs.createWriteStream(`${_aRoot}/${ds.file}.tmp`)
|
|
|
|
await request('https://genshin.honeyhunterworld.com/' + ds.url).pipe(stream)
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
stream.on('finish', () => {
|
|
|
|
fs.rename(`${_aRoot}/${ds.file}.tmp`, `${_aRoot}/${ds.file}`, () => {
|
|
|
|
console.log(`图像下载成功: ${ds.file}`)
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`图像下载失败: ${ds.file}`)
|
|
|
|
console.log(e)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-12 19:44:56 +00:00
|
|
|
await down('水仙之梦,花海甘露之光')
|