forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Release Pixiv & SIS001 #1
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3abab79
add R18 novels for pixiv
keocheung e7d1e2e
add pixiv novel series
keocheung 1840079
update novels
keocheung 9b9f6dc
remove replacing jumpings
keocheung 4bf1781
add language tag
keocheung 3ed1969
add novel caption & tags
keocheung f9cd121
Merge branch 'DIYgod:master' into pixiv
keocheung dca9575
Merge branch 'DIYgod:master' into pixiv
keocheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import got from '../pixiv-got'; | ||
import { maskHeader } from '../constants'; | ||
import queryString from 'query-string'; | ||
|
||
export default function getNovelContent(id, token) { | ||
return got('https://app-api.pixiv.net/webview/v2/novel', { | ||
headers: { | ||
...maskHeader, | ||
Authorization: 'Bearer ' + token, | ||
}, | ||
searchParams: queryString.stringify({ | ||
id, | ||
}), | ||
}); | ||
} |
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,16 @@ | ||
import got from '../pixiv-got'; | ||
import { maskHeader } from '../constants'; | ||
import queryString from 'query-string'; | ||
|
||
export default function getNovelSeries(series_id, last_order, token) { | ||
return got('https://app-api.pixiv.net/v2/novel/series', { | ||
headers: { | ||
...maskHeader, | ||
Authorization: 'Bearer ' + token, | ||
}, | ||
searchParams: queryString.stringify({ | ||
series_id, | ||
last_order, | ||
}), | ||
}); | ||
} |
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,15 @@ | ||
import got from '../pixiv-got'; | ||
import { maskHeader } from '../constants'; | ||
import queryString from 'query-string'; | ||
|
||
export default function getUserNovels(user_id, token) { | ||
return got('https://app-api.pixiv.net/v1/user/novels', { | ||
headers: { | ||
...maskHeader, | ||
Authorization: 'Bearer ' + token, | ||
}, | ||
searchParams: queryString.stringify({ | ||
user_id, | ||
}), | ||
}); | ||
} |
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,102 @@ | ||
import { Route } from '@/types'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { config } from '@/config'; | ||
import cache from '@/utils/cache'; | ||
import { getToken } from './token'; | ||
import getNovelSeries from './api/get-novel-series'; | ||
import getNovelContent from './api/get-novel-content'; | ||
|
||
const baseUrl = 'https://www.pixiv.net'; | ||
const novelTextRe = /"text":"(.+?[^\\])"/; | ||
|
||
export const route: Route = { | ||
path: '/novel/series/:id/:lang?', | ||
categories: ['social-media'], | ||
example: '/pixiv/user/novels/1394738', | ||
parameters: { | ||
id: "Novel series id, available in novel series' homepage URL", | ||
lang: 'IETF BCP 47 language tag that helps RSS readers choose the right font', | ||
}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: { | ||
source: ['www.pixiv.net/novel/series/:id'], | ||
}, | ||
name: 'Novel Series', | ||
maintainers: ['keocheung'], | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
if (!config.pixiv || !config.pixiv.refreshToken) { | ||
throw new Error('pixiv RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>'); | ||
} | ||
|
||
const id = ctx.req.param('id'); | ||
let limit = Number.parseInt(ctx.req.query('limit')) || 10; | ||
if (limit > 30) { | ||
limit = 30; | ||
} | ||
const token = await getToken(cache.tryGet); | ||
if (!token) { | ||
throw new Error('pixiv not login'); | ||
} | ||
|
||
let novelSeriesResponse = await getNovelSeries(id, 0, token); | ||
const contentCount = Number.parseInt(novelSeriesResponse.data.novel_series_detail.content_count); | ||
if (contentCount > limit) { | ||
novelSeriesResponse = await getNovelSeries(id, contentCount - limit, token); | ||
} | ||
|
||
const novels = novelSeriesResponse.data.novels.reverse().map((novel) => { | ||
const tags = novel.tags.map((tag) => `<a href="${baseUrl}/tags/${tag.name}/novels">#${tag.name}</a>`).join('<span> </span>'); | ||
const item = { | ||
novelId: novel.id, | ||
novelCaption: tags, | ||
title: novel.title, | ||
author: novel.user.name, | ||
pubDate: parseDate(novel.create_date), | ||
link: `https://www.pixiv.net/novel/show.php?id=${novel.id}`, | ||
}; | ||
if (novel.caption) { | ||
item.novelCaption = `${novel.caption}<br><br>${tags}`; | ||
} | ||
return item; | ||
}); | ||
|
||
let langDivLeft = ''; | ||
let langDivRight = ''; | ||
const lang = ctx.req.param('lang'); | ||
if (lang) { | ||
langDivLeft = `<div lang="${lang}">`; | ||
langDivRight = '</div>'; | ||
} | ||
const items = await Promise.all( | ||
novels.map((novel) => | ||
cache.tryGet(novel.link, async () => { | ||
const content = await getNovelContent(novel.novelId, token); | ||
const rawText = novelTextRe.exec(content.data)[1]; | ||
novel.description = `${langDivLeft}<blockquote>${novel.novelCaption}</blockquote><p>${unescape(rawText.replaceAll('\\u', '%u'))}</p>${langDivRight}` | ||
.replaceAll('\\n', '</p><p>') | ||
Check failure Code scanning / ESLint Prefer using the `String.raw` tag to avoid escaping `\`. Error
String.raw should be used to avoid escaping \.
|
||
.replaceAll('\\t', '\t') | ||
Check failure Code scanning / ESLint Prefer using the `String.raw` tag to avoid escaping `\`. Error
String.raw should be used to avoid escaping \.
|
||
.replaceAll('\\', '') | ||
.replaceAll(/\[\[rb:(.+?) > (.+?)]]/g, '<ruby>$1<rp>(</rp><rt>$2</rt><rp>)</rp></ruby>') | ||
.replaceAll(/\[pixivimage:(\d+-\d+)]/g, `<p><img src="${config.pixiv.imgProxy}/$1.jpg"></p>`); | ||
return novel; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: novelSeriesResponse.data.novel_series_detail.title, | ||
link: `https://www.pixiv.net/novel/series/${id}`, | ||
description: novelSeriesResponse.data.novel_series_detail.caption, | ||
item: items, | ||
}; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / ESLint
Prefer using the `String.raw` tag to avoid escaping `\`. Error