-
Notifications
You must be signed in to change notification settings - Fork 9
/
settings.js
85 lines (73 loc) · 2.22 KB
/
settings.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
77
78
79
80
81
82
83
84
85
const { networkInterfaces } = require("os");
const { readFileSync, existsSync } = require("fs");
const { getMPVHome } = require("./crud");
const path = require("path");
const IP_ADDR = Object.values(networkInterfaces())
.flat()
.find((i) => (i.family == "IPv4" || i.family == 4) && !i.internal);
const CORSOPTIONS = {
origin: "*",
methods: ["GET", "POST", "DELETE", "UPDATE", "PUT", "PATCH"],
};
let settings = {
serverIP: IP_ADDR ? IP_ADDR.address : "127.0.0.1", // Used for displaying the remote access URL
realServerIP: undefined, // Used for app.listen(). Default is all interfaces
serverPort: null,
serverPortRangeEnd: null,
filebrowserPaths: [],
socketName: null,
uselocaldb: false,
unsafefilebrowsing: false,
verbose: false,
};
/*
Loads settings
*/
function loadSettings(argv) {
settings.socketName = argv._[0];
settings.realServerIP = argv.address;
// If we have an explicit address, display that instead
if (argv.address) settings.serverIP = argv.address;
settings.serverPort = argv.webport;
settings.serverPortRangeEnd = argv.webportrangeend;
settings.uselocaldb = argv.uselocaldb;
settings.unsafefilebrowsing = argv.unsafefilebrowsing;
settings.verbose = argv.verbose;
settings.osdMessages = argv["osd-messages"];
if (argv.filebrowserpaths) {
settings.filebrowserPaths = argv.filebrowserpaths.map((el, index) => {
return {
index,
path: el.replace(/^"|'+|"|'+$/g, ""),
};
});
}
}
/*
Load default ytdl format,
if it don't exist return empty string
*/
function readDefaultYtdlFormat() {
const mpvConfigPath = path.join(getMPVHome(), "mpv.conf");
if (!existsSync(mpvConfigPath)) {
console.log("No mpv.conf file found");
return ""
}
const ytdlFormatLine =
readFileSync(mpvConfigPath, "utf8")
.split("\n")
.find((line) => line.includes("ytdl-format"))
if (!ytdlFormatLine) {
console.log("No ytdl-format line found in mpv.conf")
return "";
}
const regex = /ytdl-format="(.+?)"/;
const match = ytdlFormatLine.match(regex);
if (match)
return match[1];
return "";
}
exports.loadSettings = loadSettings;
exports.settings = settings;
exports.CORSOPTIONS = CORSOPTIONS;
exports.YTDL_DEFAULT_FORMAT = readDefaultYtdlFormat();