forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 18comic (DIYgod#8588)
- Loading branch information
Ethan Shen
authored
Nov 27, 2021
1 parent
02fda1c
commit 4ba85ef
Showing
9 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const { rootUrl } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const id = ctx.params.id; | ||
|
||
const currentUrl = `${rootUrl}/album/${id}`; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
const category = $('span[data-type="tags"]') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((c) => $(c).text()); | ||
const author = $('span[data-type="author"]') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((a) => $(a).text()) | ||
.join(', '); | ||
|
||
let items = $('.btn-toolbar') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.text(), | ||
link: `${rootUrl}${item.attr('href')}`, | ||
pubDate: parseDate(item.find('.hidden-xs').text()), | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
const content = cheerio.load(detailResponse.data); | ||
|
||
content('.tab-content').remove(); | ||
|
||
item.author = author; | ||
item.category = category; | ||
item.description = `<img src="${content('.thumb-overlay-albums img[data-original]') | ||
.toArray() | ||
.map((image) => content(image).attr('data-original')) | ||
.join('"><img src="')}">`; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('title').text(), | ||
link: currentUrl, | ||
item: items, | ||
description: $('meta[property="og:description"]').attr('content'), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const { rootUrl } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category ?? ''; | ||
|
||
const currentUrl = `${rootUrl}/blogs${category ? `/${category}` : ''}`; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
let items = $('.title') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.text(), | ||
link: `${rootUrl}${item.parent().attr('href')}`, | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.pubDate = parseDate(content('.date').first().text()); | ||
|
||
content('.d-flex').remove(); | ||
|
||
item.author = content('.blog_name_id').first().text(); | ||
item.description = content('.blog_content').html(); | ||
item.category = content('.panel-heading dropdown-toggle') | ||
.toArray() | ||
.map((c) => $(c).text()); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('title').text().replace(/最新的/, $('.article-nav .active').text()), | ||
link: currentUrl, | ||
item: items, | ||
description: $('meta[property="og:description"]').attr('content'), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { rootUrl, ProcessItems } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category ?? 'all'; | ||
const keyword = ctx.params.keyword ?? ''; | ||
const time = ctx.params.time ?? 'a'; | ||
const order = ctx.params.order ?? 'mr'; | ||
|
||
const currentUrl = `${rootUrl}/albums${category !== 'all' ? `/${category}` : ''}${keyword ? `?screen=${keyword}` : '?'}${time !== 'a' ? `&t=${time}` : ''}${order !== 'mr' ? `&o=${order}` : ''}`; | ||
|
||
ctx.state.data = await ProcessItems(ctx, currentUrl); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
'/album/:id': ['nczitzk'], | ||
'/blogs/:category?': ['nczitzk'], | ||
'/search/:option?/:category?/:time?/:order?/:keyword?': ['nczitzk'], | ||
'/:category?/:time?/:order?/:keyword?': ['nczitzk'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
'18comic.org': { | ||
_name: '18comic 禁漫天堂', | ||
'.': [ | ||
{ | ||
title: '成人 A 漫', | ||
docs: 'https://docs.rsshub.app/anime.html#18comic-jin-man-tian-tang-cheng-ren-a-man', | ||
source: ['/'], | ||
target: '/18comic/:category?/:time?/:order?/:keyword?', | ||
}, | ||
{ | ||
title: '搜索', | ||
docs: 'https://docs.rsshub.app/anime.html#18comic-jin-man-tian-tang-sou-suo', | ||
source: ['/'], | ||
target: '/18comic/search/:option?/:category?:keyword?/:time?/:order?', | ||
}, | ||
{ | ||
title: '专辑', | ||
docs: 'https://docs.rsshub.app/anime.html#18comic-jin-man-tian-tang-zhuan-ji', | ||
source: ['/'], | ||
target: '/18comic/album/:id', | ||
}, | ||
{ | ||
title: '文庫', | ||
docs: 'https://docs.rsshub.app/anime.html#18comic-jin-man-tian-tang-wen-ku', | ||
source: ['/'], | ||
target: '/18comic/blogs/:category?', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function (router) { | ||
router.get('/album/:id', require('./album')); | ||
router.get('/blogs/:category?', require('./blogs')); | ||
router.get('/search/:option?/:category?/:keyword?/:time?/:order?', require('./search')); | ||
router.get('/:category?/:time?/:order?/:keyword?', require('./index')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { rootUrl, ProcessItems } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const option = ctx.params.option ?? 'photos'; | ||
const category = ctx.params.category ?? 'all'; | ||
const keyword = ctx.params.keyword ?? ''; | ||
const time = ctx.params.time ?? 'a'; | ||
const order = ctx.params.order ?? 'mr'; | ||
|
||
const currentUrl = `${rootUrl}/search/${option}${category !== 'all' ? `/${category}` : ''}${keyword ? `?search_query=${keyword}` : '?'}${time !== 'a' ? `&t=${time}` : ''}${order !== 'mr' ? `&o=${order}` : ''}`; | ||
|
||
ctx.state.data = await ProcessItems(ctx, currentUrl); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const rootUrl = 'https://18comic.org'; | ||
|
||
module.exports = { | ||
rootUrl, | ||
ProcessItems: async (ctx, currentUrl) => { | ||
currentUrl = currentUrl.replace(/\?$/, ''); | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
let items = $('.video-title') | ||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.text().trim(), | ||
link: `${rootUrl}${item.prev().prev().attr('href')}`, | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.pubDate = parseDate(content('div[itemprop="datePublished"]').first().attr('content')); | ||
item.category = content('span[data-type="tags"]') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((c) => $(c).text()); | ||
item.author = content('span[data-type="author"]') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((a) => $(a).text()) | ||
.join(', '); | ||
item.description = `<p>${content('#intro-block .p-t-5').text()}</p><img src="${content('.img_zoom_img img') | ||
.toArray() | ||
.map((image) => content(image).attr('src')) | ||
.join('"><img src="')}">`; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: $('title').text(), | ||
link: currentUrl, | ||
item: items, | ||
description: $('meta[property="og:description"]').attr('content'), | ||
allowEmpty: true, | ||
}; | ||
}, | ||
}; |