Skip to content

Commit

Permalink
fix(deluge-labels): non-static label support during injection (cross-…
Browse files Browse the repository at this point in the history
…seed#540)

# Deluge Labels

## Purpose

this mirrors the qbittorrent behavior where a matched torrent's label
will now be used during injection (if a label is set)

- [x] duplicateCategories (true) will append ".cross-seed" to the same
label.
- [x] dataCategory will be used for data-based matches
- [x] if "No Label" is set, default will be "cross-seed"

Closes cross-seed#538
  • Loading branch information
zakkarry authored Nov 6, 2023
1 parent 577ef65 commit 62a714e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
26 changes: 22 additions & 4 deletions src/clients/Deluge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum DelugeErrorCode {
}
interface TorrentInfo {
complete: boolean;
save_path?: string;
save_path: string;
label?: string;
}

export default class Deluge implements TorrentClient {
Expand Down Expand Up @@ -156,6 +157,7 @@ export default class Deluge implements TorrentClient {
): Promise<InjectionResult> {
try {
let torrentInfo: TorrentInfo;
const { duplicateCategories } = getRuntimeConfig();
if (searchee.infoHash) {
torrentInfo = await this.getTorrentInfo(searchee);
if (!torrentInfo.complete) {
Expand All @@ -182,7 +184,13 @@ export default class Deluge implements TorrentClient {
const { dataCategory } = getRuntimeConfig();
await this.setLabel(
newTorrent.infoHash,
searchee.path ? dataCategory : this.delugeLabel
searchee.path
? dataCategory
: torrentInfo.label
? duplicateCategories
? `${torrentInfo.label}.cross-seed`
: torrentInfo.label
: this.delugeLabel
);
return InjectionResult.SUCCESS;
} else if (addResult?.error?.message?.includes("already")) {
Expand Down Expand Up @@ -229,17 +237,26 @@ export default class Deluge implements TorrentClient {
*/
private async getTorrentInfo(searchee: Searchee): Promise<TorrentInfo> {
try {
let torrentLabel: string = undefined;
const params = [
["state", "progress", "save_path"],
["state", "progress", "save_path", "label"],
{ hash: searchee.infoHash },
];

const response = await this.call("web.update_ui", params);
if (response?.result?.torrents?.[searchee.infoHash] === undefined) {
throw new Error(
`Torrent not found in client (${searchee.infoHash})`
);
}
if (
this.isLabelEnabled &&
response?.result?.torrents?.[searchee.infoHash]?.label
?.length != 0
) {
torrentLabel =
response?.result?.torrents?.[searchee.infoHash]?.label;
}

const completedTorrent =
response?.result?.torrents?.[searchee.infoHash]?.state ===
"Seeding" ||
Expand All @@ -249,6 +266,7 @@ export default class Deluge implements TorrentClient {
complete: completedTorrent,
save_path:
response?.result?.torrents?.[searchee.infoHash]?.save_path,
label: torrentLabel,
};
} catch (e) {
logger.error({
Expand Down
7 changes: 4 additions & 3 deletions src/config.template.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ module.exports = {
delugeRpcUrl: undefined,

/**
* qBittorrent-specific
* Whether to inject using categories with the same save paths as your normal categories.
* Example: if you have a category called "Movies",
* qBittorrent and Deluge specific
* Whether to inject using the same labels/categories as the original torrent.
* qBittorrent: This will apply the category's save path
* Example: if you have a label/category called "Movies",
* this will automatically inject cross-seeds to "Movies.cross-seed"
*/
duplicateCategories: false,
Expand Down
7 changes: 4 additions & 3 deletions src/config.template.docker.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ module.exports = {
delugeRpcUrl: undefined,

/**
* qBittorrent-specific
* Whether to inject using categories with the same save paths as your normal categories.
* Example: if you have a category called "Movies",
* qBittorrent and Deluge specific
* Whether to inject using the same labels/categories as the original torrent.
* qBittorrent: This will apply the category's save path
* Example: if you have a label/category called "Movies",
* this will automatically inject cross-seeds to "Movies.cross-seed"
*/
duplicateCategories: false,
Expand Down

0 comments on commit 62a714e

Please sign in to comment.