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