Skip to content

Commit

Permalink
feat(route): add Bandcamp Tag (DIYgod#7523)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored May 12, 2021
1 parent f7fd251 commit 0e38a21
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Full transcript support for better user experience.

<RouteEn author="Ji4n1ng" example="/99percentinvisible/transcript" path="/99percentinvisible/transcript"/>

## Bandcamp

### Tag

<RouteEn author="nczitzk" example="/bandcamp/tag/united-kingdom" path="/bandcamp/tag/:tag?" :paramsDesc="['Tag, can be found in URL']"/>

## EZTV

::: tip
Expand Down
6 changes: 6 additions & 0 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ pageClass: routes

<Route author="I2IMk" example="/avgle/search/橋本ありな" path="/avgle/search/:keyword/:order?/:time?/:top?" :paramsDesc="['搜索的关键词', '视频次序, `bw` 观看中 / `mr` 最新 / `mv` 最多观看 / `tr` 最高评分 / `tf` 最多收藏 / `lg` 最长, 默认 `mr`', '视频的添加时间, `a` 所有 / `t` 今天 / `d` 本周 / `m` 本月, 默认 `a`', '按次序获取的视频数, 不大于 `250`, 默认 `30`']"/>

## Bandcamp

### Tag

<Route author="nczitzk" example="/bandcamp/tag/united-kingdom" path="/bandcamp/tag/:tag?" :paramsDesc="['标签,可在 URL 中找到']"/>

## bilibili

[#bilibili](/social-media.html#bilibili)
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
47 changes: 47 additions & 0 deletions lib/routes/bandcamp/tag.js
Original file line number Diff line number Diff line change
@@ -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&quot;:&quot;(.*?)&quot;,&quot;audio_url/g)
.slice(0, 10)
.map((item) => ({
link: item.match(/tralbum_url&quot;:&quot;(.*?)&quot;,&quot;audio_url/)[1].split('&quot;')[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,
};
};

0 comments on commit 0e38a21

Please sign in to comment.