* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+189 -185
View File
@@ -1,219 +1,223 @@
import { load as parseHTML } from "cheerio";
import { fetchText, fetchFile } from "@libs/fetch";
import { FilterTypes, Filters } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from 'cheerio';
import { fetchText, fetchFile } from '@libs/fetch';
import { FilterTypes, Filters } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus';
class Shu69 implements Plugin.PluginBase {
id = "69shu";
name = "69书吧";
icon = "src/cn/69shu/icon.png";
site = "https://www.69shu.xyz";
version = "0.2.0";
id = '69shu';
name = '69书吧';
icon = 'src/cn/69shu/icon.png';
site = 'https://www.69shu.xyz';
version = '0.2.0';
async popularNovels(
pageNo: number,
{
showLatestNovels,
filters,
}: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> {
let url: string;
if (showLatestNovels) {
url = `${this.site}/rank/lastupdate/${pageNo}.html`;
} else if (filters.sort.value === 'none') {
url = `${this.site}/rank/${filters.rank.value}/${pageNo}.html`;
} else {
url = `${this.site}/sort/${filters.sort.value}/${pageNo}.html`;
}
const body = await fetchText(url);
if (body === '') throw Error('无法获取小说列表,请检查网络');
const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio('div.book-coverlist').each((i, el) => {
let url = loadedCheerio(el).find('a.cover').attr('href');
const novelName = loadedCheerio(el).find('h4.name').text().trim();
const novelCover = loadedCheerio(el).find('a.cover > img').attr('src');
if (!url) return;
const novel = {
name: novelName,
cover: novelCover,
path: url,
};
novels.push(novel);
});
return novels;
async popularNovels(
pageNo: number,
{
showLatestNovels,
filters,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url: string;
if (showLatestNovels) {
url = `${this.site}/rank/lastupdate/${pageNo}.html`;
} else if (filters.sort.value === 'none') {
url = `${this.site}/rank/${filters.rank.value}/${pageNo}.html`;
} else {
url = `${this.site}/sort/${filters.sort.value}/${pageNo}.html`;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const url = this.site + novelPath;
const body = await fetchText(url);
if (body === '') throw Error('无法获取小说列表,请检查网络');
const body = await fetchText(url);
if (body === '') throw Error('无法获取小说内容,请检查网络');
const loadedCheerio = parseHTML(body);
let loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
const novel: Plugin.SourceNovel = {
path: novelPath,
chapters: [],
name: loadedCheerio('h1').text().trim()
};
loadedCheerio('div.book-coverlist').each((i, el) => {
let url = loadedCheerio(el).find('a.cover').attr('href');
novel.cover = loadedCheerio('div.cover > img').attr('src');
const novelName = loadedCheerio(el).find('h4.name').text().trim();
const novelCover = loadedCheerio(el).find('a.cover > img').attr('src');
if (!url) return;
novel.summary = loadedCheerio('#bookIntro').text().trim();
const novel = {
name: novelName,
cover: novelCover,
path: url,
};
const bookInfo = loadedCheerio('div.caption-bookinfo > p')
novels.push(novel);
});
novel.author = bookInfo.find("a").attr('title');
return novels;
}
novel.artist = undefined;
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const url = this.site + novelPath;
novel.status = bookInfo.text().includes('连载') ? NovelStatus.Ongoing : NovelStatus.Completed;
const body = await fetchText(url);
if (body === '') throw Error('无法获取小说内容,请检查网络');
novel.genres = '';
let loadedCheerio = parseHTML(body);
// Table of Content is on a different page than the summary page
let chapters: Plugin.ChapterItem[] = [];
const allUrl = loadedCheerio('dd.all > a').attr('href')
if (allUrl) {
const chaptersUrl = this.site + allUrl;
const chaptersBody = await fetchText(chaptersUrl);
const chaptersLoadedCheerio = parseHTML(chaptersBody);
chaptersLoadedCheerio('dd').each((i, el) => {
const chapterUrl = chaptersLoadedCheerio(el).find('a').attr('href');
const chapterName = chaptersLoadedCheerio(el).find('a').text().trim();
if(chapterUrl){
chapters.push({
name: chapterName,
path: chapterUrl,
});
}
});
} else {
loadedCheerio('div.panel.hidden-xs > dl.panel-chapterlist:nth-child(2) > dd').each((i, el) => {
const chapterUrl = loadedCheerio(el).find('a').attr('href');
const chapterName = loadedCheerio(el).find('a').text().trim();
if(chapterUrl){
chapters.push({
name: chapterName,
path: chapterUrl,
});
}
});
}
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchText(this.site + chapterPath);
const loadedCheerio = parseHTML(body);
const chapterText = loadedCheerio('#chaptercontent p')
.map((i, el) => loadedCheerio(el).text())
.get()
// remove empty lines and 69shu ads
.map((line: string) => line.trim())
.filter((line: string) => line !== '' && !line.includes('69书吧'))
.map((line: string) => `<p>${line}</p>`)
.join('\n');
return chapterText;
const novel: Plugin.SourceNovel = {
path: novelPath,
chapters: [],
name: loadedCheerio('h1').text().trim(),
};
async searchNovels(
searchTerm: string,
pageNo: number
): Promise<Plugin.NovelItem[]> {
if (pageNo > 1) return [];
novel.cover = loadedCheerio('div.cover > img').attr('src');
const searchUrl = `${this.site}/search`;
const formData = new FormData();
formData.append('searchkey', searchTerm);
novel.summary = loadedCheerio('#bookIntro').text().trim();
const body = await fetchText(searchUrl, {
method: 'post',
body: formData,
});
if (body === '') throw Error('无法获取搜索结果,请检查网络');
const bookInfo = loadedCheerio('div.caption-bookinfo > p');
let loadedCheerio = parseHTML(body);
novel.author = bookInfo.find('a').attr('title');
const novels: Plugin.NovelItem[] = [];
novel.artist = undefined;
loadedCheerio('div.book-coverlist').each((i, el) => {
let url = loadedCheerio(el).find('a.cover').attr('href');
novel.status = bookInfo.text().includes('连载')
? NovelStatus.Ongoing
: NovelStatus.Completed;
const novelName = loadedCheerio(el).find('h4.name').text().trim();
const novelCover = loadedCheerio(el).find('a.cover > img').attr('src');
novel.genres = '';
if (!url) return;
// Table of Content is on a different page than the summary page
let chapters: Plugin.ChapterItem[] = [];
const novel = {
name: novelName,
cover: novelCover,
path: url,
};
const allUrl = loadedCheerio('dd.all > a').attr('href');
if (allUrl) {
const chaptersUrl = this.site + allUrl;
const chaptersBody = await fetchText(chaptersUrl);
novels.push(novel);
});
const chaptersLoadedCheerio = parseHTML(chaptersBody);
return novels;
chaptersLoadedCheerio('dd').each((i, el) => {
const chapterUrl = chaptersLoadedCheerio(el).find('a').attr('href');
const chapterName = chaptersLoadedCheerio(el).find('a').text().trim();
if (chapterUrl) {
chapters.push({
name: chapterName,
path: chapterUrl,
});
}
});
} else {
loadedCheerio(
'div.panel.hidden-xs > dl.panel-chapterlist:nth-child(2) > dd',
).each((i, el) => {
const chapterUrl = loadedCheerio(el).find('a').attr('href');
const chapterName = loadedCheerio(el).find('a').text().trim();
if (chapterUrl) {
chapters.push({
name: chapterName,
path: chapterUrl,
});
}
});
}
fetchImage = fetchFile;
novel.chapters = chapters;
filters = {
rank: {
label: "排行榜",
value: "allvisit",
options: [
{ label: "总排行榜", value: "allvisit" },
{ label: "月排行榜", value: "monthvisit" },
{ label: "周排行榜", value: "weekvisit" },
{ label: "日排行榜", value: "dayvisit" },
{ label: "收藏榜", value: "goodnum" },
{ label: "字数榜", value: "words" },
{ label: "推荐榜", value: "allvote" },
{ label: "新书榜", value: "postdate" },
{ label: "更新榜", value: "lastupdate" },
],
type: FilterTypes.Picker,
},
sort: {
label: "分类",
value: "none",
options: [
{ label: "无", value: "none" },
{ label: "全部", value: "all" },
{ label: "玄幻", value: "xuanhuan" },
{ label: "仙侠", value: "xianxia" },
{ label: "都市", value: "dushi" },
{ label: "历史", value: "lishi" },
{ label: "游戏", value: "youxi" },
{ label: "科幻", value: "kehuan" },
{ label: "灵异", value: "kongbu" },
{ label: "言情", value: "nvsheng" },
{ label: "其它", value: "qita" },
],
type: FilterTypes.Picker,
}
} satisfies Filters;
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchText(this.site + chapterPath);
const loadedCheerio = parseHTML(body);
const chapterText = loadedCheerio('#chaptercontent p')
.map((i, el) => loadedCheerio(el).text())
.get()
// remove empty lines and 69shu ads
.map((line: string) => line.trim())
.filter((line: string) => line !== '' && !line.includes('69书吧'))
.map((line: string) => `<p>${line}</p>`)
.join('\n');
return chapterText;
}
async searchNovels(
searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
if (pageNo > 1) return [];
const searchUrl = `${this.site}/search`;
const formData = new FormData();
formData.append('searchkey', searchTerm);
const body = await fetchText(searchUrl, {
method: 'post',
body: formData,
});
if (body === '') throw Error('无法获取搜索结果,请检查网络');
let loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio('div.book-coverlist').each((i, el) => {
let url = loadedCheerio(el).find('a.cover').attr('href');
const novelName = loadedCheerio(el).find('h4.name').text().trim();
const novelCover = loadedCheerio(el).find('a.cover > img').attr('src');
if (!url) return;
const novel = {
name: novelName,
cover: novelCover,
path: url,
};
novels.push(novel);
});
return novels;
}
fetchImage = fetchFile;
filters = {
rank: {
label: '排行榜',
value: 'allvisit',
options: [
{ label: '总排行榜', value: 'allvisit' },
{ label: '月排行榜', value: 'monthvisit' },
{ label: '周排行榜', value: 'weekvisit' },
{ label: '日排行榜', value: 'dayvisit' },
{ label: '收藏榜', value: 'goodnum' },
{ label: '字数榜', value: 'words' },
{ label: '推荐榜', value: 'allvote' },
{ label: '新书榜', value: 'postdate' },
{ label: '更新榜', value: 'lastupdate' },
],
type: FilterTypes.Picker,
},
sort: {
label: '分类',
value: 'none',
options: [
{ label: '无', value: 'none' },
{ label: '全部', value: 'all' },
{ label: '玄幻', value: 'xuanhuan' },
{ label: '仙侠', value: 'xianxia' },
{ label: '都市', value: 'dushi' },
{ label: '历史', value: 'lishi' },
{ label: '游戏', value: 'youxi' },
{ label: '科幻', value: 'kehuan' },
{ label: '灵异', value: 'kongbu' },
{ label: '言情', value: 'nvsheng' },
{ label: '其它', value: 'qita' },
],
type: FilterTypes.Picker,
},
} satisfies Filters;
}
export default new Shu69();
+184 -173
View File
@@ -1,199 +1,210 @@
import { load as parseHTML } from "cheerio";
import { fetchText, fetchFile } from "@libs/fetch";
import { FilterTypes, Filters } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { encode } from "urlencode";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from 'cheerio';
import { fetchText, fetchFile } from '@libs/fetch';
import { FilterTypes, Filters } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { encode } from 'urlencode';
import { NovelStatus } from '@libs/novelStatus';
class XinShu69 implements Plugin.PluginBase {
id = "69xinshu";
name = "69书吧";
icon = "src/cn/69xinshu/icon.png";
site = "https://www.69shu.pro";
version = "0.1.1";
id = '69xinshu';
name = '69书吧';
icon = 'src/cn/69xinshu/icon.png';
site = 'https://www.69shu.pro';
version = '0.1.1';
async popularNovels(
pageNo: number,
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> {
let url: string;
if (pageNo === 1) {
url = `${this.site}/novels/class/${filters.class.value}.htm`;
} else {
url = `${this.site}/ajax_novels/class/${filters.class.value}/${pageNo}.htm`;
}
const body = await fetchText(url, {}, 'gbk');
if (body === '') throw Error('无法获取小说列表,请检查网络');
const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
const novelsList = pageNo === 1 ? loadedCheerio('div.newbox > ul > li') : loadedCheerio('li');
novelsList.each((i, e) => {
const novelUrl = loadedCheerio(e).find('li > div > h3 > a:nth-child(2)').attr('href');
if (novelUrl) {
const novelName = loadedCheerio(e).find('li > div > h3 > a:nth-child(2)').text();
const novelCover = loadedCheerio(e)
.find('li > a > img')
.attr('data-src');
const novel = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ''),
};
novels.push(novel);
}
});
return novels;
async popularNovels(
pageNo: number,
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url: string;
if (pageNo === 1) {
url = `${this.site}/novels/class/${filters.class.value}.htm`;
} else {
url = `${this.site}/ajax_novels/class/${filters.class.value}/${pageNo}.htm`;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const url = this.site + novelPath;
const body = await fetchText(url, {}, 'gbk');
if (body === '') throw Error('无法获取小说列表,请检查网络');
const body = await fetchText(url, {}, 'gbk');
if (body === '') throw Error('无法获取小说内容,请检查网络');
const loadedCheerio = parseHTML(body);
let loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
const novel: Plugin.SourceNovel = {
path: novelPath,
chapters: [],
name: loadedCheerio('h1 > a').text()
const novelsList =
pageNo === 1
? loadedCheerio('div.newbox > ul > li')
: loadedCheerio('li');
novelsList.each((i, e) => {
const novelUrl = loadedCheerio(e)
.find('li > div > h3 > a:nth-child(2)')
.attr('href');
if (novelUrl) {
const novelName = loadedCheerio(e)
.find('li > div > h3 > a:nth-child(2)')
.text();
const novelCover = loadedCheerio(e)
.find('li > a > img')
.attr('data-src');
const novel = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ''),
};
novel.cover = loadedCheerio('div.bookimg2 > img').attr(
'src',
);
novels.push(novel);
}
});
novel.summary = loadedCheerio('div.navtxt').text().trim();
return novels;
}
const bookInfo = loadedCheerio('div.booknav2').text()
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const url = this.site + novelPath;
const authorMatch = bookInfo.match(/作者:(.*)/);
if (authorMatch) {
novel.author = authorMatch[1];
}
const body = await fetchText(url, {}, 'gbk');
if (body === '') throw Error('无法获取小说内容,请检查网络');
novel.artist = undefined;
let loadedCheerio = parseHTML(body);
novel.status = bookInfo.includes('连载') ? NovelStatus.Ongoing : NovelStatus.Completed;
const genresMatch = bookInfo.match(/分类:(.*)/);
if (genresMatch) {
novel.genres = genresMatch[1];
}
// Table of Content is on a different page than the summary page
let chapters: Plugin.ChapterItem[] = [];
const chaptersUrl = loadedCheerio('a.more-btn').attr('href');
if (chaptersUrl) {
const chaptersBody = await fetchText(chaptersUrl, {}, 'gbk');
const chaptersLoadedCheerio = parseHTML(chaptersBody);
chaptersLoadedCheerio('li').each((i, e) => {
const chapterUrl = chaptersLoadedCheerio(e).find('a').attr('href');
if (chapterUrl?.startsWith("https://")) {
const chapterName = chaptersLoadedCheerio(e).find('a').text().trim();
chapters.push({
name: chapterName,
path: chapterUrl.replace(this.site, ''),
});
}
});
}
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchText(this.site + chapterPath, {}, 'gbk');
const loadedCheerio = parseHTML(body);
const chapterText = (loadedCheerio('div.txtnav').prop('innerText') ?? '')
.split('\n')
// remove empty lines
.map((line: string) => line.trim())
.filter((line: string) => line !== '')
// remove the first two lines which are the chapter name and author name
.slice(2)
.map((line: string) => `<p>${line}</p>`)
.join('\n');
return chapterText;
const novel: Plugin.SourceNovel = {
path: novelPath,
chapters: [],
name: loadedCheerio('h1 > a').text(),
};
async searchNovels(
searchTerm: string,
pageNo: number
): Promise<Plugin.NovelItem[]> {
if (pageNo > 1) return [];
novel.cover = loadedCheerio('div.bookimg2 > img').attr('src');
const searchUrl = `${this.site}/modules/article/search.php`;
const formData = new FormData();
formData.append('searchkey', encode(searchTerm, 'gbk'));
formData.append('searchtype', 'all');
novel.summary = loadedCheerio('div.navtxt').text().trim();
const body = await fetchText(searchUrl, { method: 'post', body: formData, }, 'gbk');
if (body === '') throw Error('无法获取搜索结果,请检查网络');
const bookInfo = loadedCheerio('div.booknav2').text();
let loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio('div.newbox > ul > li').each((i, e) => {
const novelUrl = loadedCheerio(e).find('a').attr('href')!;
const novelName = loadedCheerio(e).find('div.newnav > h3').text();
const novelCover = loadedCheerio(e).find('img').attr('data-src');
const novel = {
name: novelName,
path: novelUrl.replace(this.site, ''),
cover: novelCover,
};
novels.push(novel);
});
return novels;
const authorMatch = bookInfo.match(/作者:(.*)/);
if (authorMatch) {
novel.author = authorMatch[1];
}
fetchImage = fetchFile;
novel.artist = undefined;
filters = {
class: {
label: "分类",
value: "0",
options: [
{ label: "全部分类", value: "0" },
{ label: "言情小说", value: "3" },
{ label: "玄幻魔法", value: "1" },
{ label: "修真武侠", value: "2" },
{ label: "穿越时空", value: "11" },
{ label: "都市小说", value: "9" },
{ label: "历史军事", value: "4" },
{ label: "游戏竞技", value: "5" },
{ label: "科幻空间", value: "6" },
{ label: "悬疑惊悚", value: "7" },
{ label: "同人小说", value: "8" },
{ label: "官场职场", value: "10" },
{ label: "青春校园", value: "12" },
],
type: FilterTypes.Picker,
},
} satisfies Filters;
novel.status = bookInfo.includes('连载')
? NovelStatus.Ongoing
: NovelStatus.Completed;
const genresMatch = bookInfo.match(/分类:(.*)/);
if (genresMatch) {
novel.genres = genresMatch[1];
}
// Table of Content is on a different page than the summary page
let chapters: Plugin.ChapterItem[] = [];
const chaptersUrl = loadedCheerio('a.more-btn').attr('href');
if (chaptersUrl) {
const chaptersBody = await fetchText(chaptersUrl, {}, 'gbk');
const chaptersLoadedCheerio = parseHTML(chaptersBody);
chaptersLoadedCheerio('li').each((i, e) => {
const chapterUrl = chaptersLoadedCheerio(e).find('a').attr('href');
if (chapterUrl?.startsWith('https://')) {
const chapterName = chaptersLoadedCheerio(e).find('a').text().trim();
chapters.push({
name: chapterName,
path: chapterUrl.replace(this.site, ''),
});
}
});
}
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchText(this.site + chapterPath, {}, 'gbk');
const loadedCheerio = parseHTML(body);
const chapterText = (loadedCheerio('div.txtnav').prop('innerText') ?? '')
.split('\n')
// remove empty lines
.map((line: string) => line.trim())
.filter((line: string) => line !== '')
// remove the first two lines which are the chapter name and author name
.slice(2)
.map((line: string) => `<p>${line}</p>`)
.join('\n');
return chapterText;
}
async searchNovels(
searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
if (pageNo > 1) return [];
const searchUrl = `${this.site}/modules/article/search.php`;
const formData = new FormData();
formData.append('searchkey', encode(searchTerm, 'gbk'));
formData.append('searchtype', 'all');
const body = await fetchText(
searchUrl,
{ method: 'post', body: formData },
'gbk',
);
if (body === '') throw Error('无法获取搜索结果,请检查网络');
let loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio('div.newbox > ul > li').each((i, e) => {
const novelUrl = loadedCheerio(e).find('a').attr('href')!;
const novelName = loadedCheerio(e).find('div.newnav > h3').text();
const novelCover = loadedCheerio(e).find('img').attr('data-src');
const novel = {
name: novelName,
path: novelUrl.replace(this.site, ''),
cover: novelCover,
};
novels.push(novel);
});
return novels;
}
fetchImage = fetchFile;
filters = {
class: {
label: '分类',
value: '0',
options: [
{ label: '全部分类', value: '0' },
{ label: '言情小说', value: '3' },
{ label: '玄幻魔法', value: '1' },
{ label: '修真武侠', value: '2' },
{ label: '穿越时空', value: '11' },
{ label: '都市小说', value: '9' },
{ label: '历史军事', value: '4' },
{ label: '游戏竞技', value: '5' },
{ label: '科幻空间', value: '6' },
{ label: '悬疑惊悚', value: '7' },
{ label: '同人小说', value: '8' },
{ label: '官场职场', value: '10' },
{ label: '青春校园', value: '12' },
],
type: FilterTypes.Picker,
},
} satisfies Filters;
}
export default new XinShu69();
File diff suppressed because it is too large Load Diff