Files
RSSHub/lib/v2/spotify/artist.js
Outvi V 36b4cc5baa feat(route): add spotify (#8966)
* feat: /spotify/playlist/:id

* feat: /spotify/artist

* feat(spotify/artist): add to radar

* feat: /spotify/saved

* feat: /spotify/top/{tracks,artists}

* feat(spotify): add images for artist and playlist

* docs: /spotify/*

* docs/en: /spotify configurations

* chore(spotify): apiKey/Secret -> clientId/Secret

* fix(spotify/utils): genres can be empty
2022-02-04 18:46:53 +08:00

42 lines
1.3 KiB
JavaScript

const utils = require('./utils');
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const token = await utils.getPublicToken();
const { id } = ctx.params;
const meta = await got
.get(`https://api.spotify.com/v1/artists/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.json();
const itemsResponse = await got
.get(`https://api.spotify.com/v1/artists/${id}/albums`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.json();
const albums = itemsResponse.items;
ctx.state.data = {
title: `Albums of ${meta.name}`,
link: meta.external_urls.spotify,
allowEmpty: true,
item: albums.map((x) => ({
title: x.name,
author: x.artists.map((a) => a.name).join(', '),
description: `"${x.name}" by ${x.artists.map((a) => a.name).join(', ')}, released at ${x.release_date} with ${x.total_tracks} tracks.`,
pubDate: parseDate(x.release_date),
link: x.external_urls.spotify,
})),
};
if (meta.images.length) {
ctx.state.data.image = meta.images[0].url;
}
};