-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
73 lines (63 loc) · 1.99 KB
/
main.js
File metadata and controls
73 lines (63 loc) · 1.99 KB
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
import * as tmdb from "./tmdb.js";
import * as server from "./server.js";
import * as parse from "./parse.js";
import { fileURLToPath } from 'node:url';
import { readFileSync, writeFileSync } from "fs";
import { spawnSync } from "node:child_process";
import path from "path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
let last = JSON.parse(readFileSync(path.join(__dirname, "./last.json"), "utf-8"));
function updateLast(){
writeFileSync(path.join(__dirname, "last.json"), JSON.stringify(last));
}
function updateRepo() {
const response = spawnSync(path.join(__dirname, "./update.sh"));
if(response.error){
throw response.error;
}
console.log(response.stdout?.toString());
}
async function updateTMDB() {
try {
const currentTime = Date.now();
console.log(last);
// A week
if ((currentTime - last.time) > (60 * 60 * 24 * 7 * 1000)) {
switch(last.stage){
case 0:
console.log("Starting stage 0");
await tmdb.ini();
last.stage = 1;
updateLast();
console.log("Done with stage 0");
case 1:
console.log("Starting stage 1");
parse.ini();
last.stage = 2;
updateLast();
console.log("Done with stage 1");
case 2:
console.log("Starting stage 2");
updateRepo();
last.stage = 0;
last.time = currentTime;
updateLast();
console.log("Done with stage 2");
}
}
} catch (err) {
console.error(err);
}
}
setInterval(() => {
server.ini("fmovies");
server.ini("flixhq");
}, 60 * 60 * 1000);
// 1 hour
setInterval(async () => {
updateTMDB();
}, 60 * 60 * 1 * 1000);
// 1 hour
updateTMDB();
server.ini("fmovies");
server.ini("flixhq");