Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Bandcamp Tag #7523

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
};