refactor: 去掉switch分发mediabot按pageKey直调parseSync/parseSearch等
This commit is contained in:
@@ -2,29 +2,27 @@
|
||||
// 适用: carpt / cbg / ptfans / ptskit / hdfans / cyanbug / qingwa 等
|
||||
// medibo 负责 HTTP,脚本只做解析 + 状态码判断
|
||||
|
||||
// ==================== medibo 入口 (统一分发) ====================
|
||||
// ==================== medibo 入口 ====================
|
||||
// medibo 根据 pageKey 调用对应方法,如 parseSync(context)
|
||||
// 约定方法名: parse + pageKey 首字母大写
|
||||
|
||||
Map parse(context) {
|
||||
if (context.status != 200) {
|
||||
Map parseSync(context) { return checkStatus(context) ?: parseUserProfile(Jsoup.parse(context.content)) }
|
||||
Map parseSearch(context) { return checkStatus(context) ?: parseSearchPage(Jsoup.parse(context.content)) }
|
||||
Map parseDetail(context) { return checkStatus(context) ?: parseDetailPage(Jsoup.parse(context.content)) }
|
||||
Map parseSignIn(context) { return checkStatus(context) ?: parseSignPage(Jsoup.parse(context.content)) }
|
||||
Map parseDownload(context) { return checkStatus(context) ?: parseDownloadPage(context) }
|
||||
|
||||
/** 通用状态码检查,非 200 直接返回错误 */
|
||||
private Map checkStatus(context) {
|
||||
if (context.status == 200) return null
|
||||
return switch(context.status) {
|
||||
case 302 -> [matched: false, redirect: context.headers?.Location ?: '']
|
||||
case 403 -> [matched: false, banned: true, message: 'IP被禁']
|
||||
case 429 -> [matched: false, rateLimited: true]
|
||||
default -> [matched: false, error: true, status: context.status, message: "HTTP ${context.status}"]
|
||||
}
|
||||
}
|
||||
return switch(context.pageKey) {
|
||||
case 'sync' -> parseUserProfile(Jsoup.parse(context.content))
|
||||
case 'search' -> parseSearchPage(Jsoup.parse(context.content))
|
||||
case 'detail' -> parseDetailPage(Jsoup.parse(context.content))
|
||||
case 'signIn' -> parseSignPage(Jsoup.parse(context.content))
|
||||
case 'download'-> parseDownload(context)
|
||||
default -> [pageName: context.pageKey, message: '未实现']
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 用户信息 / 同步 ====================
|
||||
|
||||
private Map parseUserProfile(doc) {
|
||||
def fields = extractUserInfo(doc)
|
||||
if (fields.isEmpty()) return [pageName: '用户信息', matched: false, message: '未提取到数据']
|
||||
@@ -103,7 +101,7 @@ private Map parseSignPage(doc) {
|
||||
|
||||
// ==================== 下载 ====================
|
||||
|
||||
private Map parseDownload(context) {
|
||||
private Map parseDownloadPage(context) {
|
||||
// 下载页通常是重定向到种子文件
|
||||
if (context.status == 302 || context.status == 301) {
|
||||
return [pageName: '下载', matched: false, redirect: context.headers?.Location ?: '']
|
||||
|
||||
Reference in New Issue
Block a user