Skip to content

Commit

Permalink
👨‍🔬 v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
N0chteil committed May 27, 2021
1 parent c491b02 commit 8503e05
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
package-lock.json
package-lock.json
release-builds/
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
## Installation
* Download the [latest release](https://github.com/N0chteil/Apple-Music-RPC/releases/latest)
* Extract the zip file
* Open the **setup.bat** file
* Open the **AMRPC.bat** file
* Open the **AMRPC.exe** file

## Requirements
* Windows 10
* [iTunes](https://www.microsoft.com/p/itunes/9pb2mz1zmb1s?rtc=1&activetab=pivot:overviewtab)
* Windows 10/macOS (Not tested with macOS)
* [iTunes for Windows 10](https://www.microsoft.com/p/itunes/9pb2mz1zmb1s?rtc=1&activetab=pivot:overviewtab), [iTunes for macOS](https://www.apple.com/itunes/download/macos)
* [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 (macOS, Windows, Linux), check out [Apple Music RPC for PreMiD](https://premid.app/store/presences/Apple%20Music)!

## Coming soon
* Autostart
* EXE installer
Binary file added assets/SFPro.ttf
Binary file not shown.
Binary file added assets/icons/mac/icon.icns
Binary file not shown.
Binary file added assets/icons/win/icon.ico
Binary file not shown.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tray/logo@18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"autolaunch": "false",
"debugging": "false",
"version": "2.0.0"
}
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>AMRPC</title>
</head>
<body>
<h1>Apple Music RPC</h1>

<style>
@font-face {
font-family: "SFPro";
src: url("assets/SFPro.ttf");
}

body {
font-family: SFPro;
}
</style>
<script>

</script>
</body>
</html>
83 changes: 43 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ const clientId = '842112189618978897',
iTunes = require("itunes-bridge"),
getAppleMusicLink = require("get-apple-music-link"),
AutoLaunch = require("auto-launch"),
request = require("request");
request = require("request"),
electron = require("electron"),
url = require("url"),
path = require("path"),
fs = require('fs');

const rpc = new DiscordRPC.Client({ transport: 'ipc' }),
currentTrack = iTunes.getCurrentTrack(),
iTunesEmitter = iTunes.emitter;
iTunesEmitter = iTunes.emitter,
{app, Menu, Notification, Tray} = electron,
config = JSON.parse(fs.readFileSync('config.json', 'utf8'));

let presenceData = {
largeImageKey: 'applemusic-logo',
largeImageText: `AMRPC - V.${process.env.npm_package_version}`
largeImageText: `AMRPC - V.${config.version}`
},
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.state = (currentTrack) ? currentTrack.artist : "Unknown artist";
Expand All @@ -31,7 +32,7 @@ iTunesEmitter.on('playing', async function(type, currentTrack) {
if(debugging) console.log(res);
presenceData.buttons = [
{
label: "Play on Apple Musicᴮᴱᵀᴬ",
label: "Play on Apple Music",
url: res
}
]
Expand Down Expand Up @@ -61,9 +62,7 @@ iTunesEmitter.on('paused', async function(type, currentTrack) {
});

iTunesEmitter.on('stopped', async function() {
if(debugging) {
console.log("\naction", "stopped");
}
if(debugging) console.log("\naction", "stopped");
});

if(process.argv.find(element => element === "supporting")) {
Expand Down Expand Up @@ -99,51 +98,55 @@ rpc.on('ready', () => {
}, 5);
});

app.on("ready", function() {
let tray = new Tray(`${__dirname}\\assets\\logo.png`),
isQuiting;

let autoLaunch = new AutoLaunch({
name: "AMRPC",
path: app.getPath('exe')
});

app.on("quit", () => tray.destroy());
app.on('before-quit', function () {
isQuiting = true;
});

tray.setToolTip("AMRPC");
tray.setContextMenu(Menu.buildFromTemplate([
{ label: `AMRPC V${config.version}`, icon: `${__dirname}\\assets\\tray\\logo@18.png`, enabled: false },
{ type: "separator" },
{ label: "Show Presence", type: "checkbox", checked: (config.show) ? true : false, click() { updateShowRPC(this.checked) } },
{ label: "Quit", click() { isQuiting = true, app.quit() } }
]));
tray.on("right-click", () => tray.update());
autoLaunch.enable();
});

function updateChecker() {
const fetchUrl = require("fetch").fetchUrl;

fetchUrl("https://api.github.com/repos/N0chteil/Apple-Music-RPC/tags", function(error, meta, body) {
body = JSON.parse(body.toString());
let version = {
git: body[0].name.replace(".", "").replace("v", ""),
package: process.env.npm_package_version.replace(".", "")
package: config.version.replace(".", "")
}

if(version.git > version.package) {
console.log("\x1b[31m%s\x1b[0m", `VersionCheck: Your version is outdated. Newest release is ${body[0].name}`);
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Downloading newest release...");
setTimeout(() => {
updateVersion(body[0].name);
}, 2000);
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Please download the newest release from GitHub (Updater is currently in work)");
showNotification("VersionCheck", `Your version is outdated. Newest release is ${body[0].name}`);
showNotification("VersionCheck", "Please download the newest release from GitHub (Updater is currently in work)");
} else {
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Up to date");
showNotification("VersionCheck", "Up to date");
}
});
}

function updateVersion(version) {
const download = require("download-git-repo"),
fs = require('fs');

download(`direct:https://github.com/N0chteil/Apple-Music-RPC/releases/download/${version}/amrpc-win.zip`, 'github_newest', function (err) {
err = (err === undefined || err === false) ? false : true;
if(!err) {
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Successfully downloaded!");
fs.writeFile("updater.bat", 'del "index.js"\ndel "package.json"\nmove /y github_newest\\*.* .\n@RD /S /Q "github_newest"\nnpm install\ndel "updater.bat"', function(err) {
if(err) return console.log(err);
else {
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Created updater file. Exiting process in 10 seconds.");
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Please open the updater file after the process is finished.");
}
});
setTimeout(() => {
require('child_process').exec('updater.bat');
process.exit();
}, 10000);
} else {
console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Error downloading the latest version from GitHub");
}
})
function showNotification (title, body) {
new Notification({title: title,body: body}).show()
}

rpc.login({ clientId }).catch(console.error);
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "Discord RPC for iTunes",
"main": "index.js",
"scripts": {
"start": "node index.js"
"start": "node index.js",
"test": "electron .",
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
"package-win": "electron-packager . AMRPC --overwrite --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=N0chteil --version-string.FileDescription=Discord RPC for Apple Music --version-string.ProductName=\"AMRPC\"",
"package-linux": "electron-packager . AMRPC --overwrite --platform=linux --arch=x64 --icon=assets/logo.png --prune=true --out=release-builds"
},
"repository": {
"type": "git",
Expand All @@ -29,5 +33,9 @@
"fetch": "^1.1.0",
"get-apple-music-link": "^1.0.0",
"itunes-bridge": "^0.6.6"
},
"devDependencies": {
"electron": "^13.0.1",
"electron-packager": "^15.2.0"
}
}

0 comments on commit 8503e05

Please sign in to comment.