Skip to content

Commit

Permalink
Merge pull request #564 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Nov 25, 2023
2 parents d3f1ff6 + 20c284f commit 88eecf3
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/v2/bilibili/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module.exports = async (ctx) => {
// },
// });
const params = utils.addVerifyInfo(
`mid=${uid}&ps=30&tid=0&pn=1&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true&dm_img_list=[]&dm_img_str=${Buffer.from('no webgl').toString('base64')}&dm_cover_img_str=${Buffer.from(
`mid=${uid}&ps=30&tid=0&pn=1&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true&dm_img_list=[]&dm_img_str=${Buffer.from('no webgl').toString('base64').slice(0, -2)}&dm_cover_img_str=${Buffer.from(
'no webgl'
).toString('base64')}`,
)
.toString('base64')
.slice(0, -2)}`,
verifyString
);
const response = await got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, {
Expand Down
33 changes: 33 additions & 0 deletions lib/v2/google/alerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const { keyword } = ctx.params;

const { data: response, url: link } = await got('https://www.google.com/alerts/preview', {
searchParams: {
params: `[null,[null,null,null,[null,"${keyword}","com",[null,"en","US"],null,null,null,0,0],null,3,[[null,1,"[email protected]",[null,null,20],2,"en-US",null,null,null,null,null,"0",null,null,"AB2Xq4hcilCERh73EFWJVHXx-io2lhh1EhC8UD8"]]],0]`,
},
});

const $ = cheerio.load(response, null, false);

const items = $('li.result')
.toArray()
.map((item) => {
item = $(item);
const title = item.find('.result_title a');
return {
title: title.text(),
link: new URL(title.attr('href')).searchParams.get('url'),
author: item.find('.result_source').text(),
description: item.find('.snippet').html(),
};
});

ctx.state.data = {
title: `Google Alerts - ${keyword}`,
link,
item: items,
};
};
1 change: 1 addition & 0 deletions lib/v2/google/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
'/album/:id': ['hoilc'],
'/alerts/:keyword': ['TonyRL'],
'/citations/:id': ['KellyHwong'],
'/doodles/:language?': ['xyqfer'],
'/fonts/:sort?': ['Fatpandac'],
Expand Down
1 change: 1 addition & 0 deletions lib/v2/google/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = function (router) {
router.get('/album/:id', require('./album'));
router.get('/alerts/:keyword', require('./alerts'));
router.get('/citations/:id', require('./citations'));
router.get('/doodles/:language?', require('./doodles'));
router.get('/fonts/:sort?', require('./fonts'));
Expand Down
22 changes: 22 additions & 0 deletions lib/v2/showstart/params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { TITLE, HOST } = require('./const');
const { fetchCityList, fetchStyleList } = require('./service');

module.exports = async (ctx) => {
const type = ctx.params.type;
switch (type) {
case 'city':
ctx.state.data = {
title: `${TITLE} - 演出城市`,
link: `HOST`,
item: await fetchCityList(),
};
break;
case 'style':
ctx.state.data = {
title: `${TITLE} - 演出风格`,
link: HOST,
item: await fetchStyleList(),
};
break;
}
};
3 changes: 2 additions & 1 deletion lib/v2/showstart/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = (router) => {
router.get('/event/:cityCode/:showStyle?', require('./event'));
router.get('/search/:keyword', require('./search'));
router.get('/search/:keyword?', require('./search'));
router.get('/params/:type', require('./params'));
};
45 changes: 41 additions & 4 deletions lib/v2/showstart/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { HOST } = require('./const');
const { getAccessToken, post } = require('./utils');
const { getAccessToken, post, sortBy, uniqBy } = require('./utils');

async function fetchActivityList(
params = {
Expand All @@ -25,18 +25,53 @@ async function fetchActivityList(
) {
const accessToken = await getAccessToken();
const resp = await post('/web/activity/list', accessToken, params);

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 {
items: resp.result.result.map((item) => ({
title: item.title,
link: `${HOST}/event/${item.id}`,
description: `地点:${item.cityName} | ${item.siteName}`,
description: [image(item.poster), time(item.showTime), address(item.cityName, item.siteName), performers(item.performers), price(item.price)].join(''),
})),
};
}

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

async function fetchCityList() {
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}`,
}));
}

// styles is embed in each city item
// so we need to fetch all city items and then extract styles from them
async function fetchStyleList() {
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}`,
}));
}

async function fetchDictionary(cityCode, showStyle) {
const resp = await fetchParams();
const target = resp.result.find((item) => item.cityCode === cityCode);
if (!target) {
return {};
Expand All @@ -49,5 +84,7 @@ async function fetchDictionary(cityCode, showStyle) {

module.exports = {
fetchActivityList,
fetchCityList,
fetchStyleList,
fetchDictionary,
};
25 changes: 25 additions & 0 deletions lib/v2/showstart/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,33 @@ const post = async (requestPath, accessToken = md5(Date.now().toString()), paylo
return response;
};

function sortBy(items, key) {
return items.sort((a, b) => {
if (a[key] < b[key]) {
return -1;
}
if (a[key] > b[key]) {
return 1;
}
return 0;
});
}

function uniqBy(items, key) {
const set = new Set();
return items.filter((item) => {
if (set.has(item[key])) {
return false;
}
set.add(item[key]);
return true;
});
}

module.exports = {
post,
getAccessToken,
uuid,
sortBy,
uniqBy,
};
6 changes: 6 additions & 0 deletions website/docs/routes/other.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ Official Website: [https://news.yahoo.co.jp/pages/article/20200207](https://news

<Route author="denis-ya" example="/fisher-spb/news" path="/fisher-spb/news" />

## Google {#google}

### Alerts {#google-alerts}

<Route author="TonyRL" example="/google/alerts/RSSHub" path="/google/alerts/:keyword" paramsDesc={['Keyword']}/>

## Grand-Challenge {#grand-challenge}

### Challenge 列表 {#grand-challenge-challenge-lie-biao}
Expand Down
9 changes: 8 additions & 1 deletion website/docs/routes/shopping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,14 @@ For instance, in `https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3

<Route author="lchtao26" example="/showstart/event/571/3" path="/showstart/event/:cityCode/:showStyle?" paramsDesc={['演出城市 (编号)', '演出风格 (编号)']}/>

相关路由参数可在 URL 中找到,如:`https://www.showstart.com/event/list?pageNo=1&pageSize=20&cityCode=571&showStyle=26`
:::tip

路由参数查询

- cityCode: https://rsshub.app/showstart/params/city
- showStyle: https://rsshub.app/showstart/params/style

:::

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

Expand Down

0 comments on commit 88eecf3

Please sign in to comment.