Skip to content

Commit

Permalink
feat(route/秀动网): add more routes (#13884)
Browse files Browse the repository at this point in the history
* feat(route): add artist route

* feat(route): add brand route

* chore: merge '/params' route into '/search' route

* chore: fix and clean code

* chore: sort new entries in alphabetical order.

* chore: add new routes in maintainer

* chore: sort maintain entries in alphabetical order.

* fix: fix event route
  • Loading branch information
lchtao26 authored Nov 26, 2023
1 parent ffaca71 commit be74209
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 57 deletions.
15 changes: 15 additions & 0 deletions lib/v2/showstart/artist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { TITLE, HOST } = require('./const');
const { fetchPerformerInfo } = require('./service');

module.exports = async (ctx) => {
const id = ctx.params.id;
const artist = await fetchPerformerInfo({
performerId: id,
});
ctx.state.data = {
title: `${TITLE} - ${artist.name}`,
description: artist.content,
link: `${HOST}/artist/${artist.id}`,
item: artist.activityList,
};
};
15 changes: 15 additions & 0 deletions lib/v2/showstart/brand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { TITLE, HOST } = require('./const');
const { fetchBrandInfo } = require('./service');

module.exports = async (ctx) => {
const id = ctx.params.id;
const brand = await fetchBrandInfo({
brandId: id,
});
ctx.state.data = {
title: `${TITLE} - ${brand.name}`,
description: brand.content,
link: `${HOST}/host/${brand.id}`,
item: brand.activityList,
};
};
2 changes: 1 addition & 1 deletion lib/v2/showstart/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { fetchActivityList, fetchDictionary } = require('./service');
module.exports = async (ctx) => {
const cityCode = parseInt(ctx.params.cityCode);
const showStyle = parseInt(ctx.params.showStyle);
const { items } = await fetchActivityList({
const items = await fetchActivityList({
cityCode,
showStyle,
});
Expand Down
4 changes: 3 additions & 1 deletion lib/v2/showstart/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
'/artist/:id': ['lchtao26'],
'/brand/:id': ['lchtao26'],
'/event/:cityCode/:showStyle?': ['lchtao26'],
'/search/:keyword': ['lchtao26'],
'/search/:type/:keyword?': ['lchtao26'],
};
22 changes: 0 additions & 22 deletions lib/v2/showstart/params.js

This file was deleted.

14 changes: 13 additions & 1 deletion lib/v2/showstart/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ module.exports = {
target: (_, url) => {
const search = new URL(url).searchParams;
const keyword = search.get('keyword') || '';
return `/showstart/search/${keyword}`;
return `/showstart/search/event/${keyword}`;
},
},
{
title: '音乐人 - 演出更新',
docs: 'https://docs.rsshub.app/routes/shopping#yin-yue-ren-yan-chu-geng-xin',
source: ['/artist/:id'],
target: '/showstart/artist/:id',
},
{
title: '厂牌 - 演出更新',
docs: 'https://docs.rsshub.app/routes/shopping#chang-pai-yan-chu-geng-xin',
source: ['/host/:id'],
target: '/showstart/brand/:id',
},
],
},
};
5 changes: 3 additions & 2 deletions lib/v2/showstart/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = (router) => {
router.get('/artist/:id', require('./artist'));
router.get('/brand/:id', require('./brand'));
router.get('/event/:cityCode/:showStyle?', require('./event'));
router.get('/search/:keyword?', require('./search'));
router.get('/params/:type', require('./params'));
router.get('/search/:type/:keyword?', require('./search'));
};
57 changes: 47 additions & 10 deletions lib/v2/showstart/search.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
const { TITLE, HOST } = require('./const');
const { fetchActivityList } = require('./service');
const { fetchActivityList, fetchPerformerList, fetchBrandList, fetchCityList, fetchStyleList } = require('./service');

module.exports = async (ctx) => {
const keyword = ctx.params.keyword;
const { items } = await fetchActivityList({
keyword,
});
ctx.state.data = {
title: `${TITLE} - ${keyword}`,
link: HOST,
item: items,
};
const type = ctx.params.type || '';
const keyword = ctx.params.keyword || '';

switch (type) {
case 'event':
ctx.state.data = {
title: `${TITLE} - 搜演出 - ${keyword || '全部'}`,
link: HOST,
item: await fetchActivityList({ keyword }),
};
break;
case 'artist':
ctx.state.data = {
title: `${TITLE} - 搜艺人 - ${keyword || '全部'}`,
link: HOST,
item: await fetchPerformerList({ searchKeyword: keyword }),
};
break;
case 'brand':
ctx.state.data = {
title: `${TITLE} - 搜厂牌 - ${keyword || '全部'}`,
link: HOST,
item: await fetchBrandList({ searchKeyword: keyword }),
};
break;
case 'city':
ctx.state.data = {
title: `${TITLE} - 搜城市 - ${keyword || '全部'}`,
link: HOST,
item: await fetchCityList(keyword),
};
break;
case 'style':
ctx.state.data = {
title: `${TITLE} - 搜风格 - ${keyword || '全部'}`,
link: HOST,
item: await fetchStyleList(keyword),
};
break;
default:
ctx.state.data = {
title: `${TITLE} - 搜演出 - ${type || '全部'}`,
link: HOST,
item: await fetchActivityList({ keyword: type }),
};
}
};
110 changes: 93 additions & 17 deletions lib/v2/showstart/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,121 @@ async function fetchActivityList(
) {
const accessToken = await getAccessToken();
const resp = await post('/web/activity/list', accessToken, params);
return resp.result.result.map((item) => formatActivity(item));
}

function formatActivity(item) {
const image = (src) => (src ? `<img src="${src}" />` : '');
const time = (time) => (time ? `<p>演出时间:${time}</p>` : '');
const address = (cityName, siteName) => (cityName || siteName ? `<p>地址:${[cityName, siteName].join(' - ')}</p>` : '');
const performers = (name) => (name ? `<p>艺人:${name}</p>` : '');
const price = (price) => (price ? `<p>票价:${price}</p>` : '');
return {
title: item.title,
link: `${HOST}/event/${item.id}`,
description: [image(item.poster), time(item.showTime), address(item.cityName, item.siteName), performers(item.performers), price(item.price)].join(''),
};
}

async function fetchPerformerList(
params = {
pageNo: '1',
pageSize: '30',
searchKeyword: '',
styleId: '',
}
) {
const accessToken = await getAccessToken();
const resp = await post('/web/performer/list', accessToken, params);
return resp.result.result.map((item) => ({
title: item.name,
link: `${HOST}/artist/${item.id}`,
description: `id: ${item.id}`,
}));
}

async function fetchPerformerInfo(
params = {
performerId: '',
}
) {
const accessToken = await getAccessToken();
const resp = await post('/web/performer/info', accessToken, params);
return {
items: resp.result.result.map((item) => ({
title: item.title,
link: `${HOST}/event/${item.id}`,
description: [image(item.poster), time(item.showTime), address(item.cityName, item.siteName), performers(item.performers), price(item.price)].join(''),
})),
id: params.id,
name: resp.result.name,
content: resp.result.content,
avatar: resp.result.avatar,
poster: resp.result.poster,
styles: resp.result.styles,
activityList: resp.result.activities.map((item) => formatActivity(item)),
};
}

async function fetchBrandInfo(
params = {
brandId: '',
}
) {
const accessToken = await getAccessToken();
const resp = await post('/web/brand/info', accessToken, params);
return {
id: params.id,
name: resp.result.name,
content: resp.result.content,
avatar: resp.result.avatar,
poster: resp.result.poster,
activityList: resp.result.activities.map((item) => formatActivity(item)),
};
}

async function fetchBrandList(
params = {
pageNo: '1',
pageSize: '30',
searchKeyword: '',
}
) {
const accessToken = await getAccessToken();
const resp = await post('/web/brand/list', accessToken, params);
return resp.result.result.map((item) => ({
title: item.name,
link: `${HOST}/host/${item.id}`,
description: `id: ${item.id}`,
}));
}

async function fetchParams() {
const accessToken = await getAccessToken();
return post('/web/activity/list/params', accessToken);
}

async function fetchCityList() {
async function fetchCityList(keyword = '') {
const resp = await fetchParams();
const cities = sortBy(resp.result, 'cityCode');
return cities.map((item) => ({
title: item.cityName,
link: `${HOST}/event/list?cityCode=${item.cityCode}`,
description: `cityCode: ${item.cityCode}`,
}));
return cities
.filter((item) => item.cityName.includes(keyword.trim()))
.map((item) => ({
title: item.cityName,
link: `${HOST}/event/list?cityCode=${item.cityCode}`,
description: `cityCode: ${item.cityCode}`,
}));
}

// styles is embed in each city item
// so we need to fetch all city items and then extract styles from them
async function fetchStyleList() {
async function fetchStyleList(keyword = '') {
const resp = await fetchParams();
let styles = resp.result.flatMap((item) => item.styles);
styles = uniqBy(styles, 'key');
styles = sortBy(styles, 'key');
return styles.map((item) => ({
title: item.showName,
link: `${HOST}/event/list?showStyle=${item.key}`,
description: `showStyle: ${item.key}`,
}));
return styles
.filter((item) => item.showName.includes(keyword.trim()))
.map((item) => ({
title: item.showName,
link: `${HOST}/event/list?showStyle=${item.key}`,
description: `showStyle: ${item.key}`,
}));
}

async function fetchDictionary(cityCode, showStyle) {
Expand All @@ -86,5 +158,9 @@ module.exports = {
fetchActivityList,
fetchCityList,
fetchStyleList,
fetchPerformerList,
fetchPerformerInfo,
fetchBrandList,
fetchBrandInfo,
fetchDictionary,
};
25 changes: 22 additions & 3 deletions website/docs/routes/shopping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -711,17 +711,36 @@ For instance, in `https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3

:::tip

路由参数查询
- 演出城市 `cityCode` 查询: `/showstart/search/city/:keyword`, 如: https://rsshub.app/showstart/search/city/杭州

- cityCode: https://rsshub.app/showstart/params/city
- showStyle: https://rsshub.app/showstart/params/style
- 演出风格 `showStyle` 查询: `/showstart/search/style/:keyword`,如: https://rsshub.app/showstart/search/style/摇滚

:::

### 演出搜索 {#xiu-dong-wang-yan-chu-sou-suo}

<Route author="lchtao26" example="/showstart/search/live" path="/showstart/search/:keyword" paramsDesc={['搜索关键词']}/>

### 音乐人 - 演出更新 {#yin-yue-ren-yan-chu-geng-xin}

<Route author="lchtao26" example="/showstart/artist/301783" path="/showstart/artist/:id" paramsDesc={['音乐人 ID']}/>

:::tip

音乐人 ID 查询: `/showstart/search/artist/:keyword`,如: https://rsshub.app/showstart/search/artist/周杰伦

:::

### 厂牌 - 演出更新 {#chang-pai-yan-chu-geng-xin}

<Route author="lchtao26" example="/showstart/brand/34707" path="/showstart/brand/:id" paramsDesc={['厂牌 ID']}/>

:::tip

厂牌 ID 查询: `/showstart/search/brand/:keyword`,如: https://rsshub.app/showstart/search/brand/声场

:::

## 优衣库 {#you-yi-ku}

### Stylingbook {#you-yi-ku-stylingbook}
Expand Down

0 comments on commit be74209

Please sign in to comment.