This commit is contained in:
Henry Jameson 2026-01-14 15:54:22 +02:00
commit 604b617c52

View file

@ -1,10 +1,14 @@
import fs from 'node:fs';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
const botBearer = process.env.BOT_BEARER; const botBearerFile = process.env.BOT_BEARER_FILE;
const userBearer = process.env.USER_BEARER; const userBearerFile = process.env.USER_BEARER_FILE;
const instance = process.env.INSTANCE; const instance = process.env.INSTANCE;
const videoId = process.env.VIDEO_ID; const videoId = process.env.VIDEO_ID;
const botBearer = fs.readFileSync(botBearerFile, 'utf-8');
const userBearer = fs.readFileSync(userBearerFile, 'utf-8');
const globalState = { const globalState = {
exit: false, exit: false,
currentlyLive: false, currentlyLive: false,
@ -68,16 +72,16 @@ const loop = async () => {
); );
const { state } = await response.json(); const { state } = await response.json();
const isLive = state.id === 1; // published const isLive = state.id === 1; // published
console.info('Live: ', isLive, globalState.currentlyLive) console.info('Live: ', isLive, globalState.currentlyLive);
const stateChange = isLive !== globalState.currentlyLive; const stateChange = isLive !== globalState.currentlyLive;
console.info('State change', stateChange) console.info('State change', stateChange);
globalState.currentlyLive = isLive; globalState.currentlyLive = isLive;
console.info('State: ', state) console.info('State: ', state);
if (stateChange) { if (stateChange) {
if (isLive) { if (isLive) {
console.info('Went live!') console.info('Went live!');
console.info(process.env) console.info(process.env);
const postResult = await post({ const postResult = await post({
spoiler_text: 'Stream announcment', spoiler_text: 'Stream announcment',
status: [ status: [
@ -87,15 +91,15 @@ const loop = async () => {
].join('\n'), ].join('\n'),
visibility: 'public', visibility: 'public',
}); });
console.info(postResult) console.info(postResult);
const scrobbleResult = await scrobble({ const scrobbleResult = await scrobble({
title: 'Streaming on PeerTube', title: 'Streaming on PeerTube',
external_link: `https://tube.ebin.club/w/${videoId}`, external_link: `https://tube.ebin.club/w/${videoId}`,
}); });
console.info(scrobbleResult) console.info(scrobbleResult);
} else { } else {
console.info('Went offline...') console.info('Went offline...');
await scrobble({ await scrobble({
title: 'Stream over', title: 'Stream over',
}); });