feat: add DLsite同人贩售站 当前日期发售产品 (#3296)

This commit is contained in:
cssxsh
2019-10-21 12:11:46 +08:00
committed by DIYgod
parent 9c9a3cf6ca
commit a226c6ac59
3 changed files with 123 additions and 0 deletions

View File

@@ -79,6 +79,18 @@ pageClass: routes
见 [#bilibili](/social-media.html#bilibili) 见 [#bilibili](/social-media.html#bilibili)
## DLsite
### 当前日期发售产品
<Route author="cssxsh" example="/dlsite/new/home" path="/dlsite/new/:type" :paramsDesc="['类型,如下表']">
| 同人 | 漫画 | 软件 | 同人(R18) | 漫画(R18) | 美少女游戏 | 乙女 | BL |
| ---- | ----- | ---- | --------- | --------- | ---------- | ----- | --- |
| home | comic | soft | maniax | books | pro | girls | bl |
</Route>
## ebb.io ## ebb.io
### ebb ### ebb

View File

@@ -1861,6 +1861,9 @@ router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous
// kaggle // kaggle
router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion')); router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion'));
// dlsite
router.get('/dlsite/new/:type', require('./routes/dlsite/new'));
// mcbbs // mcbbs
router.get('/mcbbs/forum/:type', require('./routes/mcbbs/forum')); router.get('/mcbbs/forum/:type', require('./routes/mcbbs/forum'));
router.get('/mcbbs/post/:tid/:authorid?', require('./routes/mcbbs/post')); router.get('/mcbbs/post/:tid/:authorid?', require('./routes/mcbbs/post'));

108
lib/routes/dlsite/new.js Normal file
View File

@@ -0,0 +1,108 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const host = 'https://www.dlsite.com';
const infos = {
// 全年齢向け
home: {
type: 'home',
name: '「DLsite 同人」',
url: '/home/new',
},
comic: {
type: 'comic',
name: '「DLsite コミック」',
url: '/comic/new',
},
soft: {
type: 'soft',
name: '「DLsite PCソフト」',
url: '/soft/new',
},
// 成人向け( R18 )
maniax: {
type: 'maniax',
name: '「DLsite 同人 - R18」',
url: '/maniax/new',
},
books: {
type: 'books',
name: '「DLsite 成年コミック - R18」',
url: '/books/new',
},
pro: {
type: 'pro',
name: '「DLsite 美少女ゲーム」',
url: '/pro/new',
},
// 女性向け
girls: {
type: 'girls',
name: '「DLsite 乙女」',
url: '/girls/new',
},
bl: {
type: 'bl',
name: '「DLsite BL」',
url: '/bl/new',
},
};
module.exports = async (ctx) => {
const info = infos[ctx.params.type];
// 判断参数是否合理
if (info === undefined) {
throw Error('不支持指定类型!');
}
const response = await got(info.url, {
method: 'GET',
baseUrl: host,
});
const data = response.data;
const $ = cheerio.load(data);
const title = $('title').text();
const link = response.requestUrl;
const description = $('meta[name="description"]').attr('content');
const list = $('.n_worklist_item');
const dateText = $('.work_update')
.text()
.replace(/(年 |月)/g, '-')
.substring(0, 10);
const pubDate = new Date(`${dateText} GMT+0900`).toUTCString();
const item = list
.map((index, element) => {
const title = $('.work_name', element).text();
const link = $('.work_name > a', element).attr('href');
// 使链接
$('a', element).each((index, element) => {
$(element).attr('target', '_blank');
});
const description = $(element).html();
const arr = $('.search_tag', element);
const category = $('a', arr)
.map((index, a) => $(a).text())
.get();
const author = $('.maker_name', element).text();
const signle = {
title: title,
link: link,
description: description,
category: category,
author: author,
pubDate: pubDate,
};
return signle;
})
.get();
ctx.state.data = {
title: title,
link: link,
description: description,
language: 'ja-jp',
item: item,
};
};