Skip to content

Commit ae3dd06

Browse files
committed
Added Artist and Album URLs to output json
1 parent 4c04a75 commit ae3dd06

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

client/page.js

100644100755
File mode changed.

server/app.js

100644100755
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// spotify-web-presence
2+
// By: dev-sda1
3+
// Version 1.0
4+
// GitHub Repo: https://github.com/dev-sda1/spotify-web-presence
5+
6+
// Changelog
7+
// 1.0 [6/7/2021]
8+
// - First Major Version!!11
9+
// - Added album URLs to JSON output
10+
// - Added seperate artist outputs to JSON output
11+
// - Errors on the data fetching of /currentplaying will now output in console instead of
12+
// relaying in the browser as "no track playing"
13+
//
14+
15+
116
const express = require("express");
217
const SpotifyWebApi = require("spotify-web-api-node");
318
const config = require("./config.json");
@@ -52,43 +67,37 @@ function getPlaying(req, res) {
5267
spotifyApi.getMyCurrentPlayingTrack()
5368
.then(function (data) {
5469

55-
//console.log(data.body.item.album.images[2]["url"]);
56-
//console.log(data.body.item.external_urls['spotify']);
57-
//console.log(data.body.item.album.external_urls['spotify']);
58-
//console.log(data.body.item.album.name);
59-
//var artist = data.body.item.artists[0]['name'];
60-
//console.log(data.body.item.artists);
61-
//console.log(artist);
62-
//console.log("hi")
70+
console.log(data.body.item.artists[0].name);
71+
console.log(data.body.item.artists[0].external_urls.spotify);
6372

6473
if (data.body === {}) {
6574
console.log("There is nothing.");
6675
}
6776

6877
var artists = "";
78+
var authors = {};
6979
var i;
7080

7181
try {
7282
if (data.body.item.artists.length > 1) {
7383
for (i = 0; i < data.body.item.artists.length; i++) {
74-
artists += data.body.item.artists[i]['name'] + ", "
84+
authors[data.body.item.artists[i].name] = data.body.item.artists[i].external_urls.spotify;
7585
}
7686
} else {
77-
artists += data.body.item.artists[0]['name']
87+
authors[data.body.item.artists[0]['name']] = data.body.item.artists[0].external_urls.spotify;
7888
}
7989

8090
res.json({
8191
"trackname": data.body.item.name,
82-
"author": artists,
83-
"url": data.body.item.external_urls['spotify'],
8492
"albumtitle": data.body.item.album.name,
8593
"albumart": data.body.item.album.images[1]["url"],
8694
"playing": data.body.is_playing,
87-
"urls": { "authorURL": "", "albumURL": "", "songURL": "" }
95+
"urls": { "albumURL": data.body.item.album.external_urls['spotify'], "trackURL": data.body.item.external_urls['spotify'], "artists": authors }
8896
});
8997

9098
} catch (e) {
9199
res.json({ "notice": "No sound playing" });
100+
console.log(e);
92101
}
93102

94103
}, function (err) {
@@ -99,9 +108,9 @@ function getPlaying(req, res) {
99108

100109

101110
app.get('/api/currentplaying', function (req, res) {
102-
var owo = Number(Math.floor(Date.now() / 1000) - tokenExpireEpoch);
103-
console.log(owo);
104-
if (owo >= 3600) {
111+
var timesincetoken = Number(Math.floor(Date.now() / 1000) - tokenExpireEpoch);
112+
//console.log(timesincetoken);
113+
if (timesincetoken >= 3600) {
105114
pleaseRefreshlmao();
106115
getPlaying(req, res);
107116
} else {
@@ -115,6 +124,7 @@ app.get('/api/currentplaying', function (req, res) {
115124
});
116125

117126

127+
// Callback - for when you're setting the API up for the first time
118128

119129
app.get('/callback', function (req, res) {
120130
var code = req.query.code;
@@ -137,7 +147,7 @@ app.get('/callback', function (req, res) {
137147
//res.status(err.code);
138148
//res.send(err.message);
139149
//res.sendStatus(500).json({"success": false});
140-
console.log("oh fuck it errored. error was: " + err.message);
150+
console.log("Fatal error! Couldn't get an auth token: " + err.message);
141151
})
142152
}
143153
});

server/config.json

100644100755
File mode changed.

server/package-lock.json

100644100755
Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dependencies": {
77
"cors": "^2.8.5",
88
"express": "^4.17.1",
9-
"nodemon": "^2.0.7",
9+
"nodemon": "^2.0.9",
1010
"spotify-web-api-node": "^5.0.2"
1111
},
1212
"devDependencies": {},

0 commit comments

Comments
 (0)