refactor: default-nexusphp移除旧sign/sync/search,加统一fetch方法
This commit is contained in:
@@ -147,86 +147,12 @@ private Map parseUserPanel(doc) {
|
||||
return [pageName: '控制面板', fields: fields, message: fields.isEmpty() ? '未提取' : '解析成功']
|
||||
}
|
||||
|
||||
// ==================== mediabot 运行时 ====================
|
||||
// ==================== 统一入口(mediabot 调用) ====================
|
||||
|
||||
Map sign(PluginContext ctx) {
|
||||
if (!ctx.auth) return [message: '未配置认证', loginRequired: true]
|
||||
Map fetch(PluginContext ctx, String pageKey) {
|
||||
try {
|
||||
def url = ctx.siteUrl.replaceAll('/+\$', '') + '/attendance.php'
|
||||
def body = http.get(url, ctx.auth)
|
||||
def matched = body ==~ /.*(签到成功|已签到|重复签到|获得.*魔力值).*/
|
||||
return [success: matched, message: matched ? '已签到' : '失败']
|
||||
} catch (e) { return [message: "签到异常: ${e.message}"] }
|
||||
}
|
||||
|
||||
Map sync(PluginContext ctx) {
|
||||
if (!ctx.auth) return [message: '未配置认证', loginRequired: true]
|
||||
try {
|
||||
def url = ctx.siteUrl.replaceAll('/+\$', '') + '/index.php'
|
||||
def body = http.get(url, ctx.auth)
|
||||
def doc = Jsoup.parse(body)
|
||||
def el = doc.selectFirst('#info_block, td.bottom.clearfix, .userbar')
|
||||
if (!el) { ctx.incomplete = true; return [message: '未找到用户信息'] }
|
||||
def t = el.text()
|
||||
def result = [:]
|
||||
def um = t =~ /上传[^::]*[::]\s*([0-9.,]+)\s*(TB|GB|MB|KB|B)?/
|
||||
def dm = t =~ /下载[^::]*[::]\s*([0-9.,]+)\s*(TB|GB|MB|KB|B)?/
|
||||
def rm = t =~ /分享率[::]\s*([\d.,]+)/
|
||||
def bm = t =~ /魔力[^::]*[::]\s*([\d.,]+)/
|
||||
def ss = t =~ /做种积分\s*([\d.,]+)/
|
||||
def am = t =~ /当前活动[^::]*[::]\s*(\d+)\s+(\d+)/
|
||||
def im = t =~ /邀请[^::]*[::]\s*(\d+)/
|
||||
if (um) result.upload = utils.parseTraffic(um[0][1] + (um[0][2] ?: ''))
|
||||
if (dm) result.download = utils.parseTraffic(dm[0][1] + (dm[0][2] ?: ''))
|
||||
if (rm) result.shareRatio = rm[0][1].replace(',','') as double
|
||||
if (bm) result.bonus = bm[0][1].replace(',','') as double
|
||||
if (ss) result.seedingScore = ss[0][1].replace(',','') as double
|
||||
if (am) { result.seeding = am[0][1] as int; result.leeching = am[0][2] as int }
|
||||
if (im) result.invites = im[0][1] as int
|
||||
def hrEl = doc.selectFirst('#info_block font[class=fcr], #info_block font[color=red], #info_block .red')
|
||||
if (hrEl) {
|
||||
def hrm = hrEl.text() =~ /(\d+)/
|
||||
if (hrm) result.hnr = hrm[0][1] as int
|
||||
}
|
||||
if (!result.upload || !result.download) ctx.incomplete = true
|
||||
return result
|
||||
} catch (e) { ctx.incomplete = true; return [message: "同步失败: ${e.message}"] }
|
||||
}
|
||||
|
||||
List search(PluginContext ctx, Map params) {
|
||||
if (!ctx.auth) return []
|
||||
try {
|
||||
def keyword = params.keyword ?: ''
|
||||
def page = (params.page ?: 0) as int
|
||||
def url = "${ctx.siteUrl.replaceAll('/+\$', '')}/torrents.php?search=${URLEncoder.encode(keyword,'UTF-8')}&page=${page}"
|
||||
def body = http.get(url, ctx.auth)
|
||||
def doc = Jsoup.parse(body)
|
||||
def rows = []
|
||||
doc.select('table.torrents tr:has(td.rowfollow):not(:has(.colhead))').each { row ->
|
||||
def titleEl = row.selectFirst('td.embedded a[href*=details]')
|
||||
if (!titleEl) return
|
||||
def tds = row.select('td.rowfollow')
|
||||
long size = 0; int seeders = 0, leechers = 0, grabs = 0
|
||||
boolean hasSize = false, hasSeed = false, hasLeech = false
|
||||
for (int i = 0; i < tds.size(); i++) {
|
||||
def cell = tds[i].text()
|
||||
if (!cell) continue
|
||||
if (!hasSize && (cell.contains('GB')||cell.contains('MB')||cell.contains('TB')||cell.contains('KB'))) {
|
||||
size = utils.parseHtmlSize(cell); hasSize = true
|
||||
} else if (hasSize && !hasSeed && cell ==~ /^\d+$/) {
|
||||
seeders = utils.toInt(cell) ?: 0; hasSeed = true
|
||||
} else if (hasSeed && !hasLeech && cell ==~ /^\d+$/) {
|
||||
leechers = utils.toInt(cell) ?: 0; hasLeech = true
|
||||
} else if (hasLeech && cell ==~ /^\d+$/) {
|
||||
grabs = utils.toInt(cell) ?: 0
|
||||
}
|
||||
}
|
||||
rows << [
|
||||
title: titleEl.text(),
|
||||
detailUrl: "${ctx.siteUrl}${titleEl.attr('href')}",
|
||||
size: size, seeders: seeders, leechers: leechers, grabs: grabs,
|
||||
]
|
||||
}
|
||||
return rows
|
||||
} catch (e) { return [] }
|
||||
Map r = parse(ctx.fetch(), pageKey)
|
||||
if (r.incomplete) ctx.incomplete = true
|
||||
return r
|
||||
} catch (e) { ctx.incomplete = true; return [error: "${pageKey} 失败: ${e.message}", matched: false] }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user