Skip to content

Commit

Permalink
fix(mt): userUploadedTorrents #1762
Browse files Browse the repository at this point in the history
  • Loading branch information
fzlins committed Mar 24, 2024
1 parent 58bcfdd commit f05323a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 53 deletions.
48 changes: 45 additions & 3 deletions resource/sites/xp.m-team.io/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"icon": "https://xp.m-team.io/favicon.ico",
"tags": ["影视", "综合","成人"],
"host": "xp.m-team.io",
"schema": "mTorrent",
"cdn": ["https://xp.m-team.io", "https://kp.m-team.cc","https://xp.m-team.cc","https://ap.m-team.cc"],
"formerHosts": [
"pt.m-team.cc",
Expand Down Expand Up @@ -263,9 +264,6 @@
"downloaded": {
"selector": ["data.memberCount.downloaded"]
},
"ratio": {
"selector": ["data.memberCount.shareRate"]
},
"levelName": {
"selector": ["data.role"],
"filters": ["if (query == '1') { 'User'; } else if (query == '2') { 'Power User'; } else if (query == '3') { 'Elite User'; } else if (query == '4') { 'Crazy User'; } else if (query == '5') { 'Insane User'; } else if (query == '6') { 'Veteran User'; } else if (query == '7') { 'Extreme User'; } else if (query == '8') { 'Ultimate User'; } else if (query == '9') { 'Nexus Master'; } else { query; }"]
Expand All @@ -274,6 +272,50 @@
"selector": ["data.memberCount.bonus"]
}
}
},
"userExtendInfo":{
"page": "/api/msg/statistic",
"dataType": "json",
"requestMethod": "POST",
"fields": {
"message": {
"selector": ["data.unMake"]
}
}
},
"userSeedingTorrents": {
"page": "/api/member/getUserTorrentList",
"dataType": "json",
"requestMethod": "POST",
"requestContentType": "application/json",
"requestData": {
"userid": "$user.id$",
"type": "SEEDING",
"pageNumber": "1",
"pageSize": "1"
},
"fields": {
"seeding": {
"selector": ["data.total"]
}
}
},
"userUploadedTorrents": {
"page": "/api/member/getUserTorrentList",
"dataType": "json",
"requestMethod": "POST",
"requestContentType": "application/json",
"requestData": {
"userid": "$user.id$",
"type": "UPLOADED",
"pageNumber": "1",
"pageSize": "1"
},
"fields": {
"uploads": {
"selector": ["data.total"]
}
}
}
}
}
83 changes: 34 additions & 49 deletions resource/sites/xp.m-team.io/getUserSeedingTorrents.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
if ("".getQueryString === undefined) {
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, User) {
class Parser {
constructor(options, dataURL) {
Expand All @@ -19,11 +7,12 @@ if ("".getQueryString === undefined) {
this.rawData = "";
this.pageInfo = {
count: 0,
current: 0
current: 0,
size: 100
};
this.result = {
seeding: 0,
seedingSize: 0
uploads: 0,
uploadsSize: 0
};
this.load();
}
Expand All @@ -39,25 +28,26 @@ if ("".getQueryString === undefined) {
* 解析内容
*/
parse() {
const doc = new DOMParser().parseFromString(this.rawData, "text/html");
// 构造 jQuery 对象
this.body = $(doc).find("body");

this.getPageInfo();

let results = new User.InfoParser(User.service).getResult(
this.body,
this.options.rule
);

if (results) {
this.result.seeding += results.seeding;
this.result.seedingSize += results.seedingSize;
let datas = this.rawData.data.data;
let results = {
uploads: 0,
uploadsSize: 0
};
if (datas) {
datas.forEach(item => {
results.uploads++;
results.uploadsSize += item[0].size;
});
}

this.result.uploads += results.uploads;
this.result.uploadsSize += results.uploadsSize;

this.pageInfo.current++;
// 是否已到最后一页
if (this.pageInfo.current < this.pageInfo.count) {
this.pageInfo.current++;
this.load();
} else {
this.done();
Expand All @@ -71,30 +61,32 @@ if ("".getQueryString === undefined) {
if (this.pageInfo.count > 0) {
return;
}
// 获取最大页码
const infos = this.body
.find("a[href*='type=seeding']:contains('1'):last")
.attr("href");

if (infos) {
this.pageInfo.count = parseInt(infos.getQueryString("page"));
} else {
this.pageInfo.count = 1;
}
this.pageInfo.count = this.rawData.data.totalPages;
}

/**
* 加载当前页内容
*/
load() {
let url = this.dataURL;
if (this.pageInfo.current > 0) {
url += "&page=" + this.pageInfo.current;
}
$.get(url)
let postData = this.options.rule.requestData;
postData.pageNumber = this.pageInfo.current + 1;

$.ajax({
url,
method: "POST",
dataType: "JSON",
data: JSON.stringify(postData),
contentType: "application/json"
})
.done(result => {
this.rawData = result;
this.parse();
if (this.rawData.data.data.length > 0) {
this.parse();
} else {
this.done();
}
})
.fail(() => {
this.done();
Expand All @@ -103,12 +95,6 @@ if ("".getQueryString === undefined) {
}

let dataURL = options.site.activeURL + options.rule.page;
dataURL = dataURL
.replace("$user.id$", options.userInfo.id)
.replace("$user.name$", options.userInfo.name)
.replace("://", "****")
.replace(/\/\//g, "/")
.replace("****", "://");

new Parser(options, dataURL);
})(_options, _self);
Expand All @@ -122,6 +108,5 @@ if ("".getQueryString === undefined) {
resolve,
reject
}
_self 表示 User(/src/background/user.ts) 类实例
*/
3 changes: 2 additions & 1 deletion src/background/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ export class User {
url,
method: rule.requestMethod || ERequestMethod.GET,
dataType: "text",
data: requestData,
data: rule.requestContentType == "application/json" ? JSON.stringify(requestData) : requestData,
contentType: rule.requestContentType == "application/json" ? "application/json" : "application/x-www-form-urlencoded",
headers: rule.headers,
timeout: this.service.options.connectClientTimeout || 30000,
cache: false
Expand Down

0 comments on commit f05323a

Please sign in to comment.