diff --git a/docs/en/multimedia.md b/docs/en/multimedia.md index 872ccab45f86a4..80545236e00811 100644 --- a/docs/en/multimedia.md +++ b/docs/en/multimedia.md @@ -16,6 +16,12 @@ Full transcript support for better user experience. +## Bandcamp + +### Tag + + + ## EZTV ::: tip diff --git a/docs/multimedia.md b/docs/multimedia.md index c950374608ff9e..81731d5bbe8142 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -161,6 +161,12 @@ pageClass: routes +## Bandcamp + +### Tag + + + ## bilibili 见 [#bilibili](/social-media.html#bilibili) diff --git a/lib/router.js b/lib/router.js index 8f9039f4bbd71d..95f1207320bd4a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4067,6 +4067,9 @@ router.get('/jisilu/topic/:user', require('./routes/jisilu/topic')); // Constitutional Court of Baden-Württemberg (Germany) router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press')); +// Bandcamp +router.get('/bandcamp/tag/:tag?', require('./routes/bandcamp/tag')); + // Hugo 更新日志 router.get('/hugo/releases', require('./routes/hugo/releases')); diff --git a/lib/routes/bandcamp/tag.js b/lib/routes/bandcamp/tag.js new file mode 100644 index 00000000000000..177f9e461df64a --- /dev/null +++ b/lib/routes/bandcamp/tag.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const tag = ctx.params.tag; + + const rootUrl = 'https://bandcamp.com'; + const currentUrl = `${rootUrl}/tag/${tag}?tab=all_releases`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = response.data + .match(/tralbum_url":"(.*?)","audio_url/g) + .slice(0, 10) + .map((item) => ({ + link: item.match(/tralbum_url":"(.*?)","audio_url/)[1].split('"')[0], + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.title = content('.trackTitle').eq(0).text(); + item.author = content('h3 span a').text(); + item.description = content('#tralbumArt').html() + content('#trackInfo').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};