Skip to content

Commit 02d5b78

Browse files
committed
add songInfo.album
1 parent 5492afe commit 02d5b78

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

plugins/shortcuts/back.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ function registerShortcuts(win, options) {
6868

6969
const player = setupMPRIS();
7070

71-
const mprisSeek = p => {
72-
player.seeked(p);
73-
}
71+
const mprisSeek = player.seeked;
72+
7473
win.webContents.send("registerOnSeek");
7574

7675
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
@@ -107,13 +106,15 @@ function registerShortcuts(win, options) {
107106

108107
registerCallback(songInfo => {
109108
if (player) {
110-
player.metadata = {
109+
const data = {
111110
'mpris:length': secToMicro(songInfo.songDuration),
112111
'mpris:artUrl': songInfo.imageSrc,
113112
'xesam:title': songInfo.title,
114113
'xesam:artist': songInfo.artist,
115114
'mpris:trackid': '/'
116-
};;
115+
};
116+
if (songInfo.album) data['xesam:album'] = songInfo.album;
117+
player.metadata = data;
117118
mprisSeek(secToMicro(songInfo.elapsedSeconds))
118119
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
119120
}

plugins/tuna-obs/back.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const data = {
1111
status: '',
1212
progress: 0,
1313
duration: 0,
14-
album_url: ''
14+
album_url: '',
15+
album: undefined
1516
};
1617

1718
const post = async (data) => {
@@ -44,7 +45,8 @@ module.exports = async () => {
4445
data.album_url = songInfo.imageSrc;
4546
data.title = songInfo.title;
4647
data.artists = [songInfo.artist];
47-
data.status = songInfo.isPaused ? 'Paused' : 'Playing';
48+
data.status = songInfo.isPaused ? 'stopped' : 'playing';
49+
data.album = songInfo.album;
4850
post(data);
4951
})
5052
}

providers/song-info-front.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { getImage } = require("./song-info");
44

55
global.songInfo = {};
66

7+
function $(selector) { return document.querySelector(selector); }
8+
79
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
810
global.songInfo = JSON.parse(extractedSongInfo);
911
global.songInfo.image = await getImage(global.songInfo.imageSrc);
@@ -13,8 +15,9 @@ module.exports = () => {
1315
document.addEventListener('apiLoaded', e => {
1416
setupTimeChangeListener();
1517

16-
document.querySelector('video').addEventListener('loadedmetadata', () => {
18+
$('video').addEventListener('loadedmetadata', () => {
1719
const data = e.detail.getPlayerResponse();
20+
data.videoDetails.album = $('ytmusic-player-page')?.__data?.playerPageWatchMetadata?.albumName?.runs[0].text
1821
ipcRenderer.send("song-info-request", JSON.stringify(data));
1922
});
2023
}, { once: true, passive: true })
@@ -25,5 +28,5 @@ function setupTimeChangeListener() {
2528
ipcRenderer.send('timeChanged', mutations[0].target.value);
2629
global.songInfo.elapsedSeconds = mutations[0].target.value;
2730
});
28-
progressObserver.observe(document.querySelector('#progress-bar'), { attributeFilter: ["value"] })
31+
progressObserver.observe($('#progress-bar'), { attributeFilter: ["value"] })
2932
}

providers/song-info.js

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const songInfo = {
4545
songDuration: 0,
4646
elapsedSeconds: 0,
4747
url: "",
48+
album: undefined
4849
};
4950

5051
const handleData = async (responseText, win) => {
@@ -57,6 +58,7 @@ const handleData = async (responseText, win) => {
5758
songInfo.image = await getImage(songInfo.imageSrc);
5859
songInfo.uploadDate = data?.microformat?.microformatDataRenderer?.uploadDate;
5960
songInfo.url = data?.microformat?.microformatDataRenderer?.urlCanonical?.split("&")[0];
61+
songInfo.album = data?.videoDetails?.album
6062

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

0 commit comments

Comments
 (0)