-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode tracker.js
More file actions
49 lines (46 loc) · 1.99 KB
/
node tracker.js
File metadata and controls
49 lines (46 loc) · 1.99 KB
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
import fetch from 'node-fetch';
import Lastfm from 'simple-lastfm';
const user = "OSU USER ID";
const lastfm_key = "LASTFM KEY"
const lastfm_secret = "LASTFM SECRET"
const lastfm_username = "LASTFM USERNAME"
const lastfm_password = "LASTFM PASSWORD"
var lastid = "0";
var lastfm = new Lastfm({
api_key: lastfm_key,
api_secret: lastfm_secret,
username: lastfm_username,
password: lastfm_password
});
lastfm.getSessionKey(function (session_result) {
console.log("lastfm session established");
if (session_result.success) {
setInterval(() => {
fetch("https://osu.ppy.sh/users/"+user+"/extra-pages/historical", { method: 'GET', redirect: 'follow' })
.then(response => response.text())
.then(result => {
var historical = JSON.parse(result)
if (historical.recent.count == 0) {
console.log("user has no recent scores")
lastid = "1";
} else {
if (lastid != historical.recent.items[0].id && lastid != "0") {
let artist = historical.recent.items[0].beatmapset.artist_unicode;
let title = historical.recent.items[0].beatmapset.title_unicode;
lastfm.scrobbleTrack({
artist: artist,
track: title,
callback: function (result) {
console.log("successfully scrobbled: ", artist, " - ", title);
}
});
}else console.log("no new plays");
lastid = historical.recent.items[0].id;
}
})
.catch(error => console.log('error', error));
}, 30000);
} else {
console.log("Error: " + session_result.error);
}
});