feat(route): add Bandcamp Upcoming Live Streams (#8512)

This commit is contained in:
Ethan Shen 2021-11-27 16:58:07 +08:00 committed by GitHub
parent 8490e33230
commit 6ec9005946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 0 deletions

View File

@ -22,6 +22,10 @@ Full transcript support for better user experience.
<RouteEn author="nczitzk" example="/bandcamp/tag/united-kingdom" path="/bandcamp/tag/:tag?" :paramsDesc="['Tag, can be found in URL']"/>
### Upcoming Live Streams
<Route author="nczitzk" example="/bandcamp/live" path="/bandcamp/live"/>
## EZTV
::: tip

View File

@ -205,6 +205,10 @@ pageClass: routes
<Route author="nczitzk" example="/bandcamp/tag/united-kingdom" path="/bandcamp/tag/:tag?" :paramsDesc="['标签,可在 URL 中找到']"/>
### Upcoming Live Streams
<Route author="nczitzk" example="/bandcamp/live" path="/bandcamp/live"/>
## bilibili
见 [#bilibili](/social-media.html#bilibili)

41
lib/v2/bandcamp/live.js Normal file
View File

@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://bandcamp.com';
const currentUrl = `${rootUrl}/live_schedule`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('.curated-wrapper').remove();
const items = $('.live-listing')
.toArray()
.map((item) => {
item = $(item);
return {
link: item.find('.title-link').attr('href'),
title: item.find('.show-title').text(),
author: item.find('.show-artist').text(),
pubDate: parseDate(item.find('.show-time-container').text().trim().split(' UTC')[0]),
description: `<img src="${
item
.find('.show-thumb-image')
.attr('style')
.match(/background-image: url\((.*)\);/)[1]
}">`,
};
});
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/live': ['nczitzk'],
};

13
lib/v2/bandcamp/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'bandcamp.com': {
_name: 'Bandcamp',
'.': [
{
title: 'Upcoming Live Streams',
docs: 'https://docs.rsshub.app/multimedia.html#bandcamp-upcoming-live-streams',
source: ['/live_schedule'],
target: '/bandcamp/live',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/live', require('./live'));
};