Skip to content

Commit

Permalink
require cookie for youtube module
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexInABox committed Nov 24, 2024
1 parent 42d97ef commit 0199567
Show file tree
Hide file tree
Showing 5 changed files with 684 additions and 498 deletions.
1 change: 1 addition & 0 deletions custom-hds.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function initializeModules() {
youtube = new youtube(
cfg.youtube.music.active,
cfg.youtube.videos.active,
cfg.youtube.cookie,
cfg.youtube.updateInterval,
presence
);
Expand Down
3 changes: 2 additions & 1 deletion defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"active": false
},
"youtube": {
"cookie": "",
"music": {
"active": false
},
Expand All @@ -60,4 +61,4 @@
},
"updateInterval": 60
}
}
}
279 changes: 155 additions & 124 deletions modules/misc/config.js
Original file line number Diff line number Diff line change
@@ -1,168 +1,200 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");

var config_valid = {
"hds": false,
"location": false,
"netflix": false,
"plex": false,
"valorant": false,
"discord": false,
"duolingo": false,
"applePay": false,
"youtube": {
"videos": false,
"music": false,
},
"spotify": false,
}
hds: false,
location: false,
netflix: false,
plex: false,
valorant: false,
discord: false,
duolingo: false,
applePay: false,
youtube: {
videos: false,
music: false,
},
spotify: false,
};

var realConfig;

class config {
constructor() {
realConfig = require('./../../config.json');
}
constructor() {
realConfig = require("./../../config.json");
}

check() {
config_valid.hds = realConfig.hds.active;
check() {
config_valid.hds = realConfig.hds.active;

config_valid.location = realConfig.location.active;
config_valid.location = realConfig.location.active;

if (realConfig.location.active && realConfig.location.credentials.GEOAPIFY_API_KEY === "") {
config_valid.location = false;
}
if (
realConfig.location.active &&
realConfig.location.credentials.GEOAPIFY_API_KEY === ""
) {
config_valid.location = false;
}

config_valid.netflix = realConfig.netflix.active;
config_valid.netflix = realConfig.netflix.active;

if (realConfig.netflix.active && (realConfig.netflix.cookie === "")) {
config_valid.netflix = false;
}
/*if (realConfig.netflix.apilayer_apikey === "") { //no use in totally disabling the module if the apikey is missing
if (realConfig.netflix.active && realConfig.netflix.cookie === "") {
config_valid.netflix = false;
}
/*if (realConfig.netflix.apilayer_apikey === "") { //no use in totally disabling the module if the apikey is missing
config_valid.netflix = false;
}*/
if (realConfig.netflix.updateInterval === "") {
realConfig.netflix.updateInterval = 900;
}

config_valid.plex = realConfig.plex.active;
if (realConfig.netflix.updateInterval === "") {
realConfig.netflix.updateInterval = 900;
}

if (realConfig.plex.active && (realConfig.plex.serverURL === "" || realConfig.plex.token === "" || realConfig.plex.username === "")) {
config_valid.plex = false;
}
if (realConfig.plex.updateInterval === "") {
realConfig.plex.updateInterval = 60;
}
config_valid.plex = realConfig.plex.active;

config_valid.valorant = realConfig.valorant.active;
if (
realConfig.plex.active &&
(realConfig.plex.serverURL === "" ||
realConfig.plex.token === "" ||
realConfig.plex.username === "")
) {
config_valid.plex = false;
}
if (realConfig.plex.updateInterval === "") {
realConfig.plex.updateInterval = 60;
}

if (realConfig.valorant.active && ((realConfig.valorant.riotID === "" || realConfig.valorant.riotTag === "") && realConfig.valorant.riotPUUID === "")) {
config_valid.valorant = false;
}
if (realConfig.valorant.henrikDevAPIKey === "") {
config_valid.valorant = false;
}
if (realConfig.valorant.updateInterval === "") {
realConfig.valorant.updateInterval = 60;
}
config_valid.valorant = realConfig.valorant.active;

config_valid.discord = realConfig.discord.active;
if (
realConfig.valorant.active &&
(realConfig.valorant.riotID === "" ||
realConfig.valorant.riotTag === "") &&
realConfig.valorant.riotPUUID === ""
) {
config_valid.valorant = false;
}
if (realConfig.valorant.henrikDevAPIKey === "") {
config_valid.valorant = false;
}
if (realConfig.valorant.updateInterval === "") {
realConfig.valorant.updateInterval = 60;
}

if (realConfig.discord.active && (realConfig.discord.userID === "")) {
config_valid.discord = false;
}
if (realConfig.discord.updateInterval === "") {
realConfig.discord.updateInterval = 30;
}
config_valid.discord = realConfig.discord.active;

config_valid.duolingo = realConfig.duolingo.active;
if (realConfig.discord.active && realConfig.discord.userID === "") {
config_valid.discord = false;
}
if (realConfig.discord.updateInterval === "") {
realConfig.discord.updateInterval = 30;
}

if (realConfig.duolingo.active && (realConfig.duolingo.username === "" || realConfig.duolingo.cookie === "")) {
config_valid.duolingo = false;
}
if (realConfig.duolingo.updateInterval === "") {
realConfig.duolingo.updateInterval = 120;
}
config_valid.duolingo = realConfig.duolingo.active;

config_valid.applePay = realConfig.applePay.active;
if (
realConfig.duolingo.active &&
(realConfig.duolingo.username === "" || realConfig.duolingo.cookie === "")
) {
config_valid.duolingo = false;
}
if (realConfig.duolingo.updateInterval === "") {
realConfig.duolingo.updateInterval = 120;
}

config_valid.youtube.videos = realConfig.youtube.videos.active;
config_valid.youtube.music = realConfig.youtube.music.active;
config_valid.applePay = realConfig.applePay.active;

if (realConfig.youtube.updateInterval === "") {
realConfig.youtube.updateInterval = 60;
}
config_valid.youtube.videos = realConfig.youtube.videos.active;
config_valid.youtube.music = realConfig.youtube.music.active;

config_valid.spotify = realConfig.spotify.active;
if (realConfig.youtube.updateInterval === "") {
realConfig.youtube.updateInterval = 60;
}
if (realConfig.youtube.cookie === "") {
config_valid.youtube.videos = false;
config_valid.youtube.music = false;
}

if (realConfig.spotify.active && (realConfig.spotify.api.clientID === "" || realConfig.spotify.api.clientSecret === "")) {
config_valid.spotify = false;
}
if (realConfig.spotify.updateInterval === "") {
realConfig.spotify.updateInterval = 60;
}
config_valid.spotify = realConfig.spotify.active;

patchConfig(realConfig);
console.log("\x1b[33m", "[CONFIG] Config check complete" + "\x1b[0m");
if (
realConfig.spotify.active &&
(realConfig.spotify.api.clientID === "" ||
realConfig.spotify.api.clientSecret === "")
) {
config_valid.spotify = false;
}

getValid() {
return config_valid;
if (realConfig.spotify.updateInterval === "") {
realConfig.spotify.updateInterval = 60;
}

get() {
return realConfig;
}
patchConfig(realConfig);
console.log("\x1b[33m", "[CONFIG] Config check complete" + "\x1b[0m");
}

setValorantPUUID(puuid) {
realConfig.valorant.riotPUUID = puuid;
console.log("\x1b[33m", "[CONFIG] [VALORANT] Valorant PUUID set to " + puuid + "\x1b[0m");
getValid() {
return config_valid;
}

patchConfig(realConfig);
}
get() {
return realConfig;
}

setValorantRiotID(riotID) {
realConfig.valorant.riotID = riotID;
console.log("\x1b[33m", "[CONFIG] [VALORANT] Valorant RiotID set to " + riotID + "\x1b[0m");
setValorantPUUID(puuid) {
realConfig.valorant.riotPUUID = puuid;
console.log(
"\x1b[33m",
"[CONFIG] [VALORANT] Valorant PUUID set to " + puuid + "\x1b[0m"
);

patchConfig(realConfig);
}
patchConfig(realConfig);
}

setValorantRiotTag(riotTag) {
realConfig.valorant.riotTag = riotTag;
console.log("\x1b[33m", "[CONFIG] [VALORANT] Valorant RiotTag set to " + riotTag + "\x1b[0m");
setValorantRiotID(riotID) {
realConfig.valorant.riotID = riotID;
console.log(
"\x1b[33m",
"[CONFIG] [VALORANT] Valorant RiotID set to " + riotID + "\x1b[0m"
);

patchConfig(realConfig);
}
patchConfig(realConfig);
}

getValorantPUUID() {
return realConfig.valorant.riotPUUID;
}
setValorantRiotTag(riotTag) {
realConfig.valorant.riotTag = riotTag;
console.log(
"\x1b[33m",
"[CONFIG] [VALORANT] Valorant RiotTag set to " + riotTag + "\x1b[0m"
);

getValorantRiotID() {
return realConfig.valorant.riotID;
}
patchConfig(realConfig);
}

getValorantRiotTag() {
return realConfig.valorant.riotTag;
}
getValorantPUUID() {
return realConfig.valorant.riotPUUID;
}

getValorantRiotID() {
return realConfig.valorant.riotID;
}

getValorantRiotTag() {
return realConfig.valorant.riotTag;
}
}

module.exports = config;


async function patchConfig(config) {
console.log("\x1b[33m", "[CONFIG] Patching config.json...", "\x1b[0m");
fs.writeFileSync(
path.resolve(__dirname, "./../../config.json"),
JSON.stringify(config, null, 2),
(err) => {
if (err) {
console.error("[CONFIG] " + err);
}
// file written successfully
}
);
console.log("\x1b[33m", "[CONFIG] Patching config.json...", "\x1b[0m");
fs.writeFileSync(
path.resolve(__dirname, "./../../config.json"),
JSON.stringify(config, null, 2),
(err) => {
if (err) {
console.error("[CONFIG] " + err);
}
// file written successfully
}
);
}

//PSEUDO:
Expand All @@ -171,7 +203,6 @@ async function patchConfig(config) {
// if correct, set the private variable in this file to true
// if not, set the private variable in this file to false


// PSEUDO:
// function configCheck() {
// if (config has !same structure as the default config) {
Expand All @@ -186,4 +217,4 @@ async function patchConfig(config) {
// ...
// return true;
// }
//
//
Loading

0 comments on commit 0199567

Please sign in to comment.