Skip to content

Commit

Permalink
fix(mt): 批量下载, 详情页下载 #1762
Browse files Browse the repository at this point in the history
* 批量下载解析进度提醒
  • Loading branch information
IITII committed Mar 27, 2024
1 parent 8115fa7 commit 8f0a60b
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 126 deletions.
3 changes: 2 additions & 1 deletion resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@
"exceedSizeCanceled": "Oversized has been cancelled",
"downloadURLsFinished": "{count} links have been sent.",
"downloadURLsTip": "Sending: {text}",
"resolveURLsTip": "Resolving torrent id:{id}, progress:{current}/{total}, approximately {min} minutes left",
"search": {
"needLogin": "[{siteName}] needs to log in and search again",
"noTorrents": "[{siteName}] did not find the relevant torrent",
Expand Down Expand Up @@ -1106,4 +1107,4 @@
}
}
}
}
}
1 change: 1 addition & 0 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@
"exceedSizeCanceled": "容量超限,已取消",
"downloadURLsFinished": "{count}条链接已发送完成。",
"downloadURLsTip": "正在发送:{text}",
"resolveURLsTip": "正在解析种子 id:{id}, 进度:{current}/{total}, 大约还需 {min} 分钟",
"search": {
"needLogin": "[{siteName}]需要登录后再搜索",
"noTorrents": "[{siteName}]没有搜索到相关的种子",
Expand Down
147 changes: 84 additions & 63 deletions resource/sites/xp.m-team.io/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,20 @@
error(this.t("needPasskey"));
return;
}
let urls = this.getDownloadURLs();

if (!urls.length || typeof urls == "string") {
error(urls);
return;
}

PTService.call(PTService.action.copyTextToClipboard, urls.join("\n"))
this.getDownloadURLs().then(urls => {
if (!urls.length || typeof urls == 'string') {
error(urls);
throw new Error('ignore')
}
return PTService.call(PTService.action.copyTextToClipboard, urls.join('\n'))
})
.then(result => {
console.log("命令执行完成", result);
console.log('命令执行完成', result);
success();
})
.catch(() => {
error();
});
})
},
onDrop: (data, event, success, error) => {
if (checkPasskey && !PTService.site.passkey) {
Expand Down Expand Up @@ -214,26 +213,19 @@
error(this.t("needPasskey"));
return;
}
let urls = this.getDownloadURLs();

if (!urls.length || typeof urls == "string") {
error(urls);
return;
}

let downloads = [];
urls.forEach(url => {
downloads.push({
url,
method: PTService.site.downloadMethod
});
});

console.log(downloads);

PTService.call(PTService.action.addBrowserDownloads, downloads)
this.getDownloadURLs().then(urls => {
if (!urls.length || typeof urls == 'string') {
error(urls);
throw new Error('ignore')
}
return urls.map(url => ({url, method: PTService.site.downloadMethod}))
})
.then(downloads => {
console.log(downloads)
return PTService.call(PTService.action.addBrowserDownloads, downloads)
})
.then(result => {
console.log("命令执行完成", result);
console.log('命令执行完成', result);
success();
})
.catch(e => {
Expand Down Expand Up @@ -989,35 +981,27 @@
return;
}

let urls = this.getDownloadURLs();
if (!urls.length || typeof urls == "string") {
error(urls);
return;
}

// 是否启用后台下载任务
if (PTService.options.enableBackgroundDownload) {
this.downloadURLsInBackground(
urls,
msg => {
success({
msg
});
},
downloadOptions
);
} else {
this.downloadURLs(
urls,
urls.length,
msg => {
success({
msg
});
},
downloadOptions
);
}
this.getDownloadURLs().then(urls => {
if (!urls.length || typeof urls == 'string') {
error(urls);
throw new Error('ignore')
}
// 是否启用后台下载任务
if (PTService.options.enableBackgroundDownload) {
this.downloadURLsInBackground(
urls, msg => {
success({msg});
},
downloadOptions
);
} else {
this.downloadURLs(urls, urls.length,
msg => {
success({msg});
}, downloadOptions
);
}
}).catch(console.error)
}

downloadURLsInBackground(urls, callback, downloadOptions) {
Expand Down Expand Up @@ -1086,8 +1070,7 @@
"/" +
count +
")"
}),
0
})
);

if (!downloadOptions) {
Expand Down Expand Up @@ -1127,13 +1110,12 @@
}
}

showStatusMessage(msg) {
showStatusMessage(msg, width = 600) {
if (!this.statusBar) {
this.statusBar = PTService.showNotice({
text: msg,
type: "info",
width: 600,
progressBar: false
width, progressBar: false
});
} else {
this.statusBar.find(".noticejs-content").html(msg);
Expand Down Expand Up @@ -1274,6 +1256,45 @@
});
}
}

resolveDownloadURLById(id, showNotice = true) {
let res = $.ajax('/api/torrent/genDlToken', {
method: 'POST',
data: {id},
cache: true,
headers: {
"x-api-key": PTService.site.authToken
},
success: function (data) {
if (data.code === '0') {
console.log(`种子 ${id} 下载链接获取成功`, data)
// return data.data
} else {
let msg = `种子 ${id} 下载链接获取失败, code != 0`
console.log(msg, data)
if (showNotice) {
PTService.showNotice({msg})
}
// return null
}
},
error: function (data) {
let msg = `种子 ${id} 下载链接获取失败`
console.log(msg, data)
if (showNotice) {
PTService.showNotice({msg})
}
},
async: false
})
return res.responseJSON.data || ''
}

// @ts-ignore
// eslint-disable-next-line
async sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
}

window.NexusPHPCommon = Common;
Expand Down
5 changes: 0 additions & 5 deletions resource/sites/xp.m-team.io/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@
"name": "种子列表",
"pages": ["/browse"],
"scripts": ["common.js", "torrents.js"]
}, {
"name": "种子列表封面模式",
"pages": ["/torrents.php", "/movie.php", "/music.php", "/adult.php"],
"scripts": ["/libs/album/album.js", "torrents.js"],
"styles": ["/libs/album/style.css"]
}
],
"searchEntryConfig": {
Expand Down
28 changes: 2 additions & 26 deletions resource/sites/xp.m-team.io/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,7 @@

_getDownloadUrlByPossibleHrefs() {
let id = window.location.pathname.split('/').pop()
return $.ajax('/api/torrent/genDlToken', {
method: 'POST',
data: {id},
headers: {
"x-api-key": PTService.site.authToken
},
success: function (data) {
if (data.code === '0') {
console.log(`种子 ${id} 下载链接获取成功`, data)
// return data.data
} else {
console.log(`种子 ${id} 下载链接获取失败, code != 0`, data)
// return null
}
},
error: function (data) {
console.log(`种子 ${id} 下载链接获取失败`, data)
// return null
},
async: false
})
return this.resolveDownloadURLById(id)
}


Expand All @@ -51,11 +31,7 @@
getDownloadURL() {
let url = PTService.getFieldValue('downloadURL')
if (!url) {
let res = this._getDownloadUrlByPossibleHrefs()
if (res.status === 200 && res.responseJSON.code === '0') {
url = res.responseJSON.data
}
return url ? url : ''
return this._getDownloadUrlByPossibleHrefs()
}

return this.getFullURL(url);
Expand Down
Loading

0 comments on commit 8f0a60b

Please sign in to comment.