Skip to content

Commit

Permalink
feat(route): melon chart (DIYgod#7318)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored May 25, 2021
1 parent fb16a63 commit 7242f72
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
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,
};
};

0 comments on commit 7242f72

Please sign in to comment.