27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
|
|
|
|
// Start polling for Plex now-playing details
|
|
checkPlexNowPlaying();
|
|
setInterval(checkPlexNowPlaying, 3000);
|
|
|
|
function checkPlexNowPlaying() {
|
|
const plexToken = "kbGwoiA_QEGzw7MgSZrY"; // <-- replace with your Plex token
|
|
const plexHost = "spyro.corp.bbrunson.com"; // <-- adjust if needed
|
|
const url = `http://${plexHost}:32400/status/sessions?X-Plex-Token=${plexToken}`;
|
|
http.get(url, (res) => {
|
|
let data = "";
|
|
res.on('data', chunk => data += chunk);
|
|
res.on('end', () => {
|
|
// For simplicity we check for a known tag in the XML response.
|
|
let nowPlaying = "No media playing";
|
|
if(data.includes("MediaContainer") && data.includes("Video")) {
|
|
nowPlaying = "Plex is playing media";
|
|
}
|
|
if(win){
|
|
win.webContents.send('plex-update', { details: nowPlaying });
|
|
}
|
|
});
|
|
}).on('error', err => {
|
|
console.error("Error fetching Plex now playing:", err);
|
|
});
|
|
} |