From 302d3f693f60cfffc047b862206049540dd7e587 Mon Sep 17 00:00:00 2001 From: mesmerx Date: Wed, 8 Sep 2021 22:45:49 -0300 Subject: [PATCH] add tuna plugin for obs --- plugins/tuna-obs/back.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plugins/tuna-obs/back.js diff --git a/plugins/tuna-obs/back.js b/plugins/tuna-obs/back.js new file mode 100644 index 0000000000..7e7c1259a8 --- /dev/null +++ b/plugins/tuna-obs/back.js @@ -0,0 +1,40 @@ + +const { ipcRenderer } = require("electron"); +const registerCallback = require("../../providers/song-info"); + +const fetch = require('node-fetch'); + +const post = (data) => { + const port = 1608; + headers = {'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Access-Control-Allow-Headers': '*', + 'Access-Control-Allow-Origin': '*'} + const url = `http://localhost:${port}/`; + fetch(url, {method: 'POST', headers, body:JSON.stringify({data})}); +} + + + +module.exports = async (win) => { + + registerCallback((songInfo) => { + + // Register the calilback + if (songInfo.title.length === 0 && songInfo.artist.length === 0) { + return; + } + + const duration = Number(songInfo.songDuration)*1000 + const progress = Number(songInfo.elapsedSeconds)*1000 + const cover_url = songInfo.imageSrc + const album_url = songInfo.imageSrc + const title = songInfo.title + const artists = [songInfo.artist] + const status = !songInfo.isPaused ? 'Playing': 'Paused' + post({ cover_url, title, artists, status, progress, duration, album_url}); + + }) + +} +