feat(route): melon chart (#7318)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-05-25 21:29:32 +08:00
committed by GitHub
parent fb16a6325c
commit 7242f72e8d
4 changed files with 68 additions and 0 deletions

View File

@@ -66,6 +66,18 @@ Official RSS: https://eztv.io/ezrss.xml
<RouteEn author="DCJaous" example="/javlibrary/bestreviews" path="/javlibrary/bestreviews" radar="1" rssbud="1"/>
## Melon
### Chart
<RouteEn author="nczitzk" example="/melon/chart" path="/melon/chart/:category?" :paramsDesc="['Category, see below, 24H by default']">
| 24H | 일간 | 주간 | 월간 |
| - | - | - | - |
| | day | week | month |
</RouteEn>
## Nyaa
### Seatch Result

View File

@@ -443,6 +443,18 @@ pageClass: routes
<Route author="hoilc" example="/lastfm/top/spain" path="/lastfm/top/:country?" :paramsDesc="['国家或地区, 需要符合`ISO 3166-1`的英文全称, 可参考`https://zh.wikipedia.org/wiki/ISO_3166-1二位字母代码#正式分配代码`']" radar="1" rssbud="1"/>
## Melon
### Chart
<Route author="nczitzk" example="/melon/chart" path="/melon/chart/:category?" :paramsDesc="['分类见下表默认为24H']">
| 24H | 일간 | 주간 | 월간 |
| --- | ---- | ---- | ----- |
| | day | week | month |
</Route>
## Mp4Ba
### 影视分类

View File

@@ -4071,6 +4071,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'));
// Melon
router.get('/melon/chart/:category?', require('./routes/melon/chart'));
// 弯弯字幕组
router.get('/wanwansub/info/:id', require('./routes/wanwansub/info'));
router.get('/wanwansub/:id?', require('./routes/wanwansub/index'));

41
lib/routes/melon/chart.js Normal file
View File

@@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category;
const rootUrl = 'https://www.melon.com';
const currentUrl = `${rootUrl}/chart/${category ? category + '/' : ''}index.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const items = $('tr[data-song-no]')
.map((_, item) => {
item = $(item);
const image = item
.find('.image_typeAll img')
.attr('src')
.split(/\/melon\//)[0];
const title = item.find('.rank01').text();
const name = item.find('.rank02').text();
const album = item.find('.rank03').text();
return {
link: currentUrl,
title: item.find('.rank01').text(),
description: `<img src="${image}"><p>${title}</p><p>${name}</p><p>${album}</p>`,
};
})
.get();
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};