Skip to content

Commit

Permalink
feat: qb 支持自动添加分类
Browse files Browse the repository at this point in the history
  • Loading branch information
IITII committed Sep 17, 2023
1 parent a010629 commit f2eaa32
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
35 changes: 27 additions & 8 deletions resource/clients/qbittorrent/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,34 @@
*/
addTorrentFromUrl(data, callback) {
let formData = new FormData();
let {savePath, category, clientOptions} = data, autoTMM = true, qbCategories

if (data.savePath) {
formData.append("savepath", data.savePath);
// 禁用自动管理种子
formData.append("autoTMM", false);
if (clientOptions && clientOptions.enableCategory) {
qbCategories = clientOptions.qbCategories
if (qbCategories && qbCategories.length > 0) {
let qbCategory = qbCategories.find(c => c.path === savePath)
// qb 4.5.2 实测 autoTMM 为 true 的情况下, 如果指定分类, 存储路径以分类为准.
// 分类不存在时, 会自动创建分类, 路径为 `默认下载路径/分类名称`.
// nastool 会自动维护分类, 这里不做那么细致的处理.
// 所以路径不匹配的情况下, 需要禁用 autoTMM
if (qbCategory) {
// 以用户手动设置为准
category = qbCategory.name
autoTMM = true
} else {
autoTMM = false
}
}
}

formData.append("autoTMM", autoTMM);

if (savePath) {
formData.append("savepath", savePath);
}

if (category != undefined) {
formData.append("category", category);
}

if (data.autoStart != undefined) {
Expand All @@ -184,10 +207,6 @@
formData.append("tags", data.imdbId);
}

if (data.category != undefined) {
formData.append("category", data.category);
}

if (data.upLoadLimit && data.upLoadLimit > 0) {
formData.append("upLimit", data.upLoadLimit * 1024);
}
Expand Down
3 changes: 3 additions & 0 deletions resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@
"id": "ID",
"autoStart": "Automatically start downloading when sending a torrent",
"tagIMDb": "Add IMDb tag when sending a torrent(Beta)",
"enableCategory": "Automatically add QB categories when sending torrents (Beta)",
"enableCategoryText": "QB category list",
"enableCategoryTextTip": "Fill in one address per line, with commas separating the category name and path. Path keywords are not supported. For example: 'movie,/tmp/movie'. You also need to fill in the same download path in the download directory settings. When the download path is specified and the download path hits a certain category, the category will be added and automatic seed management will be enabled.",
"autoCreate": "<Automatically generated after saving>",
"test": "Test if the server can connect",
"testSuccess": "Server can be connected",
Expand Down
3 changes: 3 additions & 0 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@
"autoStart": "发送种子时自动开始下载",
"enabled": "是否启用",
"tagIMDb": "发送种子时自动添加IMDb标签(Beta)",
"enableCategory": "发送种子时自动添加 QB 分类 (Beta)",
"enableCategoryText": "QB 分类列表",
"enableCategoryTextTip": "每行填写一个地址,逗号分隔分类名称和路径, 不支持路径关键字。如:'movie,/tmp/movie'. 还需在下载目录设置里面填写一样的下载路径. 当指定了下载路径且下载路径命中了某一个分类, 才会添加分类并启用自动种子管理.",
"autoCreate": "<保存后自动生成>",
"test": "测试服务器是否可连接",
"testSuccess": "服务器可连接",
Expand Down
2 changes: 2 additions & 0 deletions src/background/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export default class Controller {
let URL = Filters.parseURL(downloadOptions.url);
let downloadHost = URL.host;
let siteConfig = this.getSiteFromHost(downloadHost);
console.log("doDownload", clientConfig, downloadOptions, host, siteConfig)
return new Promise((resolve?: any, reject?: any) => {
clientConfig.client
.call(EAction.addTorrentFromURL, {
Expand All @@ -271,6 +272,7 @@ export default class Controller {
category: downloadOptions.savePath !== undefined && downloadOptions.savePath.includes(',') ? downloadOptions.savePath.split(',')[1] : null,
imdbId: downloadOptions.tagIMDb ? downloadOptions.imdbId : null,
upLoadLimit: siteConfig !== undefined ? siteConfig.upLoadLimit : null,
clientOptions: clientConfig.options,
})
.then((result: any) => {
this.service.logger.add({
Expand Down
12 changes: 12 additions & 0 deletions src/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export interface DownloadClient {
autoStart?: boolean;
tagIMDb?: boolean;
type?: string;
// 发送种子的时候发送分类
enableCategory?: boolean;
qbCategories?: QbCategory[];
}

/**
* qb 分类
*/
export interface QbCategory {
name: string;
// 不支持关键字
path: string;
}

/**
Expand Down
24 changes: 23 additions & 1 deletion src/options/views/settings/DownloadClients/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
v-if="['qbittorrent'].includes(option.type)"
></v-switch>

<!--启用 qb 分类-->
<v-switch
:label="$t('settings.downloadClients.editor.enableCategory')"
v-model="option.enableCategory"
></v-switch>
<!--自定义分类列表-->
<v-textarea v-if="option.enableCategory" v-model="categoryText"
:label="$t('settings.downloadClients.editor.enableCategoryText')"
:hint="$t('settings.downloadClients.editor.enableCategoryTextTip')"
></v-textarea>

<v-text-field
:value="option.type"
:label="$t('settings.downloadClients.editor.type')"
Expand Down Expand Up @@ -94,12 +105,13 @@
import md5 from "blueimp-md5";
import Vue from "vue";
import Extension from "@/service/extension";
import { EAction, DataResult, Dictionary } from "@/interface/common";
import {EAction, DataResult, Dictionary, QbCategory} from "@/interface/common";
const extension = new Extension();
export default Vue.extend({
data() {
return {
showPassword: false,
categoryText: '',
rules: {
require: [(v: any) => !!v || "!"],
url: (v: any) => {
Expand Down Expand Up @@ -137,6 +149,16 @@ export default Vue.extend({
option: Object
},
watch: {
option() {
console.log(`watch option`, this.option)
let qbCategories: QbCategory[] = this.option.qbCategories || [];
this.categoryText = qbCategories.map(c => `${c.name},${c.path}`).join('\n')
},
categoryText() {
this.option.qbCategories = this.categoryText.split(/\n/).filter(_ => !!_)
.map(_ => _.split(/\s*[,,]\s*/)).filter(([name, path]) => !!name && !!path)
.map(([name, path]) => ({name, path}))
},
successMsg() {
this.haveSuccess = this.successMsg != "";
},
Expand Down
1 change: 1 addition & 0 deletions src/options/views/settings/DownloadClients/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export default Vue.extend({
}
},
updateItem(item: any) {
console.debug('updateClient', item)
this.$store.commit("updateClient", item);
},
Expand Down

0 comments on commit f2eaa32

Please sign in to comment.