Skip to content

Commit

Permalink
🦉 Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
N0chteil committed May 26, 2021
1 parent 269707d commit 39e94b8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions AMRPC.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm start
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Apple Music RPC for Discord

## Installation
* Download the [latest release](https://github.com/N0chteil/Apple-Music-RPC/releases)
* Download the [latest release](https://github.com/N0chteil/Apple-Music-RPC/releases/latest)
* Extract the zip file
* Open the terminal and **cd \path\to\extracted\zip**
* Type **npm start**
* Open the **setup.bat** file
* Open the **AMRPC.bat** file

## Requirements
* Windows 10
* [iTunes](https://www.microsoft.com/p/itunes/9pb2mz1zmb1s?rtc=1&activetab=pivot:overviewtab)
* [NodeJS](https://nodejs.org/en/) (Tested with 14.17)

## Information
This RPC is only for the Windows program. If you use Apple Music in your browser, check out [Apple Music RPC for PreMiD](https://premid.app/store/presences/Apple%20Music)!
This RPC is only for the Windows program. If you use Apple Music in your browser (macOS, Windows, Linux), check out [Apple Music RPC for PreMiD](https://premid.app/store/presences/Apple%20Music)!

## Coming soon
* Autostart
Expand Down
39 changes: 29 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const clientId = '842112189618978897',
DiscordRPC = require('discord-rpc'),
iTunes = require('itunes-bridge');
DiscordRPC = require("discord-rpc"),
iTunes = require("itunes-bridge"),
AutoLaunch = require("auto-launch");

const rpc = new DiscordRPC.Client({ transport: 'ipc' }),
currentTrack = iTunes.getCurrentTrack(),
Expand All @@ -12,8 +13,13 @@ var presenceData = {
},
debugging = false;

let autoLaunch = new AutoLaunch({
name: "",
path: __dirname+"AMRPC.bat"
});

iTunesEmitter.on('playing', async function(type, currentTrack) {
presenceData.details = (currentTrack) ? `${currentTrack?.name} - ${currentTrack?.album}` : "Unknown track";
presenceData.details = (currentTrack) ? `${currentTrack.name} - ${currentTrack.album}` : "Unknown track";
presenceData.state = currentTrack.artist || "Unknown artist";

if(currentTrack) presenceData.endTimestamp = Math.floor(Date.now() / 1000) - currentTrack.elapsedTime + currentTrack.duration;
Expand All @@ -23,7 +29,14 @@ iTunesEmitter.on('playing', async function(type, currentTrack) {
console.log("type", type);
console.log("currentTrack.name", currentTrack.name);
console.log("currentTrack.album", currentTrack.album);
console.log("timestamp", Math.floor(Date.now() / 1000) - currentTrack?.elapsedTime + currentTrack?.duration);
console.log("timestamp", Math.floor(Date.now() / 1000) - currentTrack.elapsedTime + currentTrack.duration);

presenceData.buttons = [
{
label: "Play on Apple Music",
url: "https://music.apple.com"
}
]
}
});

Expand Down Expand Up @@ -57,17 +70,23 @@ if(process.argv.find(element => element === "supporting")) {
if(process.argv.find(element => element === "debugging")) {
debugging = true;
}

if(process.argv.find(element => element === "setup")) {
setTimeout(() => {
process.exit();
}, 5000);
autoLaunch.enable();
}

rpc.on('ready', () => {
presenceData.details = `${currentTrack.name} - ${currentTrack.album}` || "Unknown track";
presenceData.details = (currentTrack) ? `${currentTrack.name} - ${currentTrack.album}` : "Unknown track";
presenceData.state = currentTrack.artist || "Unknown artist";

setInterval(() => {
if(iTunes.isRunning()) {
if(presenceData.details.length > 128) presenceData.details = presenceData.details.substring(0,128);
if(presenceData.state.length > 128) presenceData.state = presenceData.state.substring(0,128);
rpc.setActivity(presenceData);
}
if(presenceData.details.length > 128) presenceData.details = presenceData.details.substring(0,128);
if(presenceData.state.length > 128) presenceData.state = presenceData.state.substring(0,128);

if(currentTrack) rpc.setActivity(presenceData);
}, 5);
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/N0chteil/Apple-Music-RPC#readme",
"dependencies": {
"auto-launch": "^5.0.5",
"discord-rpc": "^3.2.0",
"itunes-bridge": "^0.6.6"
}
Expand Down
9 changes: 9 additions & 0 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/N0chteil/Apple-Music-RPC/releases/download/latest/amrpc-win.zip', 'amrpc-win.zip')"
powershell -Command "Expand-Archive amrpc-win.zip ."
del "amrpc-win.zip"
>AMRPC.bat (
echo npm start
)
npm install
npm start setup
exit 0

0 comments on commit 39e94b8

Please sign in to comment.