This repository has been archived by the owner on Mar 7, 2019. It is now read-only.
forked from nations/spoticord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
82 lines (72 loc) · 2.7 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const DiscordRPC = require('discord-rpc'),
log = require("fancy-log"),
fs = require('fs'),
os = require("os");
const keys = require('./keys.json');
const rpc = new DiscordRPC.Client({ transport: keys.rpcTransportType }),
appClient = keys.appClientID,
largeImageKey = keys.imageKeys.large,
smallImageKey = keys.imageKeys.small,
smallImagePausedKey = keys.imageKeys.smallPaused;
async function readJSON() {
if (os.platform == "darwin") {
var obj = JSON.parse(require('fs').readFileSync(os.homedir() + '/Library/Application Support/Google Play Music Desktop Player/json_store/playback.json', 'utf8'));
} else if (os.platform == "linux") {
var obj = JSON.parse(require('fs').readFileSync(os.homedir() + '/.config/Google Play Music Desktop Player/json_store/playback.json', 'utf8'));
} else if (os.platform == "win32") {
var obj = JSON.parse(require('fs').readFileSync(os.homedir() + '\\AppData\\Roaming\\Google Play Music Desktop Player\\json_store\\playback.json', 'utf8'));
}
log.info("Playing: " + obj.song.title)
if (obj.playing == false) {
if (obj.song.title == null) {
if (keys.transmitwhenidle == true) {
rpc.setActivity({
details: `User has not picked a song,`,
state: ` or the app isn't open.`,
largeImageKey,
smallImagePausedKey,
largeImageText: `Playcord by theLMGN`,
smallImageText: `Nothing is playing.`,
instance: false,
});
}
} else {
rpc.setActivity({
details: `Paused: ${obj.song.title}`,
state: `by ${obj.song.artist}`,
largeImageKey,
smallImagePausedKey,
largeImageText: `Playcord by theLMGN`,
smallImageText: `💿 ${obj.song.album}`,
instance: false,
});
}
} else {
rpc.setActivity({
details: `Playing ${obj.song.title}`,
state: `by ${obj.song.artist}`,
startTimestamp: Math.floor((new Date() - obj.time.current) / 1000),
endTimestamp: Math.floor(((new Date() - obj.time.current) + obj.time.total) / 1000),
largeImageKey,
smallImageKey,
largeImageText: `Playcord by theLMGN`,
smallImageText: `💿 ${obj.song.album}`,
instance: true,
});
}
}
rpc.on('ready', () => {
log(`Connected to Discord! (${appClient})`);
setInterval(() => {
try {
readJSON()
} catch (e) {
log.error(e);
}
}, 1500);
});
if (os.platform() === "win32" || os.platform() === "darwin" || os.platform() === "linux") {
rpc.login(appClient).catch(log.error);
} else {
log.error(`We don't support ${os.platform()} just yet.`)
}