基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat(rules): build API search detail URLs from bare ids (#2693)
JesseLeeff8594727d9d
diff --git a/lib/pages/plugin_editor/plugin_editor_page.dart b/lib/pages/plugin_editor/plugin_editor_page.dartindex 276b4a83..d7628346 100644--- a/lib/pages/plugin_editor/plugin_editor_page.dart+++ b/lib/pages/plugin_editor/plugin_editor_page.dart@@ -91,6 +91,8 @@ abstract final class _RuleEditorText {static const searchListPath = '搜索结果列表路径(JSONPath)';static const itemNamePath = '条目名称路径(JSONPath,相对条目)';static const itemSourcePath = '条目来源路径(JSONPath,相对条目)';+ static const detailPageUrl = '详情页地址模板(URL,可选)';+ static const detailPageUrlHelper = '@source 替换为条目来源,如 https://site/GV@source';static const chapterMethod = '选集请求方法';static const chapterRequestUrl = '选集请求地址(URL)';@@ -181,6 +183,8 @@ class _PluginEditorPageState extends State<PluginEditorPage> {TextEditingController();final TextEditingController searchApiSourcePathController =TextEditingController();+ final TextEditingController searchApiSourceTemplateController =+ TextEditingController();final TextEditingController chapterApiURLController = TextEditingController();final TextEditingController chapterApiHeadersController =TextEditingController();@@ -300,6 +304,8 @@ class _PluginEditorPageState extends State<PluginEditorPage> {searchApiListPathController.text = plugin.searchApiConfig.listPath;searchApiNamePathController.text = plugin.searchApiConfig.namePath;searchApiSourcePathController.text = plugin.searchApiConfig.sourcePath;+ searchApiSourceTemplateController.text =+ plugin.searchApiConfig.sourceTemplate;chapterApiMethod = plugin.chapterApiConfig.request.method;chapterApiBodyType = plugin.chapterApiConfig.request.bodyType;chapterApiFormat = plugin.chapterApiConfig.format;@@ -373,6 +379,7 @@ class _PluginEditorPageState extends State<PluginEditorPage> {searchApiListPathController.dispose();searchApiNamePathController.dispose();searchApiSourcePathController.dispose();+ searchApiSourceTemplateController.dispose();chapterApiURLController.dispose();chapterApiHeadersController.dispose();chapterApiQueryController.dispose();@@ -843,6 +850,11 @@ class _PluginEditorPageState extends State<PluginEditorPage> {controller: searchApiSourcePathController,label: _RuleEditorText.itemSourcePath,),+ EditorTextField(+ controller: searchApiSourceTemplateController,+ label: _RuleEditorText.detailPageUrl,+ helper: _RuleEditorText.detailPageUrlHelper,+ ),];List<Widget> _buildApiChapterFields() => [@@ -1035,6 +1047,7 @@ class _PluginEditorPageState extends State<PluginEditorPage> {listPath: valueOf(searchApiListPathController),namePath: valueOf(searchApiNamePathController),sourcePath: valueOf(searchApiSourcePathController),+ sourceTemplate: valueOf(searchApiSourceTemplateController),);if (!shouldValidate) return config;if (config.request.url.isEmpty) {diff --git a/lib/plugins/api_rule_config.dart b/lib/plugins/api_rule_config.dartindex 4267ae86..3f47f8e2 100644--- a/lib/plugins/api_rule_config.dart+++ b/lib/plugins/api_rule_config.dart@@ -75,12 +75,17 @@ class ApiSearchConfig {String namePath;String sourcePath;+ /// Detail page URL built by replacing `@source`; empty keeps the raw value.+ final String sourceTemplate;+ApiSearchConfig({ApiRequestConfig? request,this.listPath = r'$.data[*]',this.namePath = r'$.name',this.sourcePath = r'$.url',- }) : request = request ?? ApiRequestConfig();+ String sourceTemplate = '',+ }) : request = request ?? ApiRequestConfig(),+ sourceTemplate = sourceTemplate.trim();factory ApiSearchConfig.fromJson(Map<String, dynamic> json) {return ApiSearchConfig(@@ -88,6 +93,7 @@ class ApiSearchConfig {listPath: json['listPath'] as String? ?? r'$.data[*]',namePath: json['namePath'] as String? ?? r'$.name',sourcePath: json['sourcePath'] as String? ?? r'$.url',+ sourceTemplate: json['sourceTemplate'] as String? ?? '',);}@@ -96,6 +102,7 @@ class ApiSearchConfig {'listPath': listPath,'namePath': namePath,'sourcePath': sourcePath,+ if (sourceTemplate.isNotEmpty) 'sourceTemplate': sourceTemplate,};}diff --git a/lib/request/config/api_endpoints.dart b/lib/request/config/api_endpoints.dartindex 0f2e8740..dac75ea0 100644--- a/lib/request/config/api_endpoints.dart+++ b/lib/request/config/api_endpoints.dart@@ -5,7 +5,7 @@ class ApiEndpoints {static const String version = appBuildName ?? '0.0.0';/// 规则API级别- static const int apiLevel = 8;+ static const int apiLevel = 9;/// 项目主页static const String projectUrl = "https://kazumi.app/";diff --git a/lib/services/plugin/api_rule_strategy.dart b/lib/services/plugin/api_rule_strategy.dartindex 123df626..86387cf5 100644--- a/lib/services/plugin/api_rule_strategy.dart+++ b/lib/services/plugin/api_rule_strategy.dart@@ -143,12 +143,17 @@ class ApiRuleStrategy {RestrictedJsonPath.validate(config.listPath);RestrictedJsonPath.validate(config.namePath);RestrictedJsonPath.validate(config.sourcePath);+ final template = config.sourceTemplate;+ if (template.isNotEmpty && !template.contains('@source')) {+ throw const ApiRuleFormatException('详情页地址模板必须引用 @source');+ }}RuleSearchParseResult parseSearch(String raw, ApiSearchConfig config) {validateSearchConfig(config);final document = decodeResponse(raw);final nodes = RestrictedJsonPath.read(document, config.listPath);+ final template = config.sourceTemplate;final results = <SearchItem>[];final fragments = <String>[];final diagnostics = <String>[];@@ -165,7 +170,11 @@ class ApiRuleStrategy {diagnostics.add('搜索节点 $index 缺少名称或来源,已跳过');continue;}- results.add(SearchItem(name: name, src: source));+ // Plain replacement so @source may follow a letter (`/GV@source`).+ final src = template.isEmpty+ ? source+ : template.replaceAll('@source', Uri.encodeComponent(source));+ results.add(SearchItem(name: name, src: src));fragments.add(jsonEncode(node));} on ApiRuleFormatException {rethrow;