|
|
|
@ -1,32 +1,55 @@
|
|
|
|
|
import {useEffect, useState} from "react";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
|
|
|
|
interface NowPlayingData {
|
|
|
|
|
introduction: string;
|
|
|
|
|
lastfm: {
|
|
|
|
|
artist: string;
|
|
|
|
|
track: string;
|
|
|
|
|
playing: boolean;
|
|
|
|
|
url: string | undefined;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function LastFmLi() {
|
|
|
|
|
const [nowPlayingData, setNowPlayingData] = useState<NowPlayingData>({
|
|
|
|
|
introduction: "",
|
|
|
|
|
lastfm: {
|
|
|
|
|
artist: "nobody",
|
|
|
|
|
playing: false,
|
|
|
|
|
track: "nothing",
|
|
|
|
|
url: undefined,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function updateNowPlaying() {
|
|
|
|
|
try {
|
|
|
|
|
const songRequestData = await axios.get("https://api.jakecover.me");
|
|
|
|
|
const songRequestData = await fetch("https://api.cobular.com/graphql", {
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
query: `
|
|
|
|
|
query {
|
|
|
|
|
nowPlaying {
|
|
|
|
|
track {
|
|
|
|
|
... on Track {
|
|
|
|
|
title
|
|
|
|
|
artists {
|
|
|
|
|
name
|
|
|
|
|
}
|
|
|
|
|
link
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setNowPlayingData(songRequestData.data);
|
|
|
|
|
`,
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: "application/json",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Dnt: "1",
|
|
|
|
|
},
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
|
|
|
|
const data: any = await songRequestData.json();
|
|
|
|
|
setNowPlayingData({
|
|
|
|
|
playing: true,
|
|
|
|
|
artist: data["data"]["nowPlaying"]["track"]["artists"][0]["name"],
|
|
|
|
|
track: data["data"]["nowPlaying"]["track"]["title"],
|
|
|
|
|
url: data["data"]["nowPlaying"]["track"]["link"],
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
@ -42,20 +65,15 @@ export function LastFmLi() {
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (nowPlayingData.lastfm.playing) {
|
|
|
|
|
if (nowPlayingData.playing) {
|
|
|
|
|
return (
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
href={nowPlayingData.lastfm.url}
|
|
|
|
|
target={"_blank"}
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
style={{color: "inherit", textDecoration: "inherit"}}
|
|
|
|
|
>
|
|
|
|
|
listening to {nowPlayingData.lastfm.track} by{" "}
|
|
|
|
|
{nowPlayingData.lastfm.artist}
|
|
|
|
|
<li id={"now-playing"}>
|
|
|
|
|
listening to{" "}
|
|
|
|
|
<a href={nowPlayingData.url} target={"_blank"} rel="noreferrer">
|
|
|
|
|
{nowPlayingData.track} by {nowPlayingData.artist}
|
|
|
|
|
</a>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return <li>not listening to anything right now.</li>;
|
|
|
|
|
return <li>not listening to anything right now. <br/></li>;
|
|
|
|
|
}
|