mirror of
				https://github.com/skidoodle/albert.lol.git
				synced 2025-02-15 06:09:15 +01:00 
			
		
		
		
	switch to spotify-now-playing
This commit is contained in:
		@@ -27,6 +27,7 @@
 | 
				
			|||||||
    "react-hot-toast": "^2.4.0",
 | 
					    "react-hot-toast": "^2.4.0",
 | 
				
			||||||
    "react-icons": "^4.4.0",
 | 
					    "react-icons": "^4.4.0",
 | 
				
			||||||
    "sass": "^1.55.0",
 | 
					    "sass": "^1.55.0",
 | 
				
			||||||
 | 
					    "spotify-now-playing": "^0.1.3",
 | 
				
			||||||
    "tailwindcss": "^3.1.8",
 | 
					    "tailwindcss": "^3.1.8",
 | 
				
			||||||
    "typescript": "4.8.4"
 | 
					    "typescript": "4.8.4"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,28 +1,22 @@
 | 
				
			|||||||
import { NextApiRequest, NextApiResponse } from "next";
 | 
					import { NextApiRequest, NextApiResponse } from 'next';
 | 
				
			||||||
 | 
					import { SpotifyService } from 'spotify-now-playing'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function (req: NextApiRequest, res: NextApiResponse) {
 | 
					export default async function (req: NextApiRequest, res: NextApiResponse) {
 | 
				
			||||||
  const { LASTFM_USERNAME, LASTFM_API } = process.env;
 | 
					    const { CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN } = process.env;
 | 
				
			||||||
 | 
					    const spotify = new SpotifyService(CLIENT_ID!, CLIENT_SECRET!, REFRESH_TOKEN!)
 | 
				
			||||||
 | 
					    const song = await spotify.getCurrentSong()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { recenttracks: response } = await fetch(
 | 
					    if(!song.isPlaying) {
 | 
				
			||||||
    `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${LASTFM_USERNAME}&api_key=${LASTFM_API}&format=json&limit=1`
 | 
					        return res.status(200).json({
 | 
				
			||||||
  ).then((res) => res.json());
 | 
					          nowplaying: false,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
  const { track } = response;
 | 
					    }
 | 
				
			||||||
  const { artist, name, url, image } = track[0];
 | 
					    res.status(200).json({
 | 
				
			||||||
 | 
					      nowplaying: true,
 | 
				
			||||||
  let nowplaying = Boolean(track[0]["@attr"]?.nowplaying);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (nowplaying) {
 | 
					 | 
				
			||||||
    return res.status(200).json({
 | 
					 | 
				
			||||||
      nowplaying,
 | 
					 | 
				
			||||||
      song: {
 | 
					      song: {
 | 
				
			||||||
        artist: artist["#text"],
 | 
					        artist: song.artist.name,
 | 
				
			||||||
        title: name,
 | 
					        title: song.title,
 | 
				
			||||||
        url: url,
 | 
					        url: song.externalUrl,
 | 
				
			||||||
        image: image[2]["#text"],
 | 
					      }
 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
  return res.status(200).json({ nowplaying });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1016,6 +1016,11 @@ side-channel@^1.0.4:
 | 
				
			|||||||
  resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
 | 
					  resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
 | 
				
			||||||
  integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
 | 
					  integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					spotify-now-playing@^0.1.3:
 | 
				
			||||||
 | 
					  version "0.1.3"
 | 
				
			||||||
 | 
					  resolved "https://registry.yarnpkg.com/spotify-now-playing/-/spotify-now-playing-0.1.3.tgz#1ffad53bf6b1fb0c36165f21a40fdfc99dec2c0a"
 | 
				
			||||||
 | 
					  integrity sha512-AB0Gp3eqUOO0WQHcapK7jxVQfED7uJQK9fIy5ALX51uBjCHSMLGtNKmr3Y70GoB6rEsIirr7zB7w1RliAp7TxQ==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
string.prototype.trimend@^1.0.5:
 | 
					string.prototype.trimend@^1.0.5:
 | 
				
			||||||
  version "1.0.5"
 | 
					  version "1.0.5"
 | 
				
			||||||
  resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz#914a65baaab25fbdd4ee291ca7dde57e869cb8d0"
 | 
					  resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz#914a65baaab25fbdd4ee291ca7dde57e869cb8d0"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user