tangled
alpha
login
or
join now
vielle.dev
/
site
0
fork
atom
Personal Site
0
fork
atom
overview
issues
pulls
pipelines
Use new API in <NowPlaying />
vielle.dev
7 months ago
f01e3563
a01f51cb
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+28
-17
1 changed file
expand all
collapse all
unified
split
src
components
playing
NowPlaying.astro
+28
-17
src/components/playing/NowPlaying.astro
···
1
1
---
2
2
-
import { getTrack, nowPlayingSongID } from "./spotify";
2
2
+
import { nowPlaying, SpotifyError } from "./spotify";
3
3
4
4
-
const nowPlaying = await nowPlayingSongID();
4
4
+
const track = await nowPlaying().catch((err) => {
5
5
+
if (!(err instanceof SpotifyError)) throw new Error("Unhandled exception");
6
6
+
console.error(err.code, err.human, err.details);
5
7
6
6
-
if (nowPlaying instanceof Error) return console.error("nowPlaying", nowPlaying);
8
8
+
if (err.code === "NO_CONTENT") return null;
9
9
+
return err;
10
10
+
});
7
11
8
8
-
const track = nowPlaying ? await getTrack(nowPlaying) : null;
9
9
-
if (track instanceof Error) return console.error("track", track);
12
12
+
console.log(track);
10
13
---
11
14
12
15
<section class="playing">
13
16
{
14
17
track ? (
15
15
-
<>
16
16
-
Now playing:
17
17
-
<img
18
18
-
src={
19
19
-
track.album.images.sort(
20
20
-
(a, b) => b.width + b.height - (a.width + a.height),
21
21
-
)[0].url
22
22
-
}
23
23
-
alt=""
24
24
-
/>
25
25
-
{track.name} by {track.artists.map((x) => x.name).join(",")}
26
26
-
</>
18
18
+
!(track instanceof SpotifyError) ? (
19
19
+
<>
20
20
+
Now playing:
21
21
+
<img
22
22
+
src={
23
23
+
track.album.images.sort(
24
24
+
(a, b) => b.width + b.height - (a.width + a.height),
25
25
+
)[0].url
26
26
+
}
27
27
+
alt=""
28
28
+
/>
29
29
+
{track.name} by {track.artists.map((x) => x.name).join(",")}
30
30
+
</>
31
31
+
) : (
32
32
+
<>
33
33
+
Error occurred {track.code} - {track.human} <br />
34
34
+
<code style="word-wrap: break-word;">{JSON.stringify(track.details)}</code>
35
35
+
<script set:html={`console.log(${JSON.stringify(track.details)})`}></script>
36
36
+
</>
37
37
+
)
27
38
) : (
28
39
<>Nothing is playing :(</>
29
40
)