-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·110 lines (105 loc) · 3.45 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env node
const iTunes = require('itunes-bridge');
const RPC = require('discord-rpc')
const { searchSong } = require('@tbogard/itunes-search');
const genre = require('./getGenreAsset')
const iTunesEmitter = iTunes.emitter;
let client = new RPC.Client({ transport: 'ipc' })
client.login({ clientId: '891586647790075964' }).catch(console.error);
iTunesEmitter.on('playing', function (type, CurrentTrack) {
console.log(CurrentTrack)
if (!CurrentTrack.artist || !CurrentTrack.album) {
client.on('ready', () => { })
client.request('SET_ACTIVITY', {
pid: process.pid,
activity:
{
details: `Playing ${CurrentTrack.name}`,
state: `Album: Unknown`,
timestamps:
{
end: Date.now() + CurrentTrack.remainingTime * 1000 + 1,
},
assets:
{
large_image: genre.getGenreAssets(CurrentTrack.album, CurrentTrack.genre, CurrentTrack.artist),
//you can change this, but please give me some credit for this!
large_text: `Made by justiceserv's MacOSDiscordRPC`,
small_image: `applemusic`,
small_text: 'https://jserv.xyz/',
},
buttons: [
{
label: 'Unable On Apple Music', url: `https://localhost/`
},
]
}
})
}
else {
searchSong(`${CurrentTrack.artist} - ${CurrentTrack.name}`).then((result) => {
client.on('ready', () => { })
client.request('SET_ACTIVITY', {
pid: process.pid,
activity:
{
details: `Playing ${CurrentTrack.name}`,
state: `Album: ${CurrentTrack.album}`,
timestamps:
{
end: Date.now() + CurrentTrack.remainingTime * 1000 + 1,
},
assets:
{
large_image: genre.getGenreAssets(CurrentTrack.album, CurrentTrack.genre, CurrentTrack.artist),
//you can change this, but please give me some credit for this!
large_text: `Made by justiceserv's MacOSDiscordRPC`,
small_image: `applemusic`,
small_text: 'https://jserv.xyz/',
},
buttons: [
{
label: 'Listen On Apple Music', url: `${result.results[0].trackViewUrl}`
},
]
}
})
}).catch(error => {
client.on('ready', () => { })
client.request('SET_ACTIVITY', {
pid: process.pid,
activity:
{
details: `Playing ${CurrentTrack.name}`,
state: `Album: ${CurrentTrack.album}`,
timestamps:
{
end: Date.now() + CurrentTrack.remainingTime * 1000 + 1,
},
assets:
{
large_image: genre.getGenreAssets(CurrentTrack.album, CurrentTrack.genre, CurrentTrack.artist),
//you can change this, but please give me some credit for this!
large_text: `Made by justiceserv's MacOSDiscordRPC`,
small_image: `applemusic`,
small_text: 'https://jserv.xyz/',
},
buttons: [
{
label: 'Unable On Apple Music', url: ``
},
]
}
})
})
}
})
iTunesEmitter.on('paused', function (type, CurrentTrack) {
client.request('SET_ACTIVITY', { pid: process.pid });
console.log(`${CurrentTrack.name} is stopped`)
})
iTunesEmitter.on('stopped', function () {
client.on('ready', () => { })
client.request('SET_ACTIVITY', { pid: process.pid });
console.log(`Apple Music is stopped.`)
})