diff --git a/docs/pttime.groovy b/docs/pttime.groovy index 7341211..a99579d 100644 --- a/docs/pttime.groovy +++ b/docs/pttime.groovy @@ -41,41 +41,23 @@ private Map parseIndex(doc) { private Map parseSearch(doc) { def rows = [] + // PTTIME 列表列序: 类别|标题|PTR(dn)|评论(dn)|时间|大小|做种|下载|完成|进度|发布者|行为 doc.select('table.torrents tr:has(td.rowfollow):not(:has(.colhead))').each { row -> def titleEl = utils.selectFirst(row, 'td.embedded a.torrentname_title') if (!titleEl) return - def catEl = utils.selectFirst(row, 'td.rowfollow a[href*=cat] img, td.rowfollow span.category') + def catEl = utils.selectFirst(row, 'td.rowfollow span.category') def freeEl = utils.selectFirst(row, 'font.promotion') def tds = row.select('td.rowfollow') - // 语义匹配:按内容特征识别字段 - def size = '', seeders = '', leechers = '', completed = '', time = '', publisher = '' - boolean hasSize = false, hasSeed = false, hasLeech = false - for (int i = 0; i < tds.size(); i++) { - def cell = utils.text(tds.get(i)) - if (!cell) continue - if (!hasSize && (cell.contains('GB')||cell.contains('MB')||cell.contains('TB')||cell.contains('KB'))) { - size = cell; hasSize = true - } else if (hasSize && !hasSeed && cell ==~ /^\d+$/) { - seeders = cell; hasSeed = true - } else if (hasSeed && !hasLeech && cell ==~ /^\d+$/) { - leechers = cell; hasLeech = true - } else if (hasSeed && hasLeech && cell ==~ /^\d+$/) { - completed = cell - } else if (cell ==~ /^\d+年|^\d+月|^\d+天|^\d+时/) { - time = cell - } - } rows << [ title: utils.text(titleEl), detailUrl: utils.attr(titleEl, 'href'), - category: utils.attr(catEl, 'alt') ?: utils.attr(catEl, 'title') ?: '', + category: utils.attr(catEl, 'title') ?: '', free: utils.text(freeEl), - size: size, - seeders: seeders, - leechers: leechers, - completed: completed, - publishDate: time, - publisher: publisher, + size: utils.text(tds.size() > 5 ? tds.get(5) : null), + seeders: utils.text(tds.size() > 6 ? tds.get(6) : null), + leechers: utils.text(tds.size() > 7 ? tds.get(7) : null), + completed: utils.text(tds.size() > 8 ? tds.get(8) : null), + publishDate: utils.text(tds.size() > 4 ? tds.get(4) : null), ] } return [pageName: '搜索', extracted: rows, message: "共 ${rows.size()} 条"] @@ -147,28 +129,13 @@ List search(PluginContext ctx, Map params) { def titleEl = utils.selectFirst(row, 'td.embedded a.torrentname_title') 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 = utils.text(tds.get(i)) - if (!cell) continue - if (!hasSize && (cell.contains('GB')||cell.contains('MB')||cell.contains('TB')||cell.contains('KB'))) { - size = parseHtmlSize(cell); hasSize = true - } else if (hasSize && !hasSeed && cell ==~ /^\d+$/) { - seeders = cell as int; hasSeed = true - } else if (hasSeed && !hasLeech && cell ==~ /^\d+$/) { - leechers = cell as int; hasLeech = true - } else if (hasSeed && hasLeech && cell ==~ /^\d+$/) { - grabs = cell as int - } - } rows << [ title: utils.text(titleEl), detailUrl: "${ctx.siteUrl}${utils.attr(titleEl,'href')}", - size: size, - seeders: seeders, - leechers: leechers, - grabs: grabs, + size: tds.size() > 5 ? parseHtmlSize(utils.text(tds.get(5))) : 0, + seeders: tds.size() > 6 ? utils.toInt(utils.text(tds.get(6))) ?: 0 : 0, + leechers: tds.size() > 7 ? utils.toInt(utils.text(tds.get(7))) ?: 0 : 0, + grabs: tds.size() > 8 ? utils.toInt(utils.text(tds.get(8))) ?: 0 : 0, ] } return rows