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): melon chart #7318

Merged
merged 2 commits into from
May 25, 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
12 changes: 12 additions & 0 deletions docs/en/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### 影视分类
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
41 changes: 41 additions & 0 deletions lib/routes/melon/chart.js
Original file line number Diff line number Diff line change
@@ -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,
};
};