-
Notifications
You must be signed in to change notification settings - Fork 0
/
nowplaying-rnp_v2.js
145 lines (130 loc) · 4.63 KB
/
nowplaying-rnp_v2.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var update, prevtext, text, title, game, system, composer, artpath, timeremaining, timelength, displaytime
//getRequest();
function unEscape(htmlStr) {
htmlStr = htmlStr.replace(/</g , "<");
htmlStr = htmlStr.replace(/>/g , ">");
htmlStr = htmlStr.replace(/"/g , "\"");
htmlStr = htmlStr.replace(/'/g , "\'");
htmlStr = htmlStr.replace(/&/g , "&");
return htmlStr;
}
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
//continuous timer
var timer = setInterval(function() { getRequest(); }, 1000);
function getRequest() {
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
}
getJSON('http://localhost:8000/default/?cmd=FormatTitles¶m1=%25album%25|%25artist%25|%25title%25%|%24directory%28%25path%25%2C2%29|%24directory%28%25path%25%2C2%29%24char%2847%29%24directory%28%25path%25%2C1%29|%25playback_time%25|%25length%25|%25length_seconds%25|%25playback_time_remaining_seconds%25¶m3=file.json', function(err, data) {
//getJSON('http://localhost:8000/default/?cmd=FormatTitles¶m1=%25album%25|%25artist%25|%25title%25%|%25Comment%25|%25playback_time%25|%25length%25|%25length_seconds%25|%25playback_time_remaining_seconds%25¶m3=file.json', function(err, data) {
if (err != null) {
console.error(err);
} else {
//get song data
title = data[2];
game = data[0];
system = data[3];
composer = data[1];
artpath = '../Music/' + data[4] + '/albumart.png' //all my album art files are named "albumart.png" in the corresponding game folder
//Playback HH:MM:SS
timeremaining = data[5];
timelength = data[6];
//Playback Seconds
length_seconds = data[7];
playback_time_seconds = data[8];
playback_percentage_text = (playback_time_seconds/length_seconds).toLocaleString(undefined,{style: 'percent', minimumFractionDigits:1});
playback_percentage = (300 * (playback_time_seconds/length_seconds)).toFixed(2)+'px';
displaytime = timeremaining + " / " + timelength;
document.getElementById("time").textContent = displaytime;
document.getElementById("progress").style.width = playback_percentage;
//compare from last song
text = title + game + system + composer;
if (prevtext != text) {
//console.log("updated!")
//console.log("JSON: " + decodeHtml(data));
//console.log("artpath: " + artpath);
startAnimation();
updateArtwork();
}
game = unEscape(game);
title = unEscape(title);
composer = unEscape(composer);
prevtext = text;
}
})
};
function updateTime() {
document.getElementById("time").textContent = "test";
}
function updateArtwork() {
var t2 = anime.timeline({
targets: '.images',
easing: 'linear'
})
.add({
opacity: 0,
duration: 500
})
.add({
update: function() {
img = document.getElementById("image1");
img.src = artpath;
img.addEventListener("error", function(event) {
event.target.src = "../Music/Station ID/albumart.png"
event.onerror = null
})
//document.getElementById("image1").src = artpath;
}
})
.add({
opacity: 1,
duration: 500
})
};
function startAnimation() {
var t1 = anime.timeline({
targets: '.song',
easing: 'linear'
})
.add({
opacity: 0,
duration: 750
})
.add({
left: '-1200px',
duration: 10,
delay: 100
})
.add({
update: function() {
document.getElementById("title").textContent = title;
document.getElementById("game").textContent = game;
document.getElementById("system").textContent = system;
document.getElementById("composer").textContent = composer;
}
})
.add({
opacity: 1,
duration: 10
})
.add({
left: '20px',
delay: anime.stagger(600),
easing: 'spring(1, 90, 25, 0)'
})
}