mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
Added Discord rich presence and added extra properties to songinfo provider
This commit is contained in:
@ -23,7 +23,13 @@
|
|||||||
"linux": {
|
"linux": {
|
||||||
"icon": "assets/generated/icons/png",
|
"icon": "assets/generated/icons/png",
|
||||||
"category": "AudioVideo",
|
"category": "AudioVideo",
|
||||||
"target": ["AppImage", "snap", "freebsd", "deb", "rpm"]
|
"target": [
|
||||||
|
"AppImage",
|
||||||
|
"snap",
|
||||||
|
"freebsd",
|
||||||
|
"deb",
|
||||||
|
"rpm"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -53,6 +59,7 @@
|
|||||||
"@ffmpeg/core": "^0.8.4",
|
"@ffmpeg/core": "^0.8.4",
|
||||||
"@ffmpeg/ffmpeg": "^0.9.5",
|
"@ffmpeg/ffmpeg": "^0.9.5",
|
||||||
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.0",
|
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.0",
|
||||||
|
"discord-rpc": "^3.1.4",
|
||||||
"downloads-folder": "^3.0.1",
|
"downloads-folder": "^3.0.1",
|
||||||
"electron-debug": "^3.1.0",
|
"electron-debug": "^3.1.0",
|
||||||
"electron-is": "^3.0.0",
|
"electron-is": "^3.0.0",
|
||||||
|
|||||||
41
plugins/discord-rpc/back.js
Normal file
41
plugins/discord-rpc/back.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const DiscordRPC = require('discord-rpc');
|
||||||
|
const rpc = new DiscordRPC.Client({
|
||||||
|
transport: 'ipc'
|
||||||
|
});
|
||||||
|
|
||||||
|
const clientId = '790655993809338398';
|
||||||
|
|
||||||
|
module.exports = win => {
|
||||||
|
// If the page is ready, register the callback
|
||||||
|
win.on('ready-to-show', () => {
|
||||||
|
// Startup the rpc client
|
||||||
|
rpc.login({
|
||||||
|
clientId
|
||||||
|
}).catch(console.error);
|
||||||
|
|
||||||
|
// Register the callback
|
||||||
|
global.songInfo.onNewData(songInfo => {
|
||||||
|
// Song information changed, so lets update the rich presence
|
||||||
|
|
||||||
|
const activityInfo = {
|
||||||
|
details: songInfo.title,
|
||||||
|
state: songInfo.artist,
|
||||||
|
largeImageKey: 'logo',
|
||||||
|
largeImageText: songInfo.views + ' - ' + songInfo.likes
|
||||||
|
};
|
||||||
|
|
||||||
|
if (songInfo.isPaused) {
|
||||||
|
// Add an idle icon to show that the song is paused
|
||||||
|
activityInfo.smallImageKey = 'idle';
|
||||||
|
activityInfo.smallImageText = 'idle/paused';
|
||||||
|
} else {
|
||||||
|
// Add the start and end time of the song
|
||||||
|
const songStartTime = Date.now() - (songInfo.elapsedSeconds * 1000);
|
||||||
|
activityInfo.startTimestamp = songStartTime;
|
||||||
|
activityInfo.endTimestamp = songStartTime + (songInfo.songDuration * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc.setActivity(activityInfo);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -10,6 +10,9 @@ const imageSelector = '#layout > ytmusic-player-bar > div.middle-controls.style-
|
|||||||
// This selects the song subinfo, this includes artist, views, likes
|
// This selects the song subinfo, this includes artist, views, likes
|
||||||
const subInfoSelector = '#layout > ytmusic-player-bar > div.middle-controls.style-scope.ytmusic-player-bar > div.content-info-wrapper.style-scope.ytmusic-player-bar > span';
|
const subInfoSelector = '#layout > ytmusic-player-bar > div.middle-controls.style-scope.ytmusic-player-bar > div.content-info-wrapper.style-scope.ytmusic-player-bar > span';
|
||||||
|
|
||||||
|
// This selects the progress bar, used for songlength and current progress
|
||||||
|
const progressSelector = '#progress-bar';
|
||||||
|
|
||||||
// This is used for to control the songs
|
// This is used for to control the songs
|
||||||
const presskey = (window, key) => {
|
const presskey = (window, key) => {
|
||||||
window.webContents.sendInputEvent({
|
window.webContents.sendInputEvent({
|
||||||
@ -55,6 +58,18 @@ const getSubInfo = async win => {
|
|||||||
return subInfo;
|
return subInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Grab the progress using the selector
|
||||||
|
const getProgress = async win => {
|
||||||
|
// Get max value of the progressbar element
|
||||||
|
const songDuration = await win.webContents.executeJavaScript(
|
||||||
|
'document.querySelector("' + progressSelector + '").max');
|
||||||
|
// Get current value of the progressbar element
|
||||||
|
const elapsedSeconds = await win.webContents.executeJavaScript(
|
||||||
|
'document.querySelector("' + progressSelector + '").value');
|
||||||
|
|
||||||
|
return {songDuration, elapsedSeconds};
|
||||||
|
};
|
||||||
|
|
||||||
// Grab the native image using the src
|
// Grab the native image using the src
|
||||||
const getImage = async src => {
|
const getImage = async src => {
|
||||||
const result = await fetch(src);
|
const result = await fetch(src);
|
||||||
@ -79,7 +94,9 @@ module.exports = win => {
|
|||||||
likes: '',
|
likes: '',
|
||||||
imageSrc: '',
|
imageSrc: '',
|
||||||
image: null,
|
image: null,
|
||||||
isPaused: true
|
isPaused: true,
|
||||||
|
songDuration: 0,
|
||||||
|
elapsedSeconds: 0
|
||||||
};
|
};
|
||||||
// The song control functions
|
// The song control functions
|
||||||
global.songControls = {
|
global.songControls = {
|
||||||
@ -102,6 +119,10 @@ module.exports = win => {
|
|||||||
global.songInfo.title = await getTitle(win);
|
global.songInfo.title = await getTitle(win);
|
||||||
global.songInfo.isPaused = await getPausedStatus(win);
|
global.songInfo.isPaused = await getPausedStatus(win);
|
||||||
|
|
||||||
|
const {songDuration, elapsedSeconds} = await getProgress(win);
|
||||||
|
global.songInfo.songDuration = songDuration;
|
||||||
|
global.songInfo.elapsedSeconds = elapsedSeconds;
|
||||||
|
|
||||||
// If title changed then we do need to update other info
|
// If title changed then we do need to update other info
|
||||||
if (oldTitle !== global.songInfo.title) {
|
if (oldTitle !== global.songInfo.title) {
|
||||||
const subInfo = await getSubInfo(win);
|
const subInfo = await getSubInfo(win);
|
||||||
|
|||||||
13
yarn.lock
13
yarn.lock
@ -2885,6 +2885,14 @@ dir-glob@^2.2.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
path-type "^3.0.0"
|
path-type "^3.0.0"
|
||||||
|
|
||||||
|
discord-rpc@^3.1.4:
|
||||||
|
version "3.1.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/discord-rpc/-/discord-rpc-3.1.4.tgz#6d449a682e6a0dec4f0444d5f36f9ebfabaccf91"
|
||||||
|
integrity sha512-QaBu+gHica2SzgRAmTpuJ4J8DX9+fDwAqhvaie3hcbkU9WPqewEPh21pWdd/7vTI/JNuapU7PFm2ZKg3BTkbGg==
|
||||||
|
dependencies:
|
||||||
|
node-fetch "^2.6.1"
|
||||||
|
ws "^7.3.1"
|
||||||
|
|
||||||
dmg-builder@22.8.1:
|
dmg-builder@22.8.1:
|
||||||
version "22.8.1"
|
version "22.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-22.8.1.tgz#9b3bcbbc43e5fed232525d61a5567ea4b66085c3"
|
resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-22.8.1.tgz#9b3bcbbc43e5fed232525d61a5567ea4b66085c3"
|
||||||
@ -8745,6 +8753,11 @@ ws@^7.2.3:
|
|||||||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8"
|
resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8"
|
||||||
integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==
|
integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==
|
||||||
|
|
||||||
|
ws@^7.3.1:
|
||||||
|
version "7.4.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.2.tgz#782100048e54eb36fe9843363ab1c68672b261dd"
|
||||||
|
integrity sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==
|
||||||
|
|
||||||
xdg-basedir@^4.0.0:
|
xdg-basedir@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
|
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
|
||||||
|
|||||||
Reference in New Issue
Block a user