-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.js
executable file
·76 lines (71 loc) · 2.48 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const PlexAPI = require("plex-api");
const fs = require("fs");
const rl = require("readline-sync");
const configExists = fs.existsSync("config.json");
if (!configExists) {
fs.copyFileSync("config.tmp.json", "config.json");
}
const config = require("./config.json");
if (!config.token.length) config.token = rl.question("Bot Token> ");
if (!config.outputFolder.length || config.outputFolder == "/path/to/output")
config.outputFolder = rl.questionPath("Output> ", {
isDirectory: true,
exists: true,
});
if (config.owners[0] == "DISCORD_ID")
config.owners[0] = rl.question("Discord ID> ");
if (!config.login.username.length)
config.login.username = rl.question("Crunchyroll Username> ");
if (!config.login.password.length)
config.login.password = rl.question("Crunchyroll Password> ", {
hideEchoBack: true,
});
async function selectPlexLibrary(plex) {
const libraries = (
await plex.query("/library/sections")
).MediaContainer.Directory.filter((l) => l.type == "show");
const libraryKey =
libraries[
rl.keyInSelect(
libraries.map((l) => l.title),
"Choose a library",
{ cancel: false }
)
].key;
config.plex.libraryIndex = libraryKey;
fs.writeFileSync("config.json", JSON.stringify(config, null, "\t"));
console.log("Setup Complete.");
}
if (rl.keyInYN("Plex Setup?")) {
if (!config.plex.hostname.length)
config.plex.hostname = rl.question("Hostname> ");
if (!config.plex.token.length) {
config.plex.port = rl.questionInt("Port> ", { defaultInput: 32400 });
let plexUsername = rl.question("Username> ");
let plexPassword = rl.question("Password> ", { hideEchoBack: true });
let plex = new PlexAPI({
hostname: config.plex.hostname,
port: config.plex.port,
username: plexUsername,
password: plexPassword,
});
plex.authenticator.on("token", async (token) => {
config.plex.token = token;
config.plex.enabled = true;
fs.writeFileSync("config.json", JSON.stringify(config, null, "\t"));
await selectPlexLibrary(new PlexAPI(config.plex));
});
plex.query("/").catch((e) => {
console.error(e.message);
console.log("Please try again.");
process.exit();
});
} else {
selectPlexLibrary(new PlexAPI(config.plex));
// fs.writeFileSync("config.json", JSON.stringify(config, null, "\t"));
// console.log("Setup Complete.");
}
} else {
fs.writeFileSync("config.json", JSON.stringify(config, null, "\t"));
console.log("Setup Complete.");
}