Skip to content

Commit

Permalink
fix: AB search not functioning
Browse files Browse the repository at this point in the history
  • Loading branch information
MewX committed Dec 29, 2021
1 parent 9101724 commit e3f15c7
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 3 deletions.
16 changes: 13 additions & 3 deletions resource/sites/animebytes.tv/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"schema": "",
"host": "animebytes.tv",
"collaborator": [
"sabersalv",
"MewX"
"MewX",
"sabersalv"
],
"supportedFeatures": {
"userData": true,
"search": false,
"search": true,
"imdbSearch": false,
"sendTorrent": false
},
Expand All @@ -35,6 +35,16 @@
"authkey",
"torrent_pass"
],
"searchEntry": [
{
"entry": "/torrents.php?searchstr=$key$&force_default=1",
"name": "default",
"resultType": "html",
"parseScriptFile": "getSearchResult.js",
"resultSelector": "div.group_cont",
"enabled": true
}
],
"selectors": {
"userBaseInfo": {
"page": "/index.php",
Expand Down
108 changes: 108 additions & 0 deletions resource/sites/animebytes.tv/getSearchResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
if (!"".getQueryString) {
String.prototype.getQueryString = function (name, split) {
if (split == undefined) split = "&";
var reg = new RegExp(
"(^|" + split + "|\\?)" + name + "=([^" + split + "]*)(" + split + "|$)"
),
r;
if ((r = this.match(reg))) return decodeURI(r[2]);
return null;
};
}

(function (options) {
class Parser {
constructor() {
this.haveData = false;
this.categories = {};
if (/loginform/.test(options.responseText)) {
options.status = ESearchResultParseStatus.needLogin; //`[${options.site.name}]需要登录后再搜索`;
return;
}
options.isLogged = true;

if (/File slips through fingers/.test(options.responseText)) {
options.status = ESearchResultParseStatus.noTorrents; //`[${options.site.name}]没有搜索到相关的种子`;
return;
}
this.haveData = true;
}

/**
* Get search results.
*/
getResult() {
let site = options.site;
let results = [];

// Get groups. Each group has one title and several torrents.
let groups = options.page.find(options.resultSelector);
if (groups.length == 0) {
options.status = ESearchResultParseStatus.torrentTableIsEmpty; //`[${options.site.name}]没有定位到种子列表,或没有相关的种子`;
return results;
}

try {
for (let ig = 0; ig < groups.length; ig++) {
// Get group info.
let group = groups.eq(ig);
let groupTitle = group.find(".group_title").find("strong:first").text();
if (groupTitle.length == 0) {
continue;
}
let category = group.find("span.cat:first").text();

// Get torrent info.
let torrents = group.find(".torrent_group:first").find("tr.torrent");
for (let i = 0; i < torrents.length; i++) {
let t = torrents.eq(i);
let subTitle = t.find(".torrent_properties:first").find("a:last").text();
let dlLink = site.url + t.find(".download_link:first").find("a:first").attr("href");
let torrentURL = site.url + t.find(".torrent_properties:first").find("a:last").attr("href");
let size = t.find(".torrent_size:first").text();
let snatched = t.find(".torrent_snatched:first").text();
let seeders = t.find(".torrent_seeders:first").text();
let leechers = t.find(".torrent_leechers:first").text();

// Basic validations.
if (dlLink.length == 0) {
console.log("[%s] Invalid torrent link for \"%s\": %s", site.name, groupTitle, dlLink);
continue;
}

let data = {
title: groupTitle,
subTitle: subTitle,
link: torrentURL, // Note: link means the torrent page.
url: dlLink, // Note: url means the download link.
size: size,
time: "",
author: "",
seeders: seeders,
leechers: leechers,
completed: snatched,
comments: "",
site: site,
entryName: options.entry.name, // TODO: support specifying entry name.
category: category,
};
results.push(data);
}
}
if (results.length == 0) {
options.status = ESearchResultParseStatus.noTorrents; //`[${options.site.name}]没有搜索到相关的种子`;
}
} catch (error) {
console.error(error);
options.status = ESearchResultParseStatus.parseError;
options.errorMsg = error.stack; //`[${options.site.name}]获取种子信息出错: ${error.stack}`;
}
return results;
}

}

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

0 comments on commit e3f15c7

Please sign in to comment.