Skip to content

Commit

Permalink
fix tuna time update
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Nov 10, 2021
1 parent ccfe743 commit 9a7baea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
51 changes: 34 additions & 17 deletions plugins/tuna-obs/back.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
const { ipcRenderer } = require("electron");
const { ipcMain } = require("electron");
const fetch = require('node-fetch');

const registerCallback = require("../../providers/song-info");

const post = (data) => {
const secToMilisec = t => Math.round(Number(t) * 1000);
const data = {
cover_url: '',
title: '',
artists: [],
status: '',
progress: 0,
duration: 0,
album_url: ''
};

const post = async (data) => {
const port = 1608;
headers = {'Content-Type': 'application/json',
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*'}
'Access-Control-Allow-Origin': '*'
}
const url = `http://localhost:${port}/`;
fetch(url, {method: 'POST', headers, body:JSON.stringify({data})});
fetch(url, { method: 'POST', headers, body: JSON.stringify({ data }) });
}

module.exports = async (win) => {
registerCallback((songInfo) => {
module.exports = async () => {
ipcMain.on('timeChanged', async (_, t) => {
if (!data.title) return;
data.progress = secToMilisec(t);
post(data);
});

// Register the callback
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
registerCallback((songInfo) => {
if (!songInfo.title && !songInfo.artist) {
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});
data.duration = secToMilisec(songInfo.songDuration)
data.progress = secToMilisec(songInfo.elapsedSeconds)
data.cover_url = songInfo.imageSrc;
data.album_url = songInfo.imageSrc;
data.title = songInfo.title;
data.artists = [songInfo.artist];
data.status = songInfo.isPaused ? 'Paused' : 'Playing';
post(data);
})
}
2 changes: 0 additions & 2 deletions providers/song-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const songInfo = {
songDuration: 0,
elapsedSeconds: 0,
url: "",
videoId: "",
};

const handleData = async (responseText, win) => {
Expand All @@ -58,7 +57,6 @@ const handleData = async (responseText, win) => {
songInfo.image = await getImage(songInfo.imageSrc);
songInfo.uploadDate = data?.microformat?.microformatDataRenderer?.uploadDate;
songInfo.url = data?.microformat?.microformatDataRenderer?.urlCanonical?.split("&")[0];
songInfo.videoId = data?.videoDetails?.videoId;

// used for options.resumeOnStart
config.set("url", data?.microformat?.microformatDataRenderer?.urlCanonical);
Expand Down

0 comments on commit 9a7baea

Please sign in to comment.