59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
const request = require("sync-request");
|
|
|
|
const config = require("./config.json");
|
|
const channels = require("./channels.json");
|
|
|
|
const { XMLParser } = require("fast-xml-parser");
|
|
|
|
const parser = new XMLParser();
|
|
|
|
function checkChannel(id) {
|
|
const key = `last-vid-${id}`;
|
|
|
|
let data = request(
|
|
"GET",
|
|
`https://www.youtube.com/feeds/videos.xml?channel_id=${id}`
|
|
);
|
|
|
|
if (data.statusCode != 200) {
|
|
console.error(`${id} does not exist`);
|
|
return;
|
|
}
|
|
|
|
let jObj = parser.parse(data.body);
|
|
|
|
let lastEntry = jObj.feed.entry[0];
|
|
let lastVidId = request("GET", `http://localhost:7020/api/kv/${key}`);
|
|
|
|
if (lastVidId.statusCode == 200) {
|
|
if (lastVidId.body != lastEntry.id) {
|
|
let aaaa = request("POST", config.webhookurl, {
|
|
json: { content: `https://youtu.be/${lastEntry["yt:videoId"]}` },
|
|
});
|
|
|
|
console.log(`${id} has a new vid`);
|
|
console.log(aaaa.statusCode);
|
|
|
|
|
|
request("PUT", `http://localhost:7020/api/kv/${key}`, {
|
|
body: `${lastEntry.id}`,
|
|
});
|
|
} else {
|
|
console.log(`${id} is up to date`);
|
|
}
|
|
} else {
|
|
console.log(`${id} is a new channel`);
|
|
request("PUT", `http://localhost:7020/api/kv/${key}`, {
|
|
body: `${lastEntry.id}`,
|
|
});
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
channels.forEach((channel) => {
|
|
checkChannel(channel);
|
|
});
|
|
}
|
|
|
|
main();
|