mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 13:12:07 +00:00
add songInfo.album
This commit is contained in:
@ -68,9 +68,8 @@ function registerShortcuts(win, options) {
|
|||||||
|
|
||||||
const player = setupMPRIS();
|
const player = setupMPRIS();
|
||||||
|
|
||||||
const mprisSeek = p => {
|
const mprisSeek = player.seeked;
|
||||||
player.seeked(p);
|
|
||||||
}
|
|
||||||
win.webContents.send("registerOnSeek");
|
win.webContents.send("registerOnSeek");
|
||||||
|
|
||||||
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
|
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
|
||||||
@ -107,13 +106,15 @@ function registerShortcuts(win, options) {
|
|||||||
|
|
||||||
registerCallback(songInfo => {
|
registerCallback(songInfo => {
|
||||||
if (player) {
|
if (player) {
|
||||||
player.metadata = {
|
const data = {
|
||||||
'mpris:length': secToMicro(songInfo.songDuration),
|
'mpris:length': secToMicro(songInfo.songDuration),
|
||||||
'mpris:artUrl': songInfo.imageSrc,
|
'mpris:artUrl': songInfo.imageSrc,
|
||||||
'xesam:title': songInfo.title,
|
'xesam:title': songInfo.title,
|
||||||
'xesam:artist': songInfo.artist,
|
'xesam:artist': songInfo.artist,
|
||||||
'mpris:trackid': '/'
|
'mpris:trackid': '/'
|
||||||
};;
|
};
|
||||||
|
if (songInfo.album) data['xesam:album'] = songInfo.album;
|
||||||
|
player.metadata = data;
|
||||||
mprisSeek(secToMicro(songInfo.elapsedSeconds))
|
mprisSeek(secToMicro(songInfo.elapsedSeconds))
|
||||||
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
|
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,8 @@ const data = {
|
|||||||
status: '',
|
status: '',
|
||||||
progress: 0,
|
progress: 0,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
album_url: ''
|
album_url: '',
|
||||||
|
album: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const post = async (data) => {
|
const post = async (data) => {
|
||||||
@ -44,7 +45,8 @@ module.exports = async () => {
|
|||||||
data.album_url = songInfo.imageSrc;
|
data.album_url = songInfo.imageSrc;
|
||||||
data.title = songInfo.title;
|
data.title = songInfo.title;
|
||||||
data.artists = [songInfo.artist];
|
data.artists = [songInfo.artist];
|
||||||
data.status = songInfo.isPaused ? 'Paused' : 'Playing';
|
data.status = songInfo.isPaused ? 'stopped' : 'playing';
|
||||||
|
data.album = songInfo.album;
|
||||||
post(data);
|
post(data);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ const { getImage } = require("./song-info");
|
|||||||
|
|
||||||
global.songInfo = {};
|
global.songInfo = {};
|
||||||
|
|
||||||
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
||||||
global.songInfo = JSON.parse(extractedSongInfo);
|
global.songInfo = JSON.parse(extractedSongInfo);
|
||||||
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
||||||
@ -13,8 +15,9 @@ module.exports = () => {
|
|||||||
document.addEventListener('apiLoaded', e => {
|
document.addEventListener('apiLoaded', e => {
|
||||||
setupTimeChangeListener();
|
setupTimeChangeListener();
|
||||||
|
|
||||||
document.querySelector('video').addEventListener('loadedmetadata', () => {
|
$('video').addEventListener('loadedmetadata', () => {
|
||||||
const data = e.detail.getPlayerResponse();
|
const data = e.detail.getPlayerResponse();
|
||||||
|
data.videoDetails.album = $('ytmusic-player-page')?.__data?.playerPageWatchMetadata?.albumName?.runs[0].text
|
||||||
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}, { once: true, passive: true })
|
}, { once: true, passive: true })
|
||||||
@ -25,5 +28,5 @@ function setupTimeChangeListener() {
|
|||||||
ipcRenderer.send('timeChanged', mutations[0].target.value);
|
ipcRenderer.send('timeChanged', mutations[0].target.value);
|
||||||
global.songInfo.elapsedSeconds = mutations[0].target.value;
|
global.songInfo.elapsedSeconds = mutations[0].target.value;
|
||||||
});
|
});
|
||||||
progressObserver.observe(document.querySelector('#progress-bar'), { attributeFilter: ["value"] })
|
progressObserver.observe($('#progress-bar'), { attributeFilter: ["value"] })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ const songInfo = {
|
|||||||
songDuration: 0,
|
songDuration: 0,
|
||||||
elapsedSeconds: 0,
|
elapsedSeconds: 0,
|
||||||
url: "",
|
url: "",
|
||||||
|
album: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleData = async (responseText, win) => {
|
const handleData = async (responseText, win) => {
|
||||||
@ -57,6 +58,7 @@ 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.album = data?.videoDetails?.album
|
||||||
|
|
||||||
// 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