mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 20:31:46 +00:00
fix tuna time update
This commit is contained in:
@ -1,33 +1,50 @@
|
|||||||
const { ipcRenderer } = require("electron");
|
const { ipcMain } = require("electron");
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
const registerCallback = require("../../providers/song-info");
|
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;
|
const port = 1608;
|
||||||
headers = {'Content-Type': 'application/json',
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Access-Control-Allow-Headers': '*',
|
'Access-Control-Allow-Headers': '*',
|
||||||
'Access-Control-Allow-Origin': '*'}
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
}
|
||||||
const url = `http://localhost:${port}/`;
|
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) => {
|
module.exports = async () => {
|
||||||
registerCallback((songInfo) => {
|
ipcMain.on('timeChanged', async (_, t) => {
|
||||||
|
if (!data.title) return;
|
||||||
|
data.progress = secToMilisec(t);
|
||||||
|
post(data);
|
||||||
|
});
|
||||||
|
|
||||||
// Register the callback
|
registerCallback((songInfo) => {
|
||||||
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
|
if (!songInfo.title && !songInfo.artist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const duration = Number(songInfo.songDuration)*1000
|
data.duration = secToMilisec(songInfo.songDuration)
|
||||||
const progress = Number(songInfo.elapsedSeconds)*1000
|
data.progress = secToMilisec(songInfo.elapsedSeconds)
|
||||||
const cover_url = songInfo.imageSrc
|
data.cover_url = songInfo.imageSrc;
|
||||||
const album_url = songInfo.imageSrc
|
data.album_url = songInfo.imageSrc;
|
||||||
const title = songInfo.title
|
data.title = songInfo.title;
|
||||||
const artists = [songInfo.artist]
|
data.artists = [songInfo.artist];
|
||||||
const status = !songInfo.isPaused ? 'Playing': 'Paused'
|
data.status = songInfo.isPaused ? 'Paused' : 'Playing';
|
||||||
post({ cover_url, title, artists, status, progress, duration, album_url});
|
post(data);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,6 @@ const songInfo = {
|
|||||||
songDuration: 0,
|
songDuration: 0,
|
||||||
elapsedSeconds: 0,
|
elapsedSeconds: 0,
|
||||||
url: "",
|
url: "",
|
||||||
videoId: "",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleData = async (responseText, win) => {
|
const handleData = async (responseText, win) => {
|
||||||
@ -58,7 +57,6 @@ const handleData = async (responseText, win) => {
|
|||||||
songInfo.image = await getImage(songInfo.imageSrc);
|
songInfo.image = await getImage(songInfo.imageSrc);
|
||||||
songInfo.uploadDate = data?.microformat?.microformatDataRenderer?.uploadDate;
|
songInfo.uploadDate = data?.microformat?.microformatDataRenderer?.uploadDate;
|
||||||
songInfo.url = data?.microformat?.microformatDataRenderer?.urlCanonical?.split("&")[0];
|
songInfo.url = data?.microformat?.microformatDataRenderer?.urlCanonical?.split("&")[0];
|
||||||
songInfo.videoId = data?.videoDetails?.videoId;
|
|
||||||
|
|
||||||
// used for options.resumeOnStart
|
// used for options.resumeOnStart
|
||||||
config.set("url", data?.microformat?.microformatDataRenderer?.urlCanonical);
|
config.set("url", data?.microformat?.microformatDataRenderer?.urlCanonical);
|
||||||
|
|||||||
Reference in New Issue
Block a user