fix tuna time update

This commit is contained in:
Araxeus
2021-11-10 18:37:16 +02:00
parent ccfe7434bf
commit 9a7baeac23
2 changed files with 34 additions and 19 deletions

View File

@ -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);
})
}

View File

@ -45,7 +45,6 @@ const songInfo = {
songDuration: 0,
elapsedSeconds: 0,
url: "",
videoId: "",
};
const handleData = async (responseText, win) => {
@ -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);