From 907f7d223f32b2b61e3e46f99e9caa15096339f1 Mon Sep 17 00:00:00 2001 From: ted423 Date: Tue, 22 Feb 2022 13:51:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ACM=E6=96=B0=E5=A2=9E=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E4=B8=8D=E5=8F=97=E5=90=8E=E7=BB=AD=E6=A8=A1=E6=9D=BF=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/sites/asiancinema.me/config.json | 33 ++ .../sites/asiancinema.me/getSearchResult.js | 321 ++++++++++++++++++ 2 files changed, 354 insertions(+) create mode 100644 resource/sites/asiancinema.me/getSearchResult.js diff --git a/resource/sites/asiancinema.me/config.json b/resource/sites/asiancinema.me/config.json index 2da8594f0..447f7a9da 100644 --- a/resource/sites/asiancinema.me/config.json +++ b/resource/sites/asiancinema.me/config.json @@ -7,6 +7,39 @@ "tags": ["综合"], "schema": "UNIT3D", "host": "asiancinema.me", + "searchEntryConfig": { + "page": "/torrents/filter", + "queryString": "search=$key$", + "area": [{ + "name": "IMDB", + "keyAutoMatch": "^(tt\\d+)$", + "queryString": "imdb=$key$", + "replaceKey": [ + "tt", "" + ] + }], + "fieldSelector": { + "progress": { + "selector": ["button.btn.btn-success.btn-circle", "button.btn.btn-warning.btn-circle, button.btn.btn-info.btn-circle", ""], + "switchFilters": [ + ["100"], + ["0"], + ["null"] + ] + }, + "status": { + "selector": ["button.btn.btn-success.btn-circle", "button.btn.btn-warning.btn-circle", "button.btn.btn-info.btn-circle"], + "switchFilters": [ + ["2"], + ["1"], + ["3"] + ] + } + }, + "resultType": "html", + "parseScriptFile": "getSearchResult.js", + "resultSelector": "div.table-responsive > table:first" + }, "selectors": { "userBaseInfo": { "page": "/", diff --git a/resource/sites/asiancinema.me/getSearchResult.js b/resource/sites/asiancinema.me/getSearchResult.js new file mode 100644 index 000000000..2968bcd99 --- /dev/null +++ b/resource/sites/asiancinema.me/getSearchResult.js @@ -0,0 +1,321 @@ +(function(options, Searcher) { + class Parser { + constructor() { + this.haveData = false; + if (/\/login/.test(options.responseText)) { + options.status = ESearchResultParseStatus.needLogin; //`[${options.site.name}]需要登录后再搜索`; + return; + } + + options.isLogged = true; + + this.haveData = true; + } + + /** + * 获取搜索结果 + */ + getResult() { + if (!this.haveData) { + return []; + } + let site = options.site; + site.searchEntryConfig = options.entry + let selector = + options.resultSelector || "div.table-responsive > table:first"; + let table = options.page.find(selector); + // 获取种子列表行 + let rows = table.find("> tbody > tr"); + if (rows.length == 0) { + options.status = ESearchResultParseStatus.torrentTableIsEmpty; //`[${options.site.name}]没有定位到种子列表,或没有相关的种子`; + return []; + } + let results = []; + // 获取表头 + let header = table.find("> thead > tr > th"); + let beginRowIndex = 0; + if (header.length == 0) { + beginRowIndex = 1; + header = rows.eq(0).find("th,td"); + } + + // 用于定位每个字段所列的位置 + let fieldIndex = { + // 发布时间 + time: -1, + // 大小 + size: -1, + // 上传数量 + seeders: -1, + // 下载数量 + leechers: -1, + // 完成数量 + completed: -1, + // 评论数量 + comments: -1, + // 发布人 + author: header.length - 1, + // 分类 + category: 1 + }; + + if (site.url.lastIndexOf("/") != site.url.length - 1) { + site.url += "/"; + } + + // 获取字段所在的列 + for (let index = 0; index < header.length; index++) { + let cell = header.eq(index); + let text = cell.text(); + + // 评论数 + if (cell.find("a[href*='comments']").length) { + fieldIndex.comments = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 发布时间 + if ( + cell.find("a[href*='created_at']").length || + cell.find("i.fa-clock").length + ) { + fieldIndex.time = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 大小 + if ( + cell.find("a[href*='size']").length || + cell.find("i.fa-file").length + ) { + fieldIndex.size = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 种子数 + if ( + cell.find("a[href*='seed']").length || + cell.find("i.fa-arrow-circle-up").length + ) { + fieldIndex.seeders = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 下载数 + if ( + cell.find("a[href*='leech']").length || + cell.find("i.fa-arrow-circle-down").length + ) { + fieldIndex.leechers = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 完成数 + if ( + cell.find("a[href*='complete']").length || + cell.find("i.fa-check-square").length + ) { + fieldIndex.completed = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + + // 分类 + if (cell.is(".torrents-icon")) { + fieldIndex.category = index; + fieldIndex.author = + index == fieldIndex.author ? -1 : fieldIndex.author; + continue; + } + } + + try { + // 遍历数据行 + for (let index = beginRowIndex; index < rows.length; index++) { + const row = rows.eq(index); + let cells = row.find(">td"); + + let title = row.find("a.view-torrent"); + if (title.length == 0) { + continue; + } + let link = title.attr("href"); + if (link && link.substr(0, 4) !== "http") { + link = `${site.url}${link}`; + } + + // 获取下载链接 + let url = ""; + + let downloadURL = row.find("a[href*='/download/']"); + if (downloadURL.length == 0) { + downloadURL = row.find("a[href*='/download_check/']"); + if (downloadURL.length > 0) { + url = downloadURL + .attr("href") + .replace("/download_check/", "/download/"); + } + } else { + url = downloadURL.attr("href"); + } + + if (url.length == 0) { + continue; + } + + if (url && url.substr(0, 4) !== "http") { + url = `${site.url}${url}`; + } + + let data = { + title: title.text(), + subTitle: this.getSubTitle(title, row), + link, + url: url, + size: + cells + .eq(fieldIndex.size) + .text() + .trim() || 0, + time: + fieldIndex.time == -1 + ? "" + : cells + .eq(fieldIndex.time) + .find("span[title]") + .attr("title") || + cells.eq(fieldIndex.time).text().replace('秒前', ' seconds ago').replace('秒前', ' seconds ago').replace('分钟前', ' minutes ago').replace('分鐘前', ' minutes ago').replace('天前', ' day ago').replace('小時前', ' hours ago').replace('小时前', ' hours ago')|| + "", + author: + fieldIndex.author == -1 + ? "" + : cells.eq(fieldIndex.author).text() || "", + seeders: + fieldIndex.seeders == -1 + ? "" + : cells.eq(fieldIndex.seeders).text() || 0, + leechers: + fieldIndex.leechers == -1 + ? "" + : cells.eq(fieldIndex.leechers).text() || 0, + completed: + fieldIndex.completed == -1 + ? "" + : cells.eq(fieldIndex.completed).text() || 0, + comments: + fieldIndex.comments == -1 + ? "" + : cells.eq(fieldIndex.comments).text() || 0, + site: site, + tags: Searcher.getRowTags(site, row), + entryName: options.entry.name, + category: + fieldIndex.category == -1 + ? null + : this.getCategory(cells.eq(fieldIndex.category)), + progress: this.getFieldValue(row, cells, fieldIndex, "progress"), + status: this.getFieldValue(row, cells, fieldIndex, "status") + }; + results.push(data); + } + if (results.length == 0) { + options.status = ESearchResultParseStatus.noTorrents; // `[${options.site.name}]没有搜索到相关的种子`; + } + } catch (error) { + console.log(error); + options.status = ESearchResultParseStatus.parseError; + options.errorMsg = error.stack; //`[${options.site.name}]获取种子信息出错: ${error.stack}`; + } + + return results; + } + + /** + * 获取标签 + * @param {*} row + * @param {*} selectors + * @return array + */ + getTags(row, selectors) { + let tags = []; + if (selectors && selectors.length > 0) { + selectors.forEach(item => { + if (item.selector) { + let result = row.find(item.selector); + if (result.length) { + tags.push({ + name: item.name, + color: item.color + }); + } + } + }); + } + return tags; + } + + /** + * 获取副标题 + * @param {*} title + * @param {*} row + */ + getSubTitle(title, row) { + return ""; + } + + /** + * 获取分类 + * @param {*} cell 当前列 + */ + getCategory(cell) { + let result = { + name: cell.find("i:first").attr("data-original-title"), + link: cell.find("a:first").attr("href") + }; + if (result.name) { + result.name = result.name.replace(" torrent", ""); + } + return result; + } + + getFieldValue(row, cells, fieldIndex, fieldName, returnCell) { + let parent = row; + let cell = null; + if ( + cells && + fieldIndex && + fieldIndex[fieldName] !== undefined && + fieldIndex[fieldName] !== -1 + ) { + cell = cells.eq(fieldIndex[fieldName]); + parent = cell || row; + } + + let result = Searcher.getFieldValue(site, parent, fieldName); + + if (!result && cell) { + if (returnCell) { + return cell; + } + result = cell.text(); + } + + return result; + } + } + + let parser = new Parser(options); + options.results = parser.getResult(); + console.log(options.results); +})(options, options.searcher);