-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
959b5f0
commit e861409
Showing
2 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
(function(options) { | ||
class Parser { | ||
constructor() { | ||
this.haveData = false; | ||
this.categories = {}; | ||
if (/auth_form/.test(options.responseText)) { | ||
options.status = ESearchResultParseStatus.needLogin; | ||
return; | ||
} | ||
options.isLogged = true; | ||
this.haveData = true; | ||
this.authkey = ""; | ||
this.passkey = ""; | ||
} | ||
|
||
start() { | ||
this.getAuthKey() | ||
.then(() => { | ||
options.resolve(this.getResult()); | ||
}) | ||
.catch(() => { | ||
options.reject({ | ||
success: false, | ||
msg: options.searcher.getErrorMessage( | ||
options.site, | ||
ESearchResultParseStatus.parseError, | ||
options.errorMsg | ||
), | ||
data: { | ||
site: options.site, | ||
isLogged: options.isLogged | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* 获取搜索结果 | ||
*/ | ||
|
||
getResult() { | ||
if (!this.haveData) { | ||
return []; | ||
} | ||
let site = options.site; | ||
let groups = options.page.response.results; | ||
if (groups.length == 0) { | ||
options.status = ESearchResultParseStatus.noTorrents; | ||
return []; | ||
} | ||
let results = []; | ||
let authkey = this.authkey; | ||
let passkey = this.passkey; | ||
console.log("groups.length", groups.length); | ||
try { | ||
groups.forEach(group => { | ||
if (group.hasOwnProperty("torrents")) { | ||
let torrents = group.torrents; | ||
torrents.forEach(torrent => { | ||
let data = { | ||
title: | ||
group.artist + | ||
" - " + | ||
group.groupName + | ||
" [" + | ||
group.groupYear + | ||
"] [" + | ||
group.releaseType + | ||
"]", | ||
subTitle: | ||
torrent.codec + | ||
" / " + | ||
torrent.source + | ||
" / " + | ||
torrent.resolution + | ||
" / " + | ||
torrent.container + | ||
" / " + | ||
torrent.processing + | ||
(torrent.remasterTitle ? ` / ${torrent.remasterTitle}` : "") + | ||
(torrent.scene ? " / Scene" : "") + | ||
(torrent.isFreeleech || | ||
torrent.isNeutralLeech || | ||
torrent.isPersonalFreeleech | ||
? " / Freeleech" | ||
: ""), | ||
link: `${site.url}torrents.php?id=${group.groupId}&torrentid=${torrent.torrentId}`, | ||
url: `${site.url}torrents.php?action=download&id=${torrent.torrentId}&authkey=${authkey}&torrent_pass=${passkey}`, | ||
size: parseFloat(torrent.size), | ||
time: torrent.time, | ||
seeders: torrent.seeders, | ||
leechers: torrent.leechers, | ||
completed: torrent.snatches, | ||
site: site, | ||
entryName: options.entry.name, | ||
category: group.releaseType | ||
}; | ||
results.push(data); | ||
}); | ||
} else { | ||
let data = { | ||
title: group.groupName, | ||
link: `${site.url}torrents.php?id=${group.groupId}&torrentid=${group.torrentId}`, | ||
url: `${site.url}torrents.php?action=download&id=${group.torrentId}&authkey=${authkey}&torrent_pass=${passkey}`, | ||
size: parseFloat(group.size), | ||
time: group.groupTime, | ||
author: "", | ||
seeders: group.seeders, | ||
leechers: group.leechers, | ||
completed: group.snatches, | ||
comments: 0, | ||
site: site, | ||
tags: group.tags, | ||
entryName: options.entry.name, | ||
category: group.category | ||
}; | ||
results.push(data); | ||
} | ||
}); | ||
console.log("results.length", results.length); | ||
if (results.length == 0) { | ||
options.status = ESearchResultParseStatus.noTorrents; | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
options.status = ESearchResultParseStatus.parseError; | ||
options.errorMsg = error.stack; | ||
} | ||
return results; | ||
} | ||
|
||
/** | ||
* 获取 AuthKey ,用于组合完整的下载链接 | ||
*/ | ||
getAuthKey() { | ||
const url = (options.site.activeURL + "/ajax.php?action=index") | ||
.replace("://", "****") | ||
.replace(/\/\//g, "/") | ||
.replace("****", "://"); | ||
|
||
return new Promise((resolve, reject) => { | ||
$.get(url) | ||
.done(result => { | ||
if (result && result.status === "success" && result.response) { | ||
this.authkey = result.response.authkey; | ||
this.passkey = result.response.passkey; | ||
resolve(); | ||
} else { | ||
reject(); | ||
} | ||
}) | ||
.fail(() => { | ||
reject(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
let parser = new Parser(options); | ||
parser.start(); | ||
})(options); |