Skip to content

Commit

Permalink
fix: EZ评论页面改版修复
Browse files Browse the repository at this point in the history
#667
另外3个站还是以前的界面
  • Loading branch information
ted423 committed Oct 23, 2021
1 parent 69de776 commit 81d7c21
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resource/sites/exoticaz.to/config.json
Expand Up @@ -7,6 +7,14 @@
"tags": ["Adult"],
"schema": "AvistaZ",
"host": "exoticaz.to",
"searchEntry": [{
"entry": "/torrents?in=1&search=$key$",
"name": "全部",
"resultType": "html",
"parseScriptFile": "getSearchResult.js",
"resultSelector": "div.table-responsive > table:first",
"enabled": true
}],
"selectors": {
"common": {
"merge": true,
Expand Down
259 changes: 259 additions & 0 deletions resource/sites/exoticaz.to/getSearchResult.js
@@ -0,0 +1,259 @@
(function(options, Searcher) {
class Parser {
constructor() {
this.haveData = false;
if (/\/auth\/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;
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: 0,
progress: null,
status: null
};

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*='age']").length) {
fieldIndex.time = index;
fieldIndex.author =
index == fieldIndex.author ? -1 : fieldIndex.author;
continue;
}

// 大小
if (cell.find("a[href*='size']").length) {
fieldIndex.size = index;
fieldIndex.author =
index == fieldIndex.author ? -1 : fieldIndex.author;
continue;
}

// 种子数
if (cell.find("a[href*='seed']").length) {
fieldIndex.seeders = index;
fieldIndex.author =
index == fieldIndex.author ? -1 : fieldIndex.author;
continue;
}

// 下载数
if (cell.find("a[href*='leech']").length) {
fieldIndex.leechers = index;
fieldIndex.author =
index == fieldIndex.author ? -1 : fieldIndex.author;
continue;
}

// 完成数
if (cell.find("a[href*='complete']").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.torrent-filename, a.torrent-link");
if (title.length == 0) {
continue;
}
let link = title.attr("href");
if (link && link.substr(0, 4) !== "http") {
link = `${site.url}${link}`;
}

// 获取下载链接
let url = row.find("a[href*='/download/torrent/']").attr("href");

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() ||
"",
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).find(".tag.tag-blue").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.getProgress(row, "progress"),
status: this.getStatus(row, "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 {*} title
* @param {*} row
*/
getSubTitle(title, row) {
return "";
}

getProgress(row, fieldName, returnCell) {
let result =null;
if(row.attr('class').indexOf('success')!=-1) result = 100;
else if(row.attr('class').indexOf('warning')!=-1) result = 100;
else if(row.attr('class').indexOf('danger')!=-1) result = 100;
else if(row.attr('class').indexOf('info')!=-1) result = 0;
return result;
}

getStatus(row, fieldName, returnCell) {
let result =null;
if(row.attr('class').indexOf('success')!=-1) result = 2;
else if(row.attr('class').indexOf('warning')!=-1) result = 3;
else if(row.attr('class').indexOf('danger')!=-1) result = 3;
else if(row.attr('class').indexOf('info')!=-1) result = 1;
return result;
}
/**
* 获取分类
* @param {*} cell 当前列
*/
getCategory(cell) {
let result = {
name: cell.find("i:first").attr("title"),
link: ""
};
if (result.name) {
result.name = result.name.replace(" Torrent", "");
}
return result;
}
}

let parser = new Parser(options);
options.results = parser.getResult();
console.log(options.results);
})(options, options.searcher);

0 comments on commit 81d7c21

Please sign in to comment.