Skip to content

Commit

Permalink
Add command line parsing for DCI
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Jan 19, 2021
1 parent 7c39e47 commit 52632a8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/mmgoodnow.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions src/clients/rtorrent.js
Expand Up @@ -46,22 +46,20 @@ async function saveWithLibtorrentResume(meta, savePath, dataDir) {
}

function getClient() {
const {
rtorrentRpcUrl,
rtorrentRpcUsername,
rtorrentRpcPassword,
} = getRuntimeConfig();
const { rtorrentRpcUrl } = getRuntimeConfig();

const { origin, username, password } = new URL(rtorrentRpcUrl);

const clientCreator = rtorrentRpcUrl.startsWith("https")
? xmlrpc.createSecureClient
: xmlrpc.createClient;

const shouldUseAuth = Boolean(rtorrentRpcPassword && rtorrentRpcUsername);
const shouldUseAuth = Boolean(username && password);

const client = clientCreator({
url: rtorrentRpcUrl,
url: origin,
basic_auth: shouldUseAuth
? { user: rtorrentRpcUsername, pass: rtorrentRpcPassword }
? { user: username, pass: password }
: undefined,
});

Expand Down
28 changes: 20 additions & 8 deletions src/cmd.js
Expand Up @@ -10,17 +10,18 @@ const { clear: clearCache } = require("./cache");
const { serve } = require("./server");
const logger = require("./logger");
require("./signalHandlers");
const { ACTIONS } = require("./constants");

function fallback(...args) {
for (const arg of args) {
if (arg !== undefined) return arg;
}
return undefined;
}

async function run() {
const fileConfig = getFileConfig();

function fallback(...args) {
for (const arg of args) {
if (arg !== undefined) return arg;
}
return undefined;
}

function addSharedOptions() {
return this.requiredOption(
"-u, --jackett-server-url <url>",
Expand Down Expand Up @@ -55,7 +56,18 @@ async function run() {
"Search for all torrents regardless of their contents",
fallback(fileConfig.searchAll, false)
)
.requiredOption("-v, --verbose", "Log verbose output", false);

.requiredOption("-v, --verbose", "Log verbose output", false)
.requiredOption(
"-A, --action <action>",
"If set to 'inject', cross-seed will attempt to add the found torrents to your torrent client.",
fallback(fileConfig.action, ACTIONS.SAVE)
)
.option(
"--rtorrent-rpc-url <url>",
"The url of your rtorrent XMLRPC interface. Requires '-A inject'. See the docs for more information.",
fileConfig.rtorrentRpcUrl
);
}

// monkey patch Command with this addSharedOptions function
Expand Down
11 changes: 10 additions & 1 deletion src/config.template.docker.js
Expand Up @@ -27,12 +27,21 @@ module.exports = {
// where to put the torrent files that cross-seed finds for you.
// Don't change this for Docker.
// Instead set the volume mapping on your docker container.
outputDir: "/output",
outputDir: "/cross-seeds",

// Whether to search for single episode torrents
includeEpisodes: false,

// search for all torrents, regardless of their contents
// this option overrides includeEpisodes.
searchAll: false,

// can be either "save" or "inject".
// With "inject" you need to specify the rtorrent rpc url.
action: "save",

// The url of your rtorrent XMLRPC interface.
// Only relevant with action: "inject".
// Could be something like "http://username:password@localhost:1234/RPC2
rtorrentRpcUrl: undefined,
};
9 changes: 9 additions & 0 deletions src/config.template.js
Expand Up @@ -33,4 +33,13 @@ module.exports = {
// search for all torrents, regardless of their contents
// this option overrides includeEpisodes.
searchAll: false,

// can be either "save" or "inject".
// With "inject" you need to specify the rtorrent rpc url.
action: "save",

// The url of your rtorrent XMLRPC interface.
// Only relevant with action: "inject".
// Could be something like "http://username:password@localhost:1234/RPC2
rtorrentRpcUrl: undefined,
};
2 changes: 2 additions & 0 deletions src/runtimeConfig.js
Expand Up @@ -10,6 +10,8 @@ let runtimeConfig = {
searchAll: undefined,
excludeOlder: undefined,
excludeRecentSearch: undefined,
action: undefined,
rtorrentRpcUrl: undefined,
};

function setRuntimeConfig(configObj) {
Expand Down

0 comments on commit 52632a8

Please sign in to comment.