th-ch / youtube-music

YouTube Music Desktop App bundled with custom plugins (and built-in ad blocker / downloader)
https://th-ch.github.io/youtube-music/
MIT License
8.58k stars 491 forks source link

[Feature Request]: set background music album/artist/title for mpris metadata #1323

Open mokurin000 opened 1 year ago

mokurin000 commented 1 year ago

Preflight Checklist

Problem Description

current behaviour of youtube-music gives strange metainfo for external mpris controller, while you could find background music title/singers/album on Youtube (for example this MMD video)

Proposed Solution

query youtube api and set album / title / singers

Alternatives Considered

set youtube movie URL in xesam:url, so external players may query the necessary meta info themselves

Additional Information

No response

JellyBrick commented 1 year ago

Alternatives Considered

set youtube movie URL in xesam:url, so external players may query the necessary meta info themselves

Please enable the shortcuts plugin

https://github.com/th-ch/youtube-music/blob/6774d54f5eca432edc2e11743d9d1b1c2fda9ac8/src/plugins/shortcuts/mpris.ts#L155-L162

mokurin000 commented 1 year ago

thx. I will mention this plugin in my README

JellyBrick commented 1 year ago

I keep opening this issue because I think we need extra help to solve it. If there is a way to get background music data directly from YouTube Music, I don't need to use the ugly hack to fix this issue.

mokurin000 commented 1 year ago

I tried every 'part' (contentDetails,id,liveStreamingDetails,localizations,player,recordingDetails,snippet,statistics,status,topicDetails) public but none is related to the background music

https://developers.google.com/youtube/v3/docs/videos/list

or could we locate ytd-video-description-music-section-renderer tag and read SONG, ARTIST and ALBUM with electron?

This is pretty hacky and may easily break with youtube updates

JellyBrick commented 1 year ago

or could we locate ytd-video-description-music-section-renderer tag and read SONG, ARTIST and ALBUM with electron?

This is pretty hacky and may easily break with youtube updates

It seems to doesn't work on YTM

mokurin000 commented 1 year ago

or could we locate ytd-video-description-music-section-renderer tag and read SONG, ARTIST and ALBUM with electron? This is pretty hacky and may easily break with youtube updates

It seems to doesn't work on YTM

create a hidden BrowserWindow and once received ready-to-show we could locate ytd-video-description-music-section-renderer and read up to three meta info in order of "title, artist, album"

descriptionSection = document.getElementsByTagName("ytd-video-description-music-section-renderer")[0];
metas = descriptionSection.querySelectorAll("yt-formatted-string#default-metadata");
const metainfo = {
        title: metas[0].innerText,
        artist: metas[1].innerText,
        album: metas[2].innerText || null,
};
mokurin000 commented 1 year ago

for a complete demo:

const {app, ipcMain, BrowserWindow} = require('electron')

app.on('ready', () => {

window = new BrowserWindow({width: 400, height: 300, show: false})

window.on('ready-to-show', () => {
    window.webContents.on('dom-ready', () => {
          window.webContents.executeJavaScript(`

    descriptionSection = document.getElementsByTagName("ytd-video-description-music-section-renderer")[0];
    let metas = descriptionSection.querySelectorAll("yt-formatted-string#default-metadata");

    const metainfo = {
        title: metas[0].innerText,
        artist: metas[1].innerText,
        album: metas[2].innerText || null,
    };

    require('electron').ipcRenderer.send('ytb-bg-music', metainfo);
        `);
    });
});

ipcMain.on('ytb-bg-music', (_, metainfo) => {
    console.log(metainfo);
});

window.loadURL("https://www.youtube.com/watch?v=H6iBYmRRLYQ")
});
Readf0x commented 1 year ago

This is similarly related, may need it's own issue. Could you possibly set the mpris player to something other than chromium? I know it's hard coded but there is supposedly an npm package that has support for mpris metadata not present in chromium's source code, but idk how well it works nor how difficult implementation of this would be. Using this it would also be possible to set the artUrl so external player controllers could see the album art.

JellyBrick commented 1 year ago

This is similarly related, may need it's own issue. Could you possibly set the mpris player to something other than chromium? I know it's hard coded but there is supposedly an npm package that has support for mpris metadata not present in chromium's source code, but idk how well it works nor how difficult implementation of this would be. Using this it would also be possible to set the artUrl so external player controllers could see the album art.

https://github.com/th-ch/youtube-music/issues/1323#issuecomment-1764185013