mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
* Added Discord timeout
* Add getOptions in plugin util
* Mutex in ffmpeg conversion (only supports one command at a time)
* Add menu customization in plugin system
* Add ytpl package (playlist info)
* Handle ffmpeg metadata flags when metadata is not present
* Only use artist in file name if present
* Export sendError method
* Handle image not present in metadata util
* Add downloader utils (getFolder and default menu label)
* Pass (optional) existing metadata and subfolder in mp3 converter
* Add listener to download playlist
* Add custom menu in downloader plugin ("download playlist" item)
* nit: fix main CSS style
* Only set the "enable" item in menu if plugin not enabled
* Navigation plugin: inject HTML once CSS is loaded
Co-authored-by: Sem Visscher <semvisscher10@gmail.com>
Co-authored-by: TC <th-ch@users.noreply.github.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
const Discord = require("discord-rpc");
|
|
|
|
const getSongInfo = require("../../providers/song-info");
|
|
|
|
const rpc = new Discord.Client({
|
|
transport: "ipc",
|
|
});
|
|
|
|
// Application ID registered by @semvis123
|
|
const clientId = "790655993809338398";
|
|
|
|
let clearActivity;
|
|
|
|
module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
|
|
const registerCallback = getSongInfo(win);
|
|
|
|
// If the page is ready, register the callback
|
|
win.on("ready-to-show", () => {
|
|
rpc.on("ready", () => {
|
|
// Register the callback
|
|
registerCallback((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";
|
|
// Set start the timer so the activity gets cleared after a while if enabled
|
|
if (activityTimoutEnabled)
|
|
clearActivity = setTimeout(()=>rpc.clearActivity(), activityTimoutTime||10,000);
|
|
|
|
} else {
|
|
// stop the clear activity timout
|
|
clearTimeout(clearActivity);
|
|
// 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);
|
|
});
|
|
});
|
|
|
|
// Startup the rpc client
|
|
rpc
|
|
.login({
|
|
clientId,
|
|
})
|
|
.catch(console.error);
|
|
});
|
|
};
|