]*class=\"[^\"]*version( name)?[^\"]*\"[^>]*>\s*
]*>([^<]+)""", RegexOption.IGNORE_CASE),
73 | Regex("""
]*class=\"[^\"]*vername[^\"]*\"[^>]*>([^<]+)""", RegexOption.IGNORE_CASE)
74 | )
75 | for (p in patterns) {
76 | val m = p.find(html)
77 | if (m != null) {
78 | val idx = if (m.groupValues.size >= 3) 2 else 1
79 | return m.groupValues[idx].trim()
80 | }
81 | }
82 | return ""
83 | }
84 |
85 | internal fun extractVersionCode(html: String): String {
86 | val p = Regex("""
]*class=\"[^\"]*vercode[^\"]*\"[^>]*>\(([^)]+)\)""", RegexOption.IGNORE_CASE)
87 | return p.find(html)?.groupValues?.get(1)?.trim().orEmpty()
88 | }
89 |
90 | // Fallbacks: extract versionCode from variant blocks or URLs
91 | internal fun extractVersionCodeFallback(html: String): String {
92 | val patterns = listOf(
93 | // Variant info-top line like:
(1030640)
94 | Regex("""
]*class=\"[^\"]*code[^\"]*\"[^>]*>\\(([^)]+)\\)""", RegexOption.IGNORE_CASE),
95 | // Download button href: https://d.apkpure.com/b/XAPK/com.package?versionCode=1030640
96 | Regex("href=\"[^\"]*versionCode=([0-9]+)[^\"]*\""),
97 | // Data attribute variant code, sometimes plain number inside span
98 | Regex("""\(\s*([0-9]{3,})\s*\)""")
99 | )
100 | for (p in patterns) {
101 | val m = p.find(html)
102 | if (m != null) return m.groupValues[1].trim()
103 | }
104 | return ""
105 | }
106 |
107 | // Extract signature from More App Info section or variant dialog
108 | internal fun extractSignature(html: String): String {
109 | val patterns = listOf(
110 | // More App Info list item:
Signature
35b4...
111 | Regex("""Signature
\s*