0.2.0 • Published 1 month ago

@any-reader/core v0.2.0

Weekly downloads
-
License
GPL3
Repository
-
Last release
1 month ago

any-reader

npm version bundle JSDocs

阅读规则解析库,目前支持少量eso 书源规则

使用

npm install @any-reader/core
import { RuleManager, decodeRule } from '@any-reader/core';

const ruleManager = new RuleManager(rule: Rule);
ruleManager.search(keyword: string): SearchItem[]; // 搜索
ruleManager.getChapter(url: string): ChapterItem[]; // 获取章节列表
ruleManager.getContent(url: string): string[]; // 获取内容

decodeRule("eso://") // 可以解码 eso 书源, 得到原始 json

书源规则

可以参考eso

书源结构

export interface Rule {
  host: string; // 根域名
  searchUrl: string; // 搜索地址
  searchList: string; // 搜索列表
  searchCover: string; // 封面
  searchName: string; // 标题
  searchAuthor: string; // 作者
  searchChapter: string; // 章节
  searchDescription: string; // 描述
  searchResult: string; // 搜索结果
  chapterUrl: string; // 章节地址
  chapterName: string; // 标题
  chapterList: string; // 列表
  chapterCover: string; // 封面
  chapterTime: string; // 时间
  chapterResult: string; // 结果
  contentItems: string; // 内容
  id: string; // uuid
  name: string; // 书源名称
  sort: number; // 书源排序
  contentType: ContentType; // 书源类型
  cookies: string;
}

enum ContentType {
  MANGA = 0,
  NOVEL = 1,
  VIDEO = 2,
  AUDIO = 3,
  RSS = 4,
  NOVELMORE = 5,
}

规则支持情况

  • ✅ 理论支持
  • ⚠️ 支持部分
  • ❌ 理论不支持
  • 🚧 开发中

URL 规则

特性支持情况示例
URLhttps://xxx.com/search?q=$keyword&pageSize=10
JSON⚠️{"url":"https://xxx.com/search","method":"post","headers":{"token":"111"},"body":{"keyword":"$keyword"}}
@js⚠️@js:(() => { return {url, method, body, encoding, headers}; })();
编码

变量

字段名支持情况说明
$keyword搜索用的关键字
searchKey$keyword
$host替换规则的 host
$result
lastResult⚠️
searchPage
$page
$pageSize

结果规则会成为下一条地址规则的 result,成为下一条除地址规则的 lastResult。地址规则的响应会成为其他规则的 result

取内容规则

特性支持情况说明示例
@css@css:.box1 .box2@text
@json@json:$.list[:1].title
@xpath@xpath://*[@class="box3"]/text()
@js⚠️
@filter⚠️模拟浏览器加载地址后匹配指定链接@filter:(?:m3u8\|mp4)(?:$\|/\|\\?\|&)
@replace⚠️@replace:.*?url=\|.*?v=
##⚠️正则替换@css:.c2 a@href##\\d+\\.html
{{}}⚠️拼接http://www.aaa.com/{{$.id}}
嵌套\&组合⚠️$.info.body@css:.box1 .box2@text
||

规则可以省略开头的,@css@xpath@json, 因为解析器会尝试自动识别。

开发和调试

  1. 修改 src\start.ts 文件, 把 rule 变量修改为真实的书源
  2. vscode 打开调试终端, 输入 npm run start

喜欢的话可以点个 Star

0.1.0-alpha.5

2 months ago

0.2.0

1 month ago

0.1.0-alpha.3

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.1.0-alpha.1

4 months ago

0.1.0-alpha.2

4 months ago

0.0.1-alpha.6

4 months ago

0.0.1-alpha.5

4 months ago

0.0.1-alpha.4

4 months ago

0.0.1-alpha.3

4 months ago

0.0.1-alpha.2

4 months ago

0.0.1-alpha.1

4 months ago