Skip to content

Commit

Permalink
fix: ccf详情页连接获取
Browse files Browse the repository at this point in the history
  • Loading branch information
ted423 committed Nov 15, 2021
1 parent 139a742 commit 75475d8
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 2 deletions.
123 changes: 123 additions & 0 deletions resource/sites/ccfbits.org/browse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
(function($) {
console.log("this is browse.js");
class App extends window.NexusPHPCommon {
init() {
this.initButtons();
this.initFreeSpaceButton();
// 设置当前页面
PTService.pageApp = this;
}

/**
* 初始化按钮列表
*/
initButtons() {
this.initListButtons(true);
}

/**
* 获取下载链接
*/
getDownloadURLs() {
let links = $("a.bookmark").toArray();
let urls = $.map(links, item => {
let id = $(item).attr("tid");
return this.getDownloadURL(id);
});

if (links.length == 0) {
return "获取下载链接失败,未能正确定位到链接";
}

return urls;
}

getDownloadURL(id) {
// 格式:vvvid|||passkeyzz
let key = new Base64().encode(
"vvv" + id + "|||" + PTService.site.passkey + "zz"
);
return `https://${PTService.site.host}/rssdd.php?par=${key}&ssl=yes`;
}

/**
* 执行指定的操作
* @param {*} action 需要执行的执令
* @param {*} data 附加数据
* @return Promise
*/
call(action, data) {
return new Promise((resolve, reject) => {
switch (action) {
// 从当前的DOM中获取下载链接地址
case PTService.action.downloadFromDroper:
this.downloadFromDroper(data, () => {
resolve();
});
break;
}
});
}

/**
* 下载拖放的种子
* @param {*} data
* @param {*} callback
*/
downloadFromDroper(data, callback) {
if (!PTService.site.passkey) {
PTService.showNotice({
msg: "请先设置站点密钥(Passkey)。"
});
callback();
return;
}

if (typeof data === "string") {
data = {
url: data,
title: ""
};
}

let result = this.getDroperURL(data.url);

if (!result) {
callback();
return;
}

this.sendTorrentToDefaultClient(result)
.then(result => {
callback(result);
})
.catch(result => {
callback(result);
});
}

/**
* 获取有效的拖放地址
* @param {*} url
*/
getDroperURL(url) {
let values = url.split("/");
let id = values[values.length - 2];
let result = this.getDownloadURL(id);

return result;
}

/**
* 确认大小是否超限
*/
confirmWhenExceedSize() {
return this.confirmSize(
$("#torrent_table").find(
"td[align='center']:contains('MB'),td[align='center']:contains('GB'),td[align='center']:contains('TB')"
)
);
}
}
new App().init();
})(jQuery);
4 changes: 2 additions & 2 deletions resource/sites/ccfbits.org/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"scripts": [
"/schemas/NexusPHP/common.js",
"/sites/totheglory.im/details.js"
"details.js"
]
},
{
Expand All @@ -28,7 +28,7 @@
],
"scripts": [
"/schemas/NexusPHP/common.js",
"/sites/totheglory.im/browse.js"
"browse.js"
]
}
],
Expand Down
62 changes: 62 additions & 0 deletions resource/sites/ccfbits.org/details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(function ($, window) {
console.log("this is details.js");
class App extends window.NexusPHPCommon {
init() {
this.initButtons();
// 设置当前页面
PTService.pageApp = this;
}
/**
* 初始化按钮列表
*/
initButtons() {
this.showTorrentSize();
this.initDetailButtons();
}

/**
* 获取下载链接
*/
getDownloadURL() {
// 有一些扩展会为链接添加class,导致选择器失效,因此使用正则来获取链接
// let query = $("a[href*='/dl/']:not([class])");
let query = $("a[href*='download.php']")

let url = "";
if (query.length > 0) {
url = query.attr("href");
// 直接获取的链接下载成功率很低
// 如果设置了 passkey 则使用 rss 订阅的方式下载
if (PTService.site.passkey) {
let values = url.split("/");
let id = values[values.length - 2];

// 格式:vvvid|||passkeyzz
let key = (new Base64).encode("vvv" + id + "|||" + PTService.site.passkey + "zz");
url = `https://${PTService.site.host}/rssdd.php?par=${key}&ssl=yes`;
}
}

return url;
}

showTorrentSize() {
let query = $("td[valign='top'][align='left']:contains('字节')");
let size = "";
if (query.length > 0) {
size = query.text().split(" (")[0];
// attachment
PTService.addButton({
title: "当前种子大小",
icon: "attachment",
label: size
});
}
}

getTitle() {
return /"(.*?)"/.exec($("title").text())[1];
}
}
(new App()).init();
})(jQuery, window);

0 comments on commit 75475d8

Please sign in to comment.