| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -2,69 +2,64 @@ package io.legado.app.help | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					object RuleComplete { | 
					 | 
					 | 
					 | 
					object RuleComplete { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    // 需要补全 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    private val needComplete =Regex( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    """(?<!(@|/|^|[|%&]{2})(attr|text|ownText|textNodes|href|content|html|alt|all|value|src)(\(\))?)(?<seq>\&{2}|%%|\|{2}|$)""") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // 补全时忽略匹配规则 | 
					 | 
					 | 
					 | 
					    // 不能补全 存在js/json/{{xx}}的复杂情况 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val completeIgnore = | 
					 | 
					 | 
					 | 
					    private val notComplete = Regex("""^:|^##|\{\{|@js:|<js>|@Json:|\$\.""") | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Regex( | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            """\\n|##|@js:|<js>|@Json:|\$\.|(attr|text|ownText|textNodes|href|content|html|alt|all|value|src)(\(\)|##.*)?\s*$""", | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            RegexOption.MULTILINE | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        ) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // 补全时忽略匹配的规则(判断列表项和详情页预处理规则生效) | 
					 | 
					 | 
					 | 
					    // 修正从图片获取信息 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val completeIgnorePreRule = Regex("""^:|##|@js:|<js>|@Json:|\$\.""") | 
					 | 
					 | 
					 | 
					    private val fixImgInfo = Regex("""(?<=(^|tag\.|[\+/@>~| &]))img(?<at>\[@?.+\]|\.[-\w]+)?[@/]+text(\(\))?(?<seq>\&{2}|%%|\|{2}|$)""") | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // 匹配从图片获取信息的规则 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val imgComplete = Regex( | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        """(?<=(tag\.|[+/@~>| &]))img[@/]text(\(\))?$|^img[@/]text(\(\))?$""", | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        RegexOption.IGNORE_CASE | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    private val isXpath= Regex("^//|^@Xpath:") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * 对简单规则进行补全,简化部分书源规则的编写 | 
					 | 
					 | 
					 | 
					     * 对简单规则进行补全,简化部分书源规则的编写 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * 该方法仅对对JSOUP/XPath/CSS规则生效 | 
					 | 
					 | 
					 | 
					     * 对JSOUP/XPath/CSS规则生效 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @author 希弥 | 
					 | 
					 | 
					 | 
					     * @author 希弥 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @return 补全后的规则 或 原规则 | 
					 | 
					 | 
					 | 
					     * @return 补全后的规则 或 原规则 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @param rule 需要补全的规则 | 
					 | 
					 | 
					 | 
					     * @param rules 需要补全的规则 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @param preRule 预处理规则 | 
					 | 
					 | 
					 | 
					     * @param preRule 预处理规则或列表规则 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     *  用于分析详情页预处理规则 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @param type 补全结果的类型,可选的值有: | 
					 | 
					 | 
					 | 
					     * @param type 补全结果的类型,可选的值有: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     *  1 文字(默认) | 
					 | 
					 | 
					 | 
					     *  1 文字(默认) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     *  2 链接 | 
					 | 
					 | 
					 | 
					     *  2 链接 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     *  3 图片 | 
					 | 
					 | 
					 | 
					     *  3 图片 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun autoComplete( | 
					 | 
					 | 
					 | 
					    fun autoComplete( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        rule: String?, | 
					 | 
					 | 
					 | 
					        rules: String?, | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        preRule: String? = null, | 
					 | 
					 | 
					 | 
					        preRule: String? = null, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        type: Int = 1 | 
					 | 
					 | 
					 | 
					        type: Int = 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ): String? { | 
					 | 
					 | 
					 | 
					    ): String? { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (rule.isNullOrEmpty() || rule.contains(completeIgnore) | 
					 | 
					 | 
					 | 
					        if (rules.isNullOrEmpty()||rules.contains(notComplete) || preRule?.contains(notComplete) ?: false){ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            || preRule?.contains(completeIgnorePreRule) == true | 
					 | 
					 | 
					 | 
					            return rules | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        ) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return rule | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // 分离正则 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        val regexSplit=rules.split("##".toRegex(),2) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        val cleanedRule=regexSplit[0] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        val regexRule=if (regexSplit.size>1) "##"+regexSplit[1] else "" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val textRule: String | 
					 | 
					 | 
					 | 
					        val textRule: String | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val linkRule: String | 
					 | 
					 | 
					 | 
					        val linkRule: String | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val imgRule: String | 
					 | 
					 | 
					 | 
					        val imgRule: String | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val imgText: String | 
					 | 
					 | 
					 | 
					        val imgText: String | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (rule.contains(Regex("/[^@]+$"))) { | 
					 | 
					 | 
					 | 
					        if (cleanedRule.contains(isXpath)){ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            textRule = "/text()" | 
					 | 
					 | 
					 | 
					            textRule = "//text()\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            linkRule = "/@href" | 
					 | 
					 | 
					 | 
					            linkRule = "//@href\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            imgRule = "/@src" | 
					 | 
					 | 
					 | 
					            imgRule = "//@src\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            imgText = "img/@alt" | 
					 | 
					 | 
					 | 
					            imgText = "img\${at}/@alt\${seq}" | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					        } else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            textRule = "@text" | 
					 | 
					 | 
					 | 
					            textRule = "@text\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            linkRule = "@href" | 
					 | 
					 | 
					 | 
					            linkRule = "@href\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            imgRule = "@src" | 
					 | 
					 | 
					 | 
					            imgRule = "@src\${seq}" | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            imgText = "img@alt" | 
					 | 
					 | 
					 | 
					            imgText = "img\${at}@alt\${seq}" | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        var ret: String = rule | 
					 | 
					 | 
					 | 
					        return when (type) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        when (type) { | 
					 | 
					 | 
					 | 
					            1 -> needComplete.replace(cleanedRule, textRule).replace(fixImgInfo, imgText) + regexRule | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            1 -> ret = rule.replace(Regex("$"), textRule).replace(imgComplete, imgText) | 
					 | 
					 | 
					 | 
					            2 -> needComplete.replace(cleanedRule, linkRule) + regexRule | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            2 -> ret = rule.replace(Regex("$"), linkRule) | 
					 | 
					 | 
					 | 
					            3 -> needComplete.replace(cleanedRule, imgRule) + regexRule | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            3 -> ret = rule.replace(Regex("$"), imgRule) | 
					 | 
					 | 
					 | 
					            else -> rules | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return ret | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |