-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from th-ch/master
bring the new commits to this fork
- v3.7.2
- v3.7.1
- v3.7.0
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.12
- v3.3.11
- v3.3.10
- v3.3.9
- v3.3.8
- v3.3.7
- v3.3.6
- v3.3.5
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.0
Showing
17 changed files
with
494 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
const Discord = require('discord-rpc'); | ||
const Discord = require("discord-rpc"); | ||
|
||
const getSongInfo = require("../../providers/song-info"); | ||
|
||
const rpc = new Discord.Client({ | ||
transport: 'ipc' | ||
transport: "ipc", | ||
}); | ||
|
||
const clientId = '790655993809338398'; | ||
// Application ID registered by @semvis123 | ||
const clientId = "790655993809338398"; | ||
|
||
module.exports = (win) => { | ||
const registerCallback = getSongInfo(win); | ||
|
||
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); | ||
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"; | ||
} 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); | ||
}); | ||
}); | ||
|
||
// Startup the rpc client | ||
rpc | ||
.login({ | ||
clientId, | ||
}) | ||
.catch(console.error); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
const { triggerAction } = require('../utils'); | ||
const { triggerAction } = require("../utils"); | ||
|
||
const CHANNEL = "navigation"; | ||
const ACTIONS = { | ||
NEXT: "next", | ||
BACK: 'back', | ||
} | ||
NEXT: "next", | ||
BACK: "back", | ||
}; | ||
|
||
function goToNextPage() { | ||
triggerAction(CHANNEL, ACTIONS.NEXT); | ||
triggerAction(CHANNEL, ACTIONS.NEXT); | ||
} | ||
|
||
function goToPreviousPage() { | ||
triggerAction(CHANNEL, ACTIONS.BACK); | ||
triggerAction(CHANNEL, ACTIONS.BACK); | ||
} | ||
|
||
module.exports = { | ||
CHANNEL: CHANNEL, | ||
ACTIONS: ACTIONS, | ||
global: { | ||
goToNextPage: goToNextPage, | ||
goToPreviousPage: goToPreviousPage, | ||
} | ||
CHANNEL: CHANNEL, | ||
ACTIONS: ACTIONS, | ||
actions: { | ||
goToNextPage: goToNextPage, | ||
goToPreviousPage: goToPreviousPage, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This is used for to control the songs | ||
const pressKey = (window, key) => { | ||
window.webContents.sendInputEvent({ | ||
type: "keydown", | ||
keyCode: key, | ||
}); | ||
}; | ||
|
||
module.exports = (win) => { | ||
return { | ||
previous: () => pressKey(win, "k"), | ||
next: () => pressKey(win, "j"), | ||
playPause: () => pressKey(win, "space"), | ||
like: () => pressKey(win, "_"), | ||
dislike: () => pressKey(win, "+"), | ||
search: () => pressKey(win, "/"), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
const { nativeImage } = require("electron"); | ||
|
||
const fetch = require("node-fetch"); | ||
|
||
// This selects the song title | ||
const titleSelector = ".title.style-scope.ytmusic-player-bar"; | ||
|
||
// This selects the song image | ||
const imageSelector = | ||
"#layout > ytmusic-player-bar > div.middle-controls.style-scope.ytmusic-player-bar > img"; | ||
|
||
// 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"; | ||
|
||
// This selects the progress bar, used for songlength and current progress | ||
const progressSelector = "#progress-bar"; | ||
|
||
// Grab the title using the selector | ||
const getTitle = (win) => { | ||
return win.webContents | ||
.executeJavaScript( | ||
"document.querySelector('" + titleSelector + "').innerText" | ||
) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
// Grab the image src using the selector | ||
const getImageSrc = (win) => { | ||
return win.webContents | ||
.executeJavaScript("document.querySelector('" + imageSelector + "').src") | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
// Grab the subinfo using the selector | ||
const getSubInfo = async (win) => { | ||
// Get innerText of subinfo element | ||
const subInfoString = await win.webContents.executeJavaScript( | ||
'document.querySelector("' + subInfoSelector + '").innerText' | ||
); | ||
|
||
// Split and clean the string | ||
const splittedSubInfo = subInfoString.replaceAll("\n", "").split(" • "); | ||
|
||
// Make sure we always return 3 elements in the aray | ||
const subInfo = []; | ||
for (let i = 0; i < 3; i++) { | ||
// Fill array with empty string if not defined | ||
subInfo.push(splittedSubInfo[i] || ""); | ||
} | ||
|
||
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 | ||
const getImage = async (src) => { | ||
const result = await fetch(src); | ||
const buffer = await result.buffer(); | ||
return nativeImage.createFromBuffer(buffer); | ||
}; | ||
|
||
const getPausedStatus = async (win) => { | ||
const title = await win.webContents.executeJavaScript("document.title"); | ||
return !title.includes("-"); | ||
}; | ||
|
||
// Fill songInfo with empty values | ||
const songInfo = { | ||
title: "", | ||
artist: "", | ||
views: "", | ||
likes: "", | ||
imageSrc: "", | ||
image: null, | ||
isPaused: true, | ||
songDuration: 0, | ||
elapsedSeconds: 0, | ||
}; | ||
|
||
const registerProvider = (win) => { | ||
// This variable will be filled with the callbacks once they register | ||
const callbacks = []; | ||
|
||
// This function will allow plugins to register callback that will be triggered when data changes | ||
const registerCallback = (callback) => { | ||
callbacks.push(callback); | ||
}; | ||
|
||
win.on("page-title-updated", async () => { | ||
// Save the old title temporarily | ||
const oldTitle = songInfo.title; | ||
// Get and set the new data | ||
songInfo.title = await getTitle(win); | ||
songInfo.isPaused = await getPausedStatus(win); | ||
|
||
const { songDuration, elapsedSeconds } = await getProgress(win); | ||
songInfo.songDuration = songDuration; | ||
songInfo.elapsedSeconds = elapsedSeconds; | ||
|
||
// If title changed then we do need to update other info | ||
if (oldTitle !== songInfo.title) { | ||
const subInfo = await getSubInfo(win); | ||
songInfo.artist = subInfo[0]; | ||
songInfo.views = subInfo[1]; | ||
songInfo.likes = subInfo[2]; | ||
songInfo.imageSrc = await getImageSrc(win); | ||
songInfo.image = await getImage(songInfo.imageSrc); | ||
} | ||
|
||
// Trigger the callbacks | ||
callbacks.forEach((c) => { | ||
c(songInfo); | ||
}); | ||
}); | ||
|
||
return registerCallback; | ||
}; | ||
|
||
module.exports = registerProvider; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters