Skip to content

Commit

Permalink
Merge branch 'dev' into default
Browse files Browse the repository at this point in the history
  • Loading branch information
ted423 committed Feb 17, 2022
2 parents 92581e8 + 6e34444 commit 52aaa3c
Show file tree
Hide file tree
Showing 52 changed files with 2,413 additions and 722 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"ts-node": "^8.5.2",
"typescript": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"unique-commit-id": "^1.0.0",
"git-commit-id": "^2.0.1",
"vue-cli-plugin-vuetify": "^0.4.6",
"vue-template-compiler": "^2.5.17",
"vuetify-loader": "^1.0.5",
Expand Down
102 changes: 52 additions & 50 deletions resource/clients/synologyDownloadStation/init.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @see https://global.download.synology.com/download/Document/DeveloperGuide/Synology_Download_Station_Web_API.pdf
* @backport https://github.com/ronggang/PT-Plugin-Plus/blob/48c2d42a1d05c129c0abbbecf653b1b7d88a8a8e/src/resource/btClients/src/clients/synologyDownloadStation.ts
*/
(function ($, window) {
class Client {

init(options) {
this.options = options;
this.sessionId = "";
this.version = 2;
if (this.options.address.substr(-1) == "/") {
this.options.address = this.options.address.substr(0, this.options.address.length - 1);
}
Expand All @@ -18,7 +18,7 @@
*/
getSessionId() {
return new Promise((resolve, reject) => {
let url = `${this.options.address}/webapi/auth.cgi?api=SYNO.API.Auth&version=${this.version}&method=login&account=${encodeURIComponent(this.options.loginName)}&passwd=${encodeURIComponent(this.options.loginPwd)}&session=DownloadStation&format=sid`;
let url = `${this.options.address}/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account=${encodeURIComponent(this.options.loginName)}&passwd=${encodeURIComponent(this.options.loginPwd)}&session=DownloadStation&format=sid`;
$.ajax({
url,
timeout: PTBackgroundService.options.connectClientTimeout,
Expand Down Expand Up @@ -83,8 +83,8 @@

/**
* 添加种子链接
* @param {*} options
* @param {*} callback
* @param {*} options
* @param {*} callback
*/
addTorrentFromUrl(options, callback) {
if (!this.sessionId) {
Expand All @@ -102,64 +102,66 @@
})
return;
}
// let path = [`${this.options.address}/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task`,
// `version=${this.version}`,
// `method=create`,
// `_sid=${this.sessionId}`,
// `uri=` + encodeURIComponent(options.url),
// `destination=` + encodeURIComponent(options.savePath)
// ];
// $.ajax({
// url: path.join("&"),
// timeout: PTBackgroundService.options.connectClientTimeout,
// dataType: "json"
// }).done((result) => {
// console.log(result)
// callback(result)
// }).fail(() => {
// callback({
// status: "error",
// msg: "服务器连接失败"
// })
// })

PTBackgroundService.requestMessage({
action: "getTorrentDataFromURL",
data: options.url
})
.then((result) => {
let formData = new FormData();
formData.append("_sid", this.sessionId);
formData.append("api", "SYNO.DownloadStation.Task");
formData.append("version", this.version);
formData.append("method", "create");

if (options.savePath) {
let savePath = options.savePath + "";
// 去除路径最后的 / ,以确保可以正常添加目录信息
if (savePath.substr(-1) == "/") {
savePath = savePath.substr(0, savePath.length - 1);

let postData = {
api: 'SYNO.DownloadStation2.Task',
method: 'create',
version: 2,
create_list: false,
_sid: this.sessionId // fxxk, _sid 参数不能放在第一位,不然会直接 101 报错
}

// fxxk, 没有 destination 参数也会直接报错
let savePath = (options.savePath || "") + "";
if (savePath.substr(-1) === "/") { // 去除路径最后的 / ,以确保可以正常添加目录信息
savePath = savePath.substr(0, savePath.length - 1);
}
postData.destination = `"${savePath || ''}"`;

if (options.url.startsWith('magnet:')) {
postData.type = '"url"';
postData.url = [options.url];

this.addTorrent(postData, options, callback);
} else {
postData.type = '"file"';
postData.file = ['torrent'];

let formData = new FormData();
Object.keys(postData).forEach((k) => {
let v = postData[k];
if (v !== undefined) {
if (Array.isArray(v)) {
v = JSON.stringify(v);
}
formData.append("destination", savePath)
formData.append(k,v);
}
});

formData.append("file", result, "file.torrent")

this.addTorrent(formData, options, callback);
PTBackgroundService.requestMessage({
action: "getTorrentDataFromURL",
data: options.url
})
.catch((result) => {
callback && callback(result);
});
.then((result) => {
formData.append("torrent", result, "file.torrent")

this.addTorrent(formData, options, callback);
})
.catch((result) => {
callback && callback(result);
});

}
}

addTorrent(formData, options, callback) {
$.ajax({
url: `${this.options.address}/webapi/DownloadStation/task.cgi`,
url: `${this.options.address}/webapi/entry.cgi`,
timeout: PTBackgroundService.options.connectClientTimeout,
type: "POST",
processData: false,
contentType: false,
method: "POST",
data: formData,
dataType: "json"
}).done((result) => {
Expand Down Expand Up @@ -202,4 +204,4 @@
}
// 添加到 window 对象,用于客户页面调用
window.synologyDownloadStation = Client;
})(jQuery, window)
})(jQuery, window)
1 change: 1 addition & 0 deletions resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
"seeders": "S",
"leechers": "L",
"completed": "C",
"comments": "Comments",
"time": "Time(≈)",
"action": "Action"
},
Expand Down
4 changes: 2 additions & 2 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@
"seeders": "上传",
"leechers": "下载",
"completed": "完成",
"comments": "评论",
"time": "发布于(≈)",
"action": "操作",
"comments": "评论"
"action": "操作"
},
"optionsIsMissing": "系统参数丢失",
"sitesIsMissing": "请先设置站点",
Expand Down
4 changes: 2 additions & 2 deletions resource/schemas/GazelleJSONAPI/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"page": "/torrents.php?type=seeding&userid=$user.id$",
"fields": {
"seedingSize": {
"selector": ["tr.torrent_row > td.nobr"],
"selector": ["tr.torrent_row > td.number_column.nobr"],
"filters": ["jQuery.map(query, (item)=>{return $(item).text();})", "_self.getTotalSize(query)"]
},
"bonus": {
Expand All @@ -72,4 +72,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion resource/schemas/IPTorrents/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ver": "0.0.1",
"plugins": [{
"name": "种子详情页面",
"pages": ["/details.php"],
"pages": ["/torrent.php"],
"scripts": ["/schemas/NexusPHP/common.js", "details.js"]
}, {
"name": "种子列表",
Expand Down
4 changes: 2 additions & 2 deletions resource/schemas/UNIT3D/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
"bonus": {
"selector": ["div.ratio-bar i.fa-coins"],
"filters": ["query.parent().text().trim().replace(/\\s/g,'').match(/([\\d.]+)/)", "(query && query.length>=2)?parseFloat(query[1]):0"]
"filters": ["query.parent().text().trim().replace(/,|\\s/g,'').match(/([\\d.]+)/)", "(query && query.length>=2)?parseFloat(query[1]):0"]
},
"seeding": {
"selector": ["div.ratio-bar i.fa-upload"],
Expand Down Expand Up @@ -113,4 +113,4 @@
}
}
}
}
}
25 changes: 24 additions & 1 deletion resource/sites/aither.cc/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,28 @@
"综合"
],
"host": "aither.cc",
"collaborator": "MewX"
"collaborator": "MewX",
"searchEntry": [
{
"name": "全部",
"enabled": true
}
],
"searchEntryConfig": {
"page": "/torrents",
"queryString": "perPage=100&name=$key$",
"area": [
{
"name": "IMDB",
"keyAutoMatch": "^(tt\\d+)$",
"queryString": "perPage=100&imdbId=$key$",
"replaceKey": [
"tt",
""
]
}
],
"resultType": "html",
"parseScriptFile": "getSearchResult.js"
}
}
124 changes: 124 additions & 0 deletions resource/sites/aither.cc/getSearchResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
(function (options, Searcher) {
class Parser {
constructor() {
this.haveData = false;
if (/\/login/.test(options.responseText)) {
options.status = ESearchResultParseStatus.needLogin;
return;
}

// Logging in is required.
options.isLogged = true;
this.haveData = true;
}

/**
* Getting the search results.
*/
getResult() {
if (!this.haveData) {
return [];
}
let site = options.site;
site.searchEntryConfig = options.entry
let selector = "#torrent-list-table";
let table = options.page.find(selector);
let rows = table.find("> tbody > tr");
if (rows.length == 0) {
options.status = ESearchResultParseStatus.torrentTableIsEmpty;
return [];
}

let results = [];
try {
// For each torrent in the table.
for (let index = 0; index < rows.length; index++) {
const row = rows.eq(index);

// Torrent title.
const title = row.find(".torrent-listings-overview > .torrent-listings-name").text();
const subTitle = "";
// Time uploaded.
const time = row.find(".torrent-listings-age").text();
// File size.
const size = row.find(".torrent-listings-size").text();
// Number of seeders.
const seeders = row.find(".torrent-listings-seeders").text().trim();
// Number of leechers.
const leechers = row.find(".torrent-listings-leechers").text().trim();
// Number of downloads.
const completed = row.find(".torrent-listings-completed").text().trim();
// Number of comments.
const comments = row.find(".torrent-listings-overview > .torrent-listings-comments").text().trim();
// Uploader.
const author = row.find(".torrent-listings-uploader").text();
// Category
const categoryURL = row.find(".torrent-listings-format > a").attr('href');
const category = this.getCategory(
categoryURL == null ? -1 :
parseInt(categoryURL.substr(categoryURL.lastIndexOf("/") + 1)));
// Download link to the torrent.
const link = row.find(".torrent-listings-download > a").attr('href');
// Link to the detail page.
const url = row.find(".torrent-listings-overview > .torrent-listings-name").attr('href');

// Adding to the results.
results.push({
title,
subTitle,
link,
url,
size,
time,
author,
seeders,
leechers,
completed,
comments,
site,
tags: Searcher.getRowTags(site, row), // TODO: better tags.
entryName: options.entry.name,
category,
progress: null, // TODO: add support.
status: null, // TODO: add support.
});
}
if (results.length == 0) {
options.status = ESearchResultParseStatus.noTorrents;
}
} catch (error) {
console.log(error);
options.status = ESearchResultParseStatus.parseError;
options.errorMsg = error.stack;
alert(error.stack);
}

return results;
}

/**
* Get the Cateogry Names.
* @param {*} categoryKey The category ID from URL.
*/
getCategory(categoryKey) {
// List of cateogories: https://aither.cc/categories.
const categoryMap = {
1: "Movie",
2: "TV",
3: "Music",
4: "Games",
6: "XXX",
9: "Sport",
10: "Software & Apps",
11: "Ebooks & Magazines",
14: "Audiobooks",
15: "Education",
}
return categoryKey in categoryMap ? categoryMap[categoryKey] : null;
}
}

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

0 comments on commit 52aaa3c

Please sign in to comment.