Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f61d65c526 | ||
|
|
a2359b9dd2 | ||
|
|
8bea19d334 | ||
|
|
ebbed5ed82 | ||
|
|
8963fa5c6d | ||
|
|
d55d41f610 | ||
|
|
a2de5d2275 | ||
|
|
4ac4b7dd78 | ||
|
|
eb6f8e2398 | ||
|
|
455c20fb93 | ||
|
|
b23b53d417 | ||
|
|
6a59ae5e99 | ||
|
|
ff69bfb82c | ||
|
|
f68536009d | ||
|
|
32acd3fa4b | ||
|
|
528675d3b5 | ||
|
|
9a078a24d1 | ||
|
|
39913c6453 | ||
|
|
0306ff8bf7 | ||
|
|
c147f8e805 | ||
|
|
bcca999646 | ||
|
|
966ecd9196 | ||
|
|
682856c961 |
@@ -17,6 +17,8 @@
|
|||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
|
<!-- MediaProjection 独立截屏通道(抖音防缓存绕行,2026-11-17) -->
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
||||||
<!-- Android 13+ 通知运行时权限(仅影响通知可见性,不影响前台化生效) -->
|
<!-- Android 13+ 通知运行时权限(仅影响通知可见性,不影响前台化生效) -->
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".automation.KeepAliveService"
|
android:name=".automation.KeepAliveService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:foregroundServiceType="dataSync|specialUse">
|
android:foregroundServiceType="dataSync|specialUse|mediaProjection">
|
||||||
<property
|
<property
|
||||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||||
android:value="Accessibility automation keep-alive: prevents the process from being frozen by Android Cached App Freezer while driving the target app in background." />
|
android:value="Accessibility automation keep-alive: prevents the process from being frozen by Android Cached App Freezer while driving the target app in background." />
|
||||||
|
|||||||
@@ -27,6 +27,31 @@ import kotlinx.coroutines.launch
|
|||||||
*/
|
*/
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
|
/** MediaProjection 授权弹窗回调(抖音独立截屏通道,2026-11-17):结果直接交给 ProjectionHolder */
|
||||||
|
private val projectionLauncher =
|
||||||
|
registerForActivityResult(androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
|
val data = result.data
|
||||||
|
if (result.resultCode == android.app.Activity.RESULT_OK && data != null) {
|
||||||
|
val ok = com.haorui.app.ocr.ProjectionHolder.createProjection(applicationContext, result.resultCode, data)
|
||||||
|
com.haorui.app.automation.RunLogger.i(
|
||||||
|
"UI",
|
||||||
|
"MediaProjection 授权回调:用户同意,创建投影 ok=$ok",
|
||||||
|
)
|
||||||
|
com.haorui.app.automation.RunState.projectionReady = ok
|
||||||
|
} else {
|
||||||
|
com.haorui.app.automation.RunLogger.w("UI", "MediaProjection 授权回调:用户拒绝或数据为空")
|
||||||
|
com.haorui.app.automation.RunState.projectionReady = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发起屏幕采集授权(由 UI 页调用) */
|
||||||
|
fun requestProjection() {
|
||||||
|
val manager = getSystemService(android.content.Context.MEDIA_PROJECTION_SERVICE)
|
||||||
|
as android.media.projection.MediaProjectionManager
|
||||||
|
runCatching { projectionLauncher.launch(manager.createScreenCaptureIntent()) }
|
||||||
|
.onFailure { com.haorui.app.automation.RunLogger.w("UI", "发起投影授权失败: ${it.message}") }
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|||||||
@@ -428,6 +428,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
addAction("com.haorui.app.ACTION_TEST_ZHIHU")
|
addAction("com.haorui.app.ACTION_TEST_ZHIHU")
|
||||||
// 微博类目采集沙盒(debug APK:类目词条清单 + 单条内容全链)
|
// 微博类目采集沙盒(debug APK:类目词条清单 + 单条内容全链)
|
||||||
addAction("com.haorui.app.ACTION_TEST_WEIBO")
|
addAction("com.haorui.app.ACTION_TEST_WEIBO")
|
||||||
|
// 抖音热榜采集沙盒(debug APK:listOnly=清单;entryIndex=单条详情)
|
||||||
|
addAction("com.haorui.app.ACTION_TEST_DOUYIN")
|
||||||
// 调试输入法直写(M4 文章编辑器;需先 adb ime set 切到浩瑞调试输入法)
|
// 调试输入法直写(M4 文章编辑器;需先 adb ime set 切到浩瑞调试输入法)
|
||||||
addAction("com.haorui.app.ACTION_IME_COMMIT")
|
addAction("com.haorui.app.ACTION_IME_COMMIT")
|
||||||
// 文章发布机链路验证(debug APK:编辑器写入→回读→草稿确认;不碰「下一步」)
|
// 文章发布机链路验证(debug APK:编辑器写入→回读→草稿确认;不碰「下一步」)
|
||||||
@@ -671,6 +673,13 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
"entry=$entryIndex collectOnlyList=$collectOnlyList composeVerify=$composeVerify topics=${topics.size})",
|
"entry=$entryIndex collectOnlyList=$collectOnlyList composeVerify=$composeVerify topics=${topics.size})",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// 抖音采集沙盒(debug APK;listOnly=1 只拉清单;entryIndex=单条详情序号)
|
||||||
|
"com.haorui.app.ACTION_TEST_DOUYIN" -> {
|
||||||
|
val entryIndex = intent.getStringExtra("entryIndex")?.toIntOrNull() ?: 0
|
||||||
|
val listOnly = intent.getBooleanExtra("listOnly", true)
|
||||||
|
val accepted = startDouyinCollectSandbox(entryIndex, listOnly)
|
||||||
|
RunLogger.i(TAG, "抖音采集沙盒受理=$accepted(广播 ACTION_TEST_DOUYIN entry=$entryIndex listOnly=$listOnly)")
|
||||||
|
}
|
||||||
// 调试输入法直写(M4 文章编辑器自绘控件写入;commitText 分批,回读走 OCR)
|
// 调试输入法直写(M4 文章编辑器自绘控件写入;commitText 分批,回读走 OCR)
|
||||||
"com.haorui.app.ACTION_IME_COMMIT" -> {
|
"com.haorui.app.ACTION_IME_COMMIT" -> {
|
||||||
val text = intent.getStringExtra("text").orEmpty()
|
val text = intent.getStringExtra("text").orEmpty()
|
||||||
@@ -787,8 +796,12 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6 长跑:收到停止指令,当前轮结束后终止")
|
RunLogger.i(TAG, "M6 长跑:收到停止指令,当前轮结束后终止")
|
||||||
} else {
|
} else {
|
||||||
val loopHours = intent.getIntExtra("loopHours", 0)
|
val loopHours = intent.getIntExtra("loopHours", 0)
|
||||||
val accepted = startCrossDispatchSandbox(loopHours)
|
// article=true:不造视频任务,直接走协调器领取库中 READY 任务(如抖音 ARTICLE);
|
||||||
RunLogger.i(TAG, "协调器分发沙盒受理=$accepted(广播 ACTION_TEST_CROSS_DISPATCH loopHours=$loopHours)")
|
// accountKey:领取账号键(默认沙盒自造任务,抖音任务用 douyin-local)
|
||||||
|
val article = intent.getBooleanExtra("article", false)
|
||||||
|
val accountKey = intent.getStringExtra("accountKey") ?: "sandbox-dispatch"
|
||||||
|
val accepted = startCrossDispatchSandbox(loopHours, accountKey, article)
|
||||||
|
RunLogger.i(TAG, "协调器分发沙盒受理=$accepted(广播 ACTION_TEST_CROSS_DISPATCH loopHours=$loopHours article=$article accountKey=$accountKey)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
||||||
@@ -963,17 +976,27 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
* @param loopHours >0 = 混合长跑模式:循环执行单次沙盒直到预算耗尽(M6 验收硬门槛:
|
* @param loopHours >0 = 混合长跑模式:循环执行单次沙盒直到预算耗尽(M6 验收硬门槛:
|
||||||
* 混合连续运行 4 小时+跨日;休息期/额度门在循环内自然生效等待,广播 loopHours=0 可停)。
|
* 混合连续运行 4 小时+跨日;休息期/额度门在循环内自然生效等待,广播 loopHours=0 可停)。
|
||||||
*/
|
*/
|
||||||
fun startCrossDispatchSandbox(loopHours: Int = 0): Boolean = synchronized(stepLifecycleLock) {
|
fun startCrossDispatchSandbox(loopHours: Int = 0, accountKey: String = "sandbox-dispatch", article: Boolean = false): Boolean = synchronized(stepLifecycleLock) {
|
||||||
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
||||||
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
||||||
frontGuard.creditNavigating || !foregroundCoordinator.isIdle() || latestConfig.toutiao.autoPublish ||
|
frontGuard.creditNavigating || !foregroundCoordinator.isIdle() || latestConfig.toutiao.autoPublish ||
|
||||||
runCatching { videoDownloader.hasPendingDrafts() }.getOrDefault(true)) return@synchronized false
|
runCatching { videoDownloader.hasPendingDrafts() }.getOrDefault(true)) return@synchronized false
|
||||||
|
if (article) {
|
||||||
|
// ARTICLE 模式领取库中已有 READY 任务(如抖音采集落库的图文任务),不造视频任务;
|
||||||
|
// 图文写入依赖调试输入法(自绘无节点,ACTION_SET_TEXT 不可用——M4 定案)
|
||||||
|
val ime = android.provider.Settings.Secure.getString(contentResolver, "default_input_method").orEmpty()
|
||||||
|
if (!ime.startsWith("com.haorui.app/")) {
|
||||||
|
RunLogger.w(TAG, "M6 分发沙盒(ARTICLE):当前输入法非调试输入法($ime),请先 adb shell ime set com.haorui.app/.automation.ime.HaoRuiDebugIme")
|
||||||
|
return@synchronized false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
val fixture = java.io.File(getExternalFilesDir(null), "m5-fixture.mp4")
|
val fixture = java.io.File(getExternalFilesDir(null), "m5-fixture.mp4")
|
||||||
if (!fixture.exists() || fixture.length() <= 0) {
|
if (!fixture.exists() || fixture.length() <= 0) {
|
||||||
RunLogger.w(TAG, "M6 分发沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
RunLogger.w(TAG, "M6 分发沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
||||||
return@synchronized false
|
return@synchronized false
|
||||||
}
|
}
|
||||||
automationScope.launch { runCrossDispatchSandbox(fixture, loopHours) }
|
}
|
||||||
|
automationScope.launch { runCrossDispatchSandbox(null, loopHours, accountKey, article) }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -982,9 +1005,15 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
private var marathonRemainingHours: Int = 0
|
private var marathonRemainingHours: Int = 0
|
||||||
|
|
||||||
/** 沙盒主体(IO 协程内执行;suspend,全部落库走挂起 API 无 runBlocking)。
|
/** 沙盒主体(IO 协程内执行;suspend,全部落库走挂起 API 无 runBlocking)。
|
||||||
* loopHours>0 时循环执行单次沙盒(每轮独立 try-catch,异常不终止长跑)。 */
|
* loopHours>0 时循环执行单次沙盒(每轮独立 try-catch,异常不终止长跑)。
|
||||||
private suspend fun runCrossDispatchSandbox(fixture: java.io.File, loopHours: Int = 0): Boolean {
|
* fixture=null 且 article=true 时为 ARTICLE 模式:不造任务,领库中 READY 图文任务执行。 */
|
||||||
if (loopHours <= 0) return runCrossDispatchOnce(fixture)
|
private suspend fun runCrossDispatchSandbox(
|
||||||
|
fixture: java.io.File?,
|
||||||
|
loopHours: Int = 0,
|
||||||
|
accountKey: String = "sandbox-dispatch",
|
||||||
|
article: Boolean = false,
|
||||||
|
): Boolean {
|
||||||
|
if (loopHours <= 0) return runCrossDispatchOnce(fixture, accountKey = accountKey, article = article)
|
||||||
// ── 混合长跑模式 ──────────────────────────────────────
|
// ── 混合长跑模式 ──────────────────────────────────────
|
||||||
marathonRemainingHours = loopHours
|
marathonRemainingHours = loopHours
|
||||||
val deadlineMs = android.os.SystemClock.elapsedRealtime() + loopHours * 3_600_000L
|
val deadlineMs = android.os.SystemClock.elapsedRealtime() + loopHours * 3_600_000L
|
||||||
@@ -1002,7 +1031,7 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6 长跑第 $round 轮开始(剩余 ${marathonRemainingHours}h)")
|
RunLogger.i(TAG, "M6 长跑第 $round 轮开始(剩余 ${marathonRemainingHours}h)")
|
||||||
val roundStart = android.os.SystemClock.elapsedRealtime()
|
val roundStart = android.os.SystemClock.elapsedRealtime()
|
||||||
val ok = try {
|
val ok = try {
|
||||||
runCrossDispatchOnce(fixture, manageSession = false)
|
runCrossDispatchOnce(fixture, manageSession = false, accountKey = accountKey, article = article)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
RunLogger.e(TAG, "M6 长跑第 $round 轮异常(不终止长跑): ${t.javaClass.simpleName}:${t.message}", t)
|
RunLogger.e(TAG, "M6 长跑第 $round 轮异常(不终止长跑): ${t.javaClass.simpleName}:${t.message}", t)
|
||||||
false
|
false
|
||||||
@@ -1028,8 +1057,14 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 单次沙盒(长跑循环体复用;manageSession=false 时不做会话开关——长跑统一管理)。 */
|
/** 单次沙盒(长跑循环体复用;manageSession=false 时不做会话开关——长跑统一管理)。
|
||||||
private suspend fun runCrossDispatchOnce(fixture: java.io.File, manageSession: Boolean = true): Boolean {
|
* article=true:不造视频任务,协调器直接领取库中 READY 任务(ARTICLE 走图文机器,VIDEO 走视频桥)。 */
|
||||||
|
private suspend fun runCrossDispatchOnce(
|
||||||
|
fixture: java.io.File?,
|
||||||
|
manageSession: Boolean = true,
|
||||||
|
accountKey: String = "sandbox-dispatch",
|
||||||
|
article: Boolean = false,
|
||||||
|
): Boolean {
|
||||||
try {
|
try {
|
||||||
// 沙盒需要运行代际——跨平台会话默认关闭(新模块默认关闭),临时开启(内存态,
|
// 沙盒需要运行代际——跨平台会话默认关闭(新模块默认关闭),临时开启(内存态,
|
||||||
// 不改持久配置;currentGeneration 要求 enabled && wanted,configure+start 双开)。
|
// 不改持久配置;currentGeneration 要求 enabled && wanted,configure+start 双开)。
|
||||||
@@ -1050,6 +1085,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
opened
|
opened
|
||||||
}
|
}
|
||||||
val taskStore = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
val taskStore = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
||||||
|
// ── ① ARTICLE 模式:不造视频任务,直接进门控+领取(库中已有 READY 图文任务)──
|
||||||
|
if (!article) {
|
||||||
// ── ① 管线加工成品要素(指纹/媒体路径/许可,满足 preparationRejection)──
|
// ── ① 管线加工成品要素(指纹/媒体路径/许可,满足 preparationRejection)──
|
||||||
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
||||||
RunLogger.i(TAG, "M6-Provider: $msg")
|
RunLogger.i(TAG, "M6-Provider: $msg")
|
||||||
@@ -1116,7 +1153,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
com.haorui.app.crossplatform.model.CrossTaskState.READY,
|
com.haorui.app.crossplatform.model.CrossTaskState.READY,
|
||||||
generation, "分发沙盒·就绪",
|
generation, "分发沙盒·就绪",
|
||||||
)
|
)
|
||||||
// ── ③ 门控 + 协调器 + 桥接执行(VIDEO→旧发布器草稿车道)──
|
} // end if(!article) 造任务块
|
||||||
|
// ── ③ 门控 + 协调器 + 执行(按 contentKind 路由:ARTICLE→图文机器 / VIDEO→视频桥)──
|
||||||
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
||||||
quotaManager, latestConfig.credit.threshold,
|
quotaManager, latestConfig.credit.threshold,
|
||||||
{ threshold ->
|
{ threshold ->
|
||||||
@@ -1127,6 +1165,36 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6-Coordinator: $msg")
|
RunLogger.i(TAG, "M6-Coordinator: $msg")
|
||||||
}
|
}
|
||||||
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
||||||
|
when (t.contentKind) {
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.ARTICLE -> {
|
||||||
|
// 图文机器(M4 已真机验收全链):导航→写入→回读→草稿回执
|
||||||
|
val port = com.haorui.app.crossplatform.publish.ToutiaoArticlePort(this@HaoRuiAccessibilityService)
|
||||||
|
if (!port.openArticleEditor()) {
|
||||||
|
return@Executor com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("未进入文章编辑器")
|
||||||
|
}
|
||||||
|
val machine = com.haorui.app.crossplatform.publish.ArticlePublishMachine(port) { msg ->
|
||||||
|
RunLogger.i(TAG, "M6-Article: $msg")
|
||||||
|
}
|
||||||
|
val result = machine.run(t.title, t.bodyText)
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"M6-Article 结果: outcome=${result.outcome} phase=${result.phase} " +
|
||||||
|
"reason=${result.reason} exited=${result.exitedSafely}",
|
||||||
|
)
|
||||||
|
when {
|
||||||
|
// 草稿回执明确确认(顶栏「草稿已保存」+字数/锚点回读全过)
|
||||||
|
result.outcome == "草稿已核对" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Confirmed("article-draft:${t.title.take(20)}")
|
||||||
|
// 写入失败/未进编辑器等确定性失败(未点提交,草稿未生成)——释放预占
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.PREPARE ||
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.WRITE_TITLE && result.outcome == "失败" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("图文写入失败:${result.reason}")
|
||||||
|
// 暂停核对/回读不吻合/回执未见——编辑器可能已自动保存,结果未知进人工核对
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Unknown("图文待核对:${result.reason}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.VIDEO -> {
|
||||||
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ tt, uri, auto, decl ->
|
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ tt, uri, auto, decl ->
|
||||||
publisher.submit(tt, uri, autoPublish = auto, declaration = decl)
|
publisher.submit(tt, uri, autoPublish = auto, declaration = decl)
|
||||||
}) { msg -> RunLogger.i(TAG, "M6-Bridge: $msg") }
|
}) { msg -> RunLogger.i(TAG, "M6-Bridge: $msg") }
|
||||||
@@ -1163,12 +1231,14 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted(bridged.reason)
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted(bridged.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // end when(contentKind)
|
||||||
|
}
|
||||||
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
||||||
// dispatchOnce 在本协程(automationScope=IO)直接执行——绝不 runBlocking:
|
// dispatchOnce 在本协程(automationScope=IO)直接执行——绝不 runBlocking:
|
||||||
// 本函数可能从广播接收器(主线程)启动,runBlocking 会堵死主线程消息队列,
|
// 本函数可能从广播接收器(主线程)启动,runBlocking 会堵死主线程消息队列,
|
||||||
// 门控信用读的 withContext(Dispatchers.Main) 截屏永远排不上(2026-11-16
|
// 门控信用读的 withContext(Dispatchers.Main) 截屏永远排不上(2026-11-16
|
||||||
// 第 3~6 轮卡死实锤:卡点恒在 launchApp 后第一处 Main 调度)。
|
// 第 3~6 轮卡死实锤:卡点恒在 launchApp 后第一处 Main 调度)。
|
||||||
val dispatch = coordinator.dispatchOnce("sandbox-dispatch", generation, executor)
|
val dispatch = coordinator.dispatchOnce(accountKey, generation, executor)
|
||||||
RunLogger.i(TAG, "M6 分发沙盒结果:$dispatch")
|
RunLogger.i(TAG, "M6 分发沙盒结果:$dispatch")
|
||||||
return dispatch is com.haorui.app.crossplatform.publish.PublishCoordinator.Outcome.Dispatched
|
return dispatch is com.haorui.app.crossplatform.publish.PublishCoordinator.Outcome.Dispatched
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
@@ -1223,6 +1293,273 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音采集沙盒(debug APK,只读):listOnly=1 拉热榜清单(OCR 行解析,日志逐条输出);
|
||||||
|
* 否则采集第 entryIndex 条词条详情(相对时间折算,作者/正文未核验留 null 记 unknowns)。
|
||||||
|
* 前台占用/互斥与知乎沙盒同口径。
|
||||||
|
*/
|
||||||
|
fun startDouyinCollectSandbox(entryIndex: Int, listOnly: Boolean): Boolean =
|
||||||
|
synchronized(stepLifecycleLock) {
|
||||||
|
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
||||||
|
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
||||||
|
frontGuard.creditNavigating || !foregroundCoordinator.isIdle()) return@synchronized false
|
||||||
|
launchForegroundTask {
|
||||||
|
val ticket = foregroundCoordinator.tryEnterLegacy("DOUYIN-SANDBOX") ?: return@launchForegroundTask
|
||||||
|
try {
|
||||||
|
val port = com.haorui.app.crossplatform.source.douyin.DouyinDevicePort(this@HaoRuiAccessibilityService)
|
||||||
|
val machine = com.haorui.app.crossplatform.source.douyin.DouyinHotListCollector(port) { SystemClock.elapsedRealtime() }
|
||||||
|
machine.runGeneration = startGeneration.toLong()
|
||||||
|
if (listOnly) {
|
||||||
|
RunLogger.i(TAG, "抖音采集沙盒开始:清单模式")
|
||||||
|
val list = machine.collectHotList()
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"抖音采集沙盒清单: outcome=${list.outcome} phase=${list.phase} " +
|
||||||
|
"entries=${list.entries.size} exited=${list.exitedSafely} reason=${list.reason}",
|
||||||
|
)
|
||||||
|
list.entries.forEachIndexed { i, e ->
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"抖音热榜[$i]: 排名=${e.rank} 标题=${e.title.take(24)} " +
|
||||||
|
"标签=${e.label} 热度=${e.heatRaw}",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RunLogger.i(TAG, "抖音采集沙盒开始:单条模式 entry=$entryIndex")
|
||||||
|
// ⚠️ AI 创作链材料必须在详情页仍在前台时取(collectOne 的 finally 会 EXIT
|
||||||
|
// 返回榜单,退出后读屏=榜单不是词条——微博 M4 真机取证教训)。
|
||||||
|
// 全文失败退单屏兜底;作者行/时间行等噪声由 OcrArticleExtractor 剔除。
|
||||||
|
var detailLines: List<String> = emptyList()
|
||||||
|
val result = machine.collectOne(entryIndex, onDetail = {
|
||||||
|
val full = runCatching { port.readDetailOcrFullText() }.getOrDefault(emptyList())
|
||||||
|
detailLines = if (full.isNotEmpty()) full else port.readDetailOcrLines()
|
||||||
|
})
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"抖音采集沙盒结果: outcome=${result.outcome} phase=${result.phase} " +
|
||||||
|
"exited=${result.exitedSafely} reason=${result.reason}",
|
||||||
|
)
|
||||||
|
result.observation?.let { obs ->
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"抖音采集沙盒观察: 标题=${obs.hotEntry?.title?.take(24)} 排名=${obs.hotEntry?.rank} " +
|
||||||
|
"热度=${obs.hotEntry?.heatRaw} 发布时间=${obs.publishedAtText}(${obs.publishedAtMs}) " +
|
||||||
|
"材料=${detailLines.size}行 未知=${obs.unknowns}",
|
||||||
|
)
|
||||||
|
// 落库:采集成功后 enqueue 到任务库(仿微博模式)
|
||||||
|
if (result.outcome == "已观察") {
|
||||||
|
val store = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
||||||
|
// ⚠️ 代际统一(2026-11-17 真库实锤):enqueue 校验与三跳、协调器领取
|
||||||
|
// 共用任务库 run_control 代际(beginRun);服务 startGeneration 是另一
|
||||||
|
// 命名空间,混用会让 active() 校验全失败、任务卡 DISCOVERED。
|
||||||
|
// 沙盒默认不启调度器,会话未开 → 临时开启并轮询等 beginRun 落库。
|
||||||
|
val gen: Long = currentCrossRunGeneration() ?: run {
|
||||||
|
crossRunSession?.configure(true)
|
||||||
|
crossRunSession?.start()
|
||||||
|
var opened: Long? = null
|
||||||
|
for (i in 1..15) {
|
||||||
|
kotlinx.coroutines.delay(1_000)
|
||||||
|
opened = currentCrossRunGeneration()
|
||||||
|
if (opened != null) break
|
||||||
|
}
|
||||||
|
if (opened == null) {
|
||||||
|
RunLogger.w(TAG, "抖音采集落库:会话临时开启后仍无代际(beginRun 未完成),放弃落库")
|
||||||
|
return@let
|
||||||
|
}
|
||||||
|
opened
|
||||||
|
}
|
||||||
|
val title = obs.hotEntry?.title ?: "抖音热榜第${obs.hotEntry?.rank ?: entryIndex}条"
|
||||||
|
val identity = "douyin-rank${obs.hotEntry?.rank ?: entryIndex}-${title.hashCode()}"
|
||||||
|
// 模板正文(降级保底):AI 创作链失败时任务仍可推进,不阻塞链路
|
||||||
|
val fallbackBody = buildString {
|
||||||
|
appendLine("抖音热榜第 ${obs.hotEntry?.rank ?: entryIndex} 名:$title")
|
||||||
|
obs.hotEntry?.heatRaw?.let { appendLine("热度:$it") }
|
||||||
|
obs.hotEntry?.label?.let { appendLine("标签:$it") }
|
||||||
|
obs.publishedAtText?.let { appendLine("发布时间:$it") }
|
||||||
|
appendLine()
|
||||||
|
appendLine("以上内容来自抖音热榜实时采集。")
|
||||||
|
}
|
||||||
|
// ── AI 创作链(M4 组件复用):事实包→正文→标题,失败降级模板 ──
|
||||||
|
// 材料头部注入热榜元数据(排名/热度/标签)给模型锚定「抖音热榜第N名」语境。
|
||||||
|
var aiTitle: String? = null
|
||||||
|
var aiBody: String? = null
|
||||||
|
if (detailLines.isNotEmpty()) {
|
||||||
|
try {
|
||||||
|
val meta = buildString {
|
||||||
|
appendLine("(抖音热榜第 ${obs.hotEntry?.rank ?: entryIndex} 名" +
|
||||||
|
(obs.hotEntry?.heatRaw?.let { ",热度 $it" } ?: "") +
|
||||||
|
(obs.hotEntry?.label?.let { ",标签「$it」" } ?: "") + ")")
|
||||||
|
}
|
||||||
|
val material = listOf(meta, obs.publishedAtText?.let { "(发布时间:$it)" } ?: "")
|
||||||
|
.filter { it.isNotBlank() } + detailLines
|
||||||
|
val builder = com.haorui.app.crossplatform.compose.EvidenceBuilder(
|
||||||
|
logger = { msg -> RunLogger.i(TAG, "DY-Evidence: $msg") },
|
||||||
|
)
|
||||||
|
val evidence = builder.build(
|
||||||
|
title, "douyin://hot/${obs.hotEntry?.rank ?: entryIndex}",
|
||||||
|
material, System.currentTimeMillis(),
|
||||||
|
)
|
||||||
|
if (evidence != null) {
|
||||||
|
RunLogger.i(TAG, "DY 创作链:事实包 ${evidence.sourceRoute} ${evidence.sourceText.length} 字(首行=${evidence.sourceText.lineSequence().firstOrNull().orEmpty().take(40)})")
|
||||||
|
val aiConfig = latestConfig.ai
|
||||||
|
val bodyComposer = com.haorui.app.crossplatform.compose.ArticleBodyComposer(aiConfig) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Body: $msg")
|
||||||
|
}
|
||||||
|
val bodyResult = bodyComposer.composeBody(evidence)
|
||||||
|
if (bodyResult != null) {
|
||||||
|
val composer = com.haorui.app.crossplatform.compose.ArticleComposer(aiConfig) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Composer: $msg")
|
||||||
|
}
|
||||||
|
val titles = composer.composeTitles(evidence)
|
||||||
|
if (titles != null) {
|
||||||
|
aiTitle = titles.selected
|
||||||
|
aiBody = bodyResult.body
|
||||||
|
RunLogger.i(TAG, "DY 创作链成功:标题「${titles.selected}」正文 ${bodyResult.body.codePointCount(0, bodyResult.body.length)} 字")
|
||||||
|
titles.candidates.forEachIndexed { i, c -> RunLogger.i(TAG, "DY 标题候选[$i]: $c") }
|
||||||
|
} else {
|
||||||
|
RunLogger.w(TAG, "DY 创作链:标题失败 ${composer.failureReason},降级模板")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RunLogger.w(TAG, "DY 创作链:正文失败 ${bodyComposer.failureReason},降级模板")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RunLogger.w(TAG, "DY 创作链:事实包失败 ${builder.failureReason},降级模板")
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
RunLogger.e(TAG, "DY 创作链异常(降级模板): ${t.javaClass.simpleName}:${t.message}", t)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RunLogger.w(TAG, "DY 创作链:详情材料 0 行(OCR 未取得),降级模板")
|
||||||
|
}
|
||||||
|
// 生成内容优先,模板兜底;幂等键 identity 基于热榜标题不随 AI 标题漂移
|
||||||
|
val bodyText = aiBody ?: fallbackBody
|
||||||
|
val taskTitle = aiTitle ?: title
|
||||||
|
val task = com.haorui.app.crossplatform.model.CrossPublishTask(
|
||||||
|
id = identity,
|
||||||
|
accountKey = "douyin-local",
|
||||||
|
eventId = "douyin:$identity",
|
||||||
|
contentKind = com.haorui.app.crossplatform.model.CrossContentKind.ARTICLE,
|
||||||
|
title = taskTitle,
|
||||||
|
sourcePlatform = "douyin",
|
||||||
|
sourceUrl = "douyin://hot/${obs.hotEntry?.rank ?: entryIndex}",
|
||||||
|
state = com.haorui.app.crossplatform.model.CrossTaskState.DISCOVERED,
|
||||||
|
bodyText = bodyText,
|
||||||
|
evidenceJson = kotlinx.serialization.json.Json.encodeToString(
|
||||||
|
kotlinx.serialization.json.buildJsonObject {
|
||||||
|
put("rank", kotlinx.serialization.json.JsonPrimitive(obs.hotEntry?.rank ?: 0))
|
||||||
|
put("heatRaw", kotlinx.serialization.json.JsonPrimitive(obs.hotEntry?.heatRaw.orEmpty()))
|
||||||
|
put("label", kotlinx.serialization.json.JsonPrimitive(obs.hotEntry?.label.orEmpty()))
|
||||||
|
put("publishedAtText", kotlinx.serialization.json.JsonPrimitive(obs.publishedAtText.orEmpty()))
|
||||||
|
put("publishedAtMs", kotlinx.serialization.json.JsonPrimitive(obs.publishedAtMs ?: 0L))
|
||||||
|
put("unknowns", kotlinx.serialization.json.JsonArray(
|
||||||
|
obs.unknowns.map { kotlinx.serialization.json.JsonPrimitive(it) },
|
||||||
|
))
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// 策略检查要求:发布时间/有效期/成品指纹
|
||||||
|
publishedAtMs = obs.publishedAtMs ?: System.currentTimeMillis(),
|
||||||
|
expiresAtMs = System.currentTimeMillis() + 7 * 24 * 3600 * 1000L,
|
||||||
|
payloadHash = java.security.MessageDigest.getInstance("SHA-256")
|
||||||
|
.digest((taskTitle + bodyText).toByteArray())
|
||||||
|
.joinToString("") { "%02x".format(it) },
|
||||||
|
runGeneration = gen,
|
||||||
|
)
|
||||||
|
val enqueued = kotlinx.coroutines.runBlocking {
|
||||||
|
runCatching { store.enqueue(task) }.getOrDefault(false)
|
||||||
|
}
|
||||||
|
RunLogger.i(TAG, "抖音采集落库: id=$identity 落库=$enqueued gen=$gen")
|
||||||
|
// 状态推进:DISCOVERED→FILTERED→PREPARED→READY(走标准发布流程)
|
||||||
|
// ⚠️ 任务已存在(幂等)时也要推进状态(r35 实锤:重复采集同一条目不推进);
|
||||||
|
// ⚠️ 旧代际残留(PAUSED,resumeState=DISCOVERED)先 resume 重绑代际再推进
|
||||||
|
// (2026-11-17 真机实锤:跨天热榜复现撞幂等键,gen=0≠当前代际三跳全拒)
|
||||||
|
var readyId: String? = null
|
||||||
|
if (enqueued || store.find(identity) != null) {
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
if (!enqueued) {
|
||||||
|
val resumed = store.resumeTask(identity, gen)
|
||||||
|
RunLogger.i(TAG, "抖音旧任务重绑代际: resume=$resumed gen=$gen")
|
||||||
|
if (!resumed) {
|
||||||
|
// 孤儿 PAUSED(resumeState=null,confirmNotSubmitted 旧版残留):
|
||||||
|
// 重采=重复发现,删除重建(deleteTask 按 FK 清理+素材保护)解锁重试
|
||||||
|
val existing = store.find(identity)
|
||||||
|
if (existing?.state == com.haorui.app.crossplatform.model.CrossTaskState.PAUSED &&
|
||||||
|
existing.resumeState == null) {
|
||||||
|
val deleted = store.deleteTask(identity) != null
|
||||||
|
val reEnqueued = if (deleted) runCatching { store.enqueue(task) }.getOrDefault(false) else false
|
||||||
|
RunLogger.i(TAG, "抖音孤儿任务重建: 删除=$deleted 重落库=$reEnqueued")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val t1 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.DISCOVERED, com.haorui.app.crossplatform.model.CrossTaskState.FILTERED, gen, "抖音热榜采集")
|
||||||
|
// prepare 必须带齐 rightsRef/payloadHash(策略检查 PREPARED 门槛:
|
||||||
|
// payloadHash 须 64 位 hex,rightsRef 空串对 ARTICLE 不拦但指纹必查)
|
||||||
|
val t2 = store.prepare(identity, gen, bodyText, "", task.evidenceJson, "douyin-hotlist", task.payloadHash)
|
||||||
|
val t3 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.PREPARED, com.haorui.app.crossplatform.model.CrossTaskState.READY, gen, "图文已生成")
|
||||||
|
RunLogger.i(TAG, "抖音任务状态推进: FILTERED=$t1 PREPARED=$t2 READY=$t3 gen=$gen")
|
||||||
|
// 以库内实际状态为准:三跳成功或本代际已 READY(会话复用重采)均可分发
|
||||||
|
if (t3 || store.find(identity)?.state == com.haorui.app.crossplatform.model.CrossTaskState.READY) readyId = identity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ── 同代际分发:会话已开启(本沙盒开启),协调器直接领取执行 ──
|
||||||
|
// ⚠️ 不能拆成两个沙盒:beginRun/pauseRun 每次代际+1 并把 READY 全部
|
||||||
|
// PAUSED(interruptTasks),采集与分发分开跑任务永远追不上代际。
|
||||||
|
if (readyId != null) {
|
||||||
|
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
||||||
|
quotaManager, latestConfig.credit.threshold,
|
||||||
|
{ threshold ->
|
||||||
|
com.haorui.app.ocr.CreditGateRunner.evaluate(this@HaoRuiAccessibilityService, threshold)
|
||||||
|
},
|
||||||
|
) { msg -> RunLogger.i(TAG, "DY-Gate: $msg") }
|
||||||
|
val coordinator = com.haorui.app.crossplatform.publish.PublishCoordinator(store, gate) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Coordinator: $msg")
|
||||||
|
}
|
||||||
|
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
||||||
|
when (t.contentKind) {
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.ARTICLE -> {
|
||||||
|
val port = com.haorui.app.crossplatform.publish.ToutiaoArticlePort(this@HaoRuiAccessibilityService)
|
||||||
|
if (!port.openArticleEditor()) {
|
||||||
|
return@Executor com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("未进入文章编辑器")
|
||||||
|
}
|
||||||
|
val machine = com.haorui.app.crossplatform.publish.ArticlePublishMachine(port) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Article: $msg")
|
||||||
|
}
|
||||||
|
val result = machine.run(t.title, t.bodyText)
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"DY-Article 结果: outcome=${result.outcome} phase=${result.phase} " +
|
||||||
|
"reason=${result.reason} exited=${result.exitedSafely}",
|
||||||
|
)
|
||||||
|
when {
|
||||||
|
result.outcome == "草稿已核对" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Confirmed("article-draft:${t.title.take(20)}")
|
||||||
|
// PREPARE/写入期失败=编辑器未动或草稿未成形,确定性未提交
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.PREPARE ||
|
||||||
|
(result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.WRITE_TITLE && result.outcome == "失败") ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("图文写入失败:${result.reason}")
|
||||||
|
// 暂停核对/回读不吻合/回执未见——可能已自动保存,结果未知进核对
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Unknown("图文待核对:${result.reason}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("沙盒仅支持 ARTICLE,任务 ${t.id} kind=${t.contentKind}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val dispatch = coordinator.dispatchOnce("douyin-local", gen, executor)
|
||||||
|
RunLogger.i(TAG, "抖音采集分发结果:$dispatch")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
RunLogger.e(TAG, "抖音采集沙盒异常: ${t.javaClass.simpleName}:${t.message}", t)
|
||||||
|
} finally {
|
||||||
|
foregroundCoordinator.release(ticket)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M4 创作链真机验证(debug APK):采集单条 → OCR 全文 → 事实包 → 模型标题候选。
|
* M4 创作链真机验证(debug APK):采集单条 → OCR 全文 → 事实包 → 模型标题候选。
|
||||||
* 只读+模型调用,不落库、不发布;结果全走日志(标题候选逐条输出)。
|
* 只读+模型调用,不落库、不发布;结果全走日志(标题候选逐条输出)。
|
||||||
|
|||||||
@@ -89,16 +89,21 @@ class KeepAliveService : Service() {
|
|||||||
this,
|
this,
|
||||||
NOTIFICATION_ID,
|
NOTIFICATION_ID,
|
||||||
notification,
|
notification,
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE,
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE or
|
||||||
|
// 投影活跃期间必须带 mediaProjection 类型(MediaProjection 要求宿主前台服务含此类型),
|
||||||
|
// 未授权投影时带该类型合法(类型只是声明,无需运行时校验)
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION,
|
||||||
)
|
)
|
||||||
// API 29~33:必须用 dataSync。specialUse 是 API 34 才引入的常量,
|
// API 29~33:必须用 dataSync。specialUse 是 API 34 才引入的常量,
|
||||||
// 在旧机型上是未知类型位,vivo 等厂商的省电策略会因此不认这个前台服务,
|
// 在旧机型上是未知类型位,vivo 等厂商的省电策略会因此不认这个前台服务,
|
||||||
// 导致进程照样被 Cached App Freezer 冻结(2026-10-29 真机实测踩过)。
|
// 导致进程照样被 Cached App Freezer 冻结(2026-10-29 真机实测踩过)。
|
||||||
|
// mediaProjection 类型叠加(API 29+ 常量):投影活跃期间系统校验宿主服务类型。
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> ServiceCompat.startForeground(
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> ServiceCompat.startForeground(
|
||||||
this,
|
this,
|
||||||
NOTIFICATION_ID,
|
NOTIFICATION_ID,
|
||||||
notification,
|
notification,
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC or
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION,
|
||||||
)
|
)
|
||||||
// API 28 及以下:两参重载即可
|
// API 28 及以下:两参重载即可
|
||||||
else -> startForeground(NOTIFICATION_ID, notification)
|
else -> startForeground(NOTIFICATION_ID, notification)
|
||||||
|
|||||||
@@ -22,4 +22,8 @@ object RunState {
|
|||||||
/** 最近一次识别到的信用分(同 CreditGateRunner.lastScore;null = 未读到) */
|
/** 最近一次识别到的信用分(同 CreditGateRunner.lastScore;null = 未读到) */
|
||||||
@Volatile
|
@Volatile
|
||||||
var creditScore: Int? = null
|
var creditScore: Int? = null
|
||||||
|
|
||||||
|
/** MediaProjection 投影是否就绪(抖音独立截屏通道;授权后为 true,投影停止/进程重启后为 false) */
|
||||||
|
@Volatile
|
||||||
|
var projectionReady: Boolean = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,11 @@ class CrossPublishTaskStore private constructor(context: Context) : CrossRunPers
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 仅在明确核对未提交后释放预占;不会自动回到 READY。 */
|
/** 仅在明确核对未提交后释放预占;不会自动回到 READY。
|
||||||
|
* ⚠️ 2026-11-17 真机实锤:归 PAUSED 且 resume_state=NULL 造成孤儿 PAUSED——
|
||||||
|
* 重采撞幂等键时 resumeTask 恒 false、三跳全拒,任务永远卡死。
|
||||||
|
* 「明确未提交」是确定性结论(未进编辑器/写入失败/桥拒绝,页面无成品残留),
|
||||||
|
* 按「不会自动回到 READY」的设计意图归终态 SKIPPED(可在任务页手动删除)。 */
|
||||||
suspend fun confirmNotSubmitted(attemptId: String, evidenceRef: String): Boolean = write { db ->
|
suspend fun confirmNotSubmitted(attemptId: String, evidenceRef: String): Boolean = write { db ->
|
||||||
require(evidenceRef.isNotBlank())
|
require(evidenceRef.isNotBlank())
|
||||||
val a = attempt(db, attemptId) ?: return@write false
|
val a = attempt(db, attemptId) ?: return@write false
|
||||||
@@ -331,7 +335,7 @@ class CrossPublishTaskStore private constructor(context: Context) : CrossRunPers
|
|||||||
if (a.state !in setOf(CrossAttemptState.INTENT, CrossAttemptState.UNKNOWN)) return@write false
|
if (a.state !in setOf(CrossAttemptState.INTENT, CrossAttemptState.UNKNOWN)) return@write false
|
||||||
db.update("attempts", ContentValues().apply { put("state", CrossAttemptState.NOT_SUBMITTED.name); put("receipt_ref", evidenceRef) }, "id=?", arrayOf(attemptId))
|
db.update("attempts", ContentValues().apply { put("state", CrossAttemptState.NOT_SUBMITTED.name); put("receipt_ref", evidenceRef) }, "id=?", arrayOf(attemptId))
|
||||||
db.update("quota_ledger", ContentValues().apply { put("state", CrossReservationState.RELEASED.name) }, "attempt_id=? AND state='RESERVED'", arrayOf(attemptId))
|
db.update("quota_ledger", ContentValues().apply { put("state", CrossReservationState.RELEASED.name) }, "attempt_id=? AND state='RESERVED'", arrayOf(attemptId))
|
||||||
updateState(db, t, CrossTaskState.PAUSED, "已核对未提交,需重新检查页面和成品")
|
updateState(db, t, CrossTaskState.SKIPPED, "已核对未提交:${evidenceRef.take(40)}")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,18 @@ data class CrossPlatformConfig(
|
|||||||
val weiboHotCategories: List<String> = emptyList(),
|
val weiboHotCategories: List<String> = emptyList(),
|
||||||
/** 微博热搜词条勾选(类目 id → 勾选的词条标题;重启不丢,重启后榜单已刷新——按标题在新榜单中匹配,匹配不到保留待核)。 */
|
/** 微博热搜词条勾选(类目 id → 勾选的词条标题;重启不丢,重启后榜单已刷新——按标题在新榜单中匹配,匹配不到保留待核)。 */
|
||||||
val weiboHotTopics: Map<String, List<String>> = emptyMap(),
|
val weiboHotTopics: Map<String, List<String>> = emptyMap(),
|
||||||
|
/** 知乎热榜采集卡片区间(榜单展示序,1 起;start≤end 由 normalized 归一)。 */
|
||||||
|
val zhihuCardRangeStart: Int = 1,
|
||||||
|
val zhihuCardRangeEnd: Int = 20,
|
||||||
|
/** 抖音热榜只采前 N 条(1 起)。 */
|
||||||
|
val douyinTopN: Int = 20,
|
||||||
|
/** 抖音标签过滤(热/新/挑战/辟谣;空=不过滤)。 */
|
||||||
|
val douyinLabelFilter: List<String> = emptyList(),
|
||||||
) {
|
) {
|
||||||
fun normalized(): CrossPlatformConfig {
|
fun normalized(): CrossPlatformConfig {
|
||||||
val maximumDuration = videoMaxSeconds.coerceIn(20, 4000)
|
val maximumDuration = videoMaxSeconds.coerceIn(20, 4000)
|
||||||
|
val cardStart = zhihuCardRangeStart.coerceIn(1, 50)
|
||||||
|
val cardEnd = zhihuCardRangeEnd.coerceIn(cardStart, 50)
|
||||||
return copy(
|
return copy(
|
||||||
mode = if (mode.trim().uppercase(Locale.ROOT) == MODE_AUTO) MODE_AUTO else MODE_DRY_RUN,
|
mode = if (mode.trim().uppercase(Locale.ROOT) == MODE_AUTO) MODE_AUTO else MODE_DRY_RUN,
|
||||||
scanIntervalMinutes = scanIntervalMinutes.coerceIn(5, 120),
|
scanIntervalMinutes = scanIntervalMinutes.coerceIn(5, 120),
|
||||||
@@ -56,6 +65,10 @@ data class CrossPlatformConfig(
|
|||||||
weiboHotTopics = weiboHotTopics.entries
|
weiboHotTopics = weiboHotTopics.entries
|
||||||
.filter { it.key.trim() in WEIBO_CATEGORY_IDS }
|
.filter { it.key.trim() in WEIBO_CATEGORY_IDS }
|
||||||
.associate { it.key.trim() to it.value.map { t -> t.trim() }.filter { t -> t.isNotEmpty() }.distinct() },
|
.associate { it.key.trim() to it.value.map { t -> t.trim() }.filter { t -> t.isNotEmpty() }.distinct() },
|
||||||
|
zhihuCardRangeStart = cardStart,
|
||||||
|
zhihuCardRangeEnd = cardEnd,
|
||||||
|
douyinTopN = douyinTopN.coerceIn(1, 50),
|
||||||
|
douyinLabelFilter = douyinLabelFilter.filter { it in DOUYIN_LABELS }.distinct(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +93,8 @@ data class CrossPlatformConfig(
|
|||||||
/** 微博热搜类目合法 id(见 WeiboHotCategories,2026-11-14 e2 实测清单)。 */
|
/** 微博热搜类目合法 id(见 WeiboHotCategories,2026-11-14 e2 实测清单)。 */
|
||||||
private val WEIBO_CATEGORY_IDS: Set<String> =
|
private val WEIBO_CATEGORY_IDS: Set<String> =
|
||||||
com.haorui.app.crossplatform.source.weibo.WeiboHotCategories.ALL.map { it.id }.toSet()
|
com.haorui.app.crossplatform.source.weibo.WeiboHotCategories.ALL.map { it.id }.toSet()
|
||||||
|
/** 抖音标签过滤合法词(见 DouyinHotListParser.LABELS,2026-11-16 e1 实测全集)。 */
|
||||||
|
val DOUYIN_LABELS = listOf("热", "新", "挑战", "辟谣")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +120,10 @@ object CrossPlatformConfigCodec {
|
|||||||
"categories" to c.categories.joinToString("|"),
|
"categories" to c.categories.joinToString("|"),
|
||||||
"weibo_hot_categories" to c.weiboHotCategories.joinToString("|"),
|
"weibo_hot_categories" to c.weiboHotCategories.joinToString("|"),
|
||||||
"weibo_hot_topics" to kotlinx.serialization.json.Json.encodeToString(c.weiboHotTopics),
|
"weibo_hot_topics" to kotlinx.serialization.json.Json.encodeToString(c.weiboHotTopics),
|
||||||
|
"zhihu_card_range_start" to c.zhihuCardRangeStart.toString(),
|
||||||
|
"zhihu_card_range_end" to c.zhihuCardRangeEnd.toString(),
|
||||||
|
"douyin_top_n" to c.douyinTopN.toString(),
|
||||||
|
"douyin_label_filter" to c.douyinLabelFilter.joinToString("|"),
|
||||||
).mapKeys { (key, _) -> PREFIX + key }
|
).mapKeys { (key, _) -> PREFIX + key }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +164,11 @@ object CrossPlatformConfigCodec {
|
|||||||
kotlinx.serialization.json.Json.decodeFromString<Map<String, List<String>>>(raw)
|
kotlinx.serialization.json.Json.decodeFromString<Map<String, List<String>>>(raw)
|
||||||
}.getOrDefault(d.weiboHotTopics)
|
}.getOrDefault(d.weiboHotTopics)
|
||||||
} ?: d.weiboHotTopics,
|
} ?: d.weiboHotTopics,
|
||||||
|
zhihuCardRangeStart = i("zhihu_card_range_start", d.zhihuCardRangeStart),
|
||||||
|
zhihuCardRangeEnd = i("zhihu_card_range_end", d.zhihuCardRangeEnd),
|
||||||
|
douyinTopN = i("douyin_top_n", d.douyinTopN),
|
||||||
|
douyinLabelFilter = value("douyin_label_filter")?.split('|')?.filter { it.isNotBlank() }
|
||||||
|
?: d.douyinLabelFilter,
|
||||||
).normalized()
|
).normalized()
|
||||||
return if (validEncoding) decoded else decoded.copy(enabled = false, mode = CrossPlatformConfig.MODE_DRY_RUN)
|
return if (validEncoding) decoded else decoded.copy(enabled = false, mode = CrossPlatformConfig.MODE_DRY_RUN)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,16 @@ object ArticleTextPolicy {
|
|||||||
/** 默认分批大小(字符数):经验值,覆盖编辑器单次 commit 稳定区间。 */
|
/** 默认分批大小(字符数):经验值,覆盖编辑器单次 commit 稳定区间。 */
|
||||||
const val DEFAULT_BATCH = 500
|
const val DEFAULT_BATCH = 500
|
||||||
|
|
||||||
/** 回读锚点分片长度(字符数)与模糊命中阈值。
|
/** 回读锚点 bigram 匹配阈值与最小锚点长度。
|
||||||
* OCR 单字误读实测:「请输→清輪」「正文→正女」「已→己」——30 字锚点切 6 片,
|
* 2026-11-15 分片方案:30 字锚点切 6 片×5 字,OCR 错 2 片=0.667→0.7 误拒→放宽 0.6。
|
||||||
* 错 2 片=0.667,0.7 阈值会误拒(2026-11-15 第八轮真机);放宽到 0.6(≥4/6 片),
|
* 2026-11-17 bigram 修订(AI 正文真机):分片方案 OCR 错 1 字即毁整片(5 字全废),
|
||||||
* 无关内容 0 命中仍拒绝。 */
|
* 30 字锚点错 3 字=3 片毁=0.5<0.6 拒绝。改 bigram——错 1 字最多毁 2 组(29 组中 6 组
|
||||||
|
* 损失=0.79),阈值 0.65 留足安全边际(无关文本/段间共用短语 bigram 重合 ≤0.62,
|
||||||
|
* 污染段尾锚点 0.83,真机标定)。 */
|
||||||
private const val ANCHOR_LEN = 30
|
private const val ANCHOR_LEN = 30
|
||||||
private const val ANCHOR_MIN = 6
|
private const val ANCHOR_MIN = 6
|
||||||
private const val SHARD_LEN = 5
|
private const val SHARD_LEN = 5 // 仅短锚点退回精确包含的门槛
|
||||||
const val FUZZY_HIT_RATE = 0.6
|
const val FUZZY_HIT_RATE = 0.65
|
||||||
|
|
||||||
/** 超长文本分批(按码点切分,不切开代理对)。空文本返回空表。 */
|
/** 超长文本分批(按码点切分,不切开代理对)。空文本返回空表。 */
|
||||||
fun commitBatches(text: String, batchSize: Int = DEFAULT_BATCH): List<String> {
|
fun commitBatches(text: String, batchSize: Int = DEFAULT_BATCH): List<String> {
|
||||||
@@ -70,33 +72,50 @@ object ArticleTextPolicy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正文回读:首段前 [ANCHOR_LEN] 字 + 尾段后 [ANCHOR_LEN] 字双锚点均模糊定位。
|
* 正文回读:首段锚点(双候选)+ 尾段后 [ANCHOR_LEN] 字锚点均模糊定位。
|
||||||
* 2026-11-15 真机修订:逐字精确包含过脆(OCR 把「请输」误读为「清輪」,错 1 字即缺失),
|
* 2026-11-15 真机修订:逐字精确包含过脆(OCR 把「请输」误读为「清輪」,错 1 字即缺失),
|
||||||
* 改分片命中——锚点切 [SHARD_LEN] 字片,命中率 ≥ [FUZZY_HIT_RATE] 即判定位;
|
* 改分片命中——锚点切 [SHARD_LEN] 字片,命中率 ≥ [FUZZY_HIT_RATE] 即判定位;
|
||||||
* 弱锚点(<6 字)仍拒绝,无关内容 0 命中仍拒绝——不放行假一致。
|
* 弱锚点(<6 字)仍拒绝,无关内容 0 命中仍拒绝——不放行假一致。
|
||||||
|
* 2026-11-17 修订(AI 正文 1431 字真机):首锚点双候选——
|
||||||
|
* ① 段首前 30 字(未污染时的快路径);
|
||||||
|
* ② 段尾 30 字(污染容错:OCR 对段首前几字误读率高——「e國e中」式替换只伤段首,
|
||||||
|
* 段尾必然完好;固定跳头窗口赌不中污染长度,真机复算 skip=4/6/8 均 ≤1/6 命中)。
|
||||||
|
* 任一首候选命中即通过,尾锚点不变;两候选都未命中仍拒绝。
|
||||||
*/
|
*/
|
||||||
fun bodyMatches(expected: String, ocrLines: List<String>): Boolean {
|
fun bodyMatches(expected: String, ocrLines: List<String>): Boolean {
|
||||||
val paragraphs = expected.split('\n').map { normalize(it) }.filter { it.isNotEmpty() }
|
val paragraphs = expected.split('\n').map { normalize(it) }.filter { it.isNotEmpty() }
|
||||||
if (paragraphs.isEmpty()) return false
|
if (paragraphs.isEmpty()) return false
|
||||||
val first = paragraphs.first().take(ANCHOR_LEN)
|
val firstPara = paragraphs.first()
|
||||||
val last = paragraphs.last().takeLast(ANCHOR_LEN)
|
val last = paragraphs.last().takeLast(ANCHOR_LEN)
|
||||||
if (first.length < ANCHOR_MIN || last.length < ANCHOR_MIN) return false
|
val firstCandidates = buildList {
|
||||||
|
add(firstPara.take(ANCHOR_LEN))
|
||||||
|
if (firstPara.length > ANCHOR_LEN) add(firstPara.takeLast(ANCHOR_LEN))
|
||||||
|
}.filter { it.length >= ANCHOR_MIN }
|
||||||
|
if (firstCandidates.isEmpty() || last.length < ANCHOR_MIN) return false
|
||||||
val joined = normalize(ocrLines.joinToString("\n"))
|
val joined = normalize(ocrLines.joinToString("\n"))
|
||||||
return fuzzyContains(joined, first) && fuzzyContains(joined, last)
|
return firstCandidates.any { fuzzyContains(joined, it) } && fuzzyContains(joined, last)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 分片模糊包含:[needle] 切 [SHARD_LEN] 字片,[haystack] 命中率 ≥ [FUZZY_HIT_RATE]。 */
|
/**
|
||||||
|
* 模糊包含(2026-11-17 bigram 修订):needle 的二字组在 haystack 中的命中率 ≥ [FUZZY_HIT_RATE]。
|
||||||
|
*
|
||||||
|
* 原分片方案(5 字片)对 OCR 形近错字过脆:一片中错 1 字即整片毁,30 字锚点错 3 字
|
||||||
|
* =3 片毁=0.5<0.6 拒绝(AI 正文 1199 字真机实锤)。
|
||||||
|
*
|
||||||
|
* bigram 方案:30 字锚点=29 个二字组,OCR 错 1 字最多毁 2 组(相邻 2 个 bigram);
|
||||||
|
* 错 3 字毁 ≤6 组=23/29≈0.79 远超阈值。无关文本 bigram 重合率 <0.3(真机标定),
|
||||||
|
* 0.5 阈值留足安全边际——不放行假一致(无关内容 0 命中仍拒绝)。
|
||||||
|
*/
|
||||||
internal fun fuzzyContains(haystack: String, needle: String): Boolean {
|
internal fun fuzzyContains(haystack: String, needle: String): Boolean {
|
||||||
if (needle.isEmpty()) return true
|
if (needle.isEmpty()) return true
|
||||||
if (haystack.isEmpty()) return false
|
if (haystack.isEmpty()) return false
|
||||||
val shards = if (needle.length <= SHARD_LEN) {
|
// 短锚点(≤SHARD_LEN)无 bigram 统计力,退回精确包含
|
||||||
listOf(needle)
|
if (needle.length <= SHARD_LEN) return haystack.contains(needle)
|
||||||
} else {
|
val needleBigrams = (0 until needle.length - 1)
|
||||||
(0 until needle.length step SHARD_LEN)
|
.map { needle.substring(it, it + 2) }
|
||||||
.map { needle.substring(it, minOf(it + SHARD_LEN, needle.length)) }
|
if (needleBigrams.isEmpty()) return haystack.contains(needle)
|
||||||
}
|
val hits = needleBigrams.count { haystack.contains(it) }
|
||||||
val hits = shards.count { haystack.contains(it) }
|
return hits.toDouble() / needleBigrams.size >= FUZZY_HIT_RATE
|
||||||
return hits.toDouble() / shards.size >= FUZZY_HIT_RATE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class ToutiaoArticlePort(
|
|||||||
private const val TAG = "TT-Article"
|
private const val TAG = "TT-Article"
|
||||||
private const val TOUTIAO_PKG = "com.ss.android.article.news"
|
private const val TOUTIAO_PKG = "com.ss.android.article.news"
|
||||||
private const val NAV_TIMEOUT_MS = 60_000L
|
private const val NAV_TIMEOUT_MS = 60_000L
|
||||||
private const val MAX_BODY_SCREENS = 8
|
private const val MAX_BODY_SCREENS = 12 // AI 正文 800~1500 字约 8~10 屏,留页底判定余量
|
||||||
/** 截屏最小间隔(takeScreenshot 系统频率限制;实测连拍 <1s 即 errorCode=3)。 */
|
/** 截屏最小间隔(takeScreenshot 系统频率限制;实测连拍 <1s 即 errorCode=3)。 */
|
||||||
private const val MIN_CAPTURE_INTERVAL_MS = 1_200L
|
private const val MIN_CAPTURE_INTERVAL_MS = 1_200L
|
||||||
/** 兜底坐标(2026-11-15 取证+实测;仅在 OCR 定位失败且屏幕标记命中后使用)。 */
|
/** 兜底坐标(2026-11-15 取证+实测;仅在 OCR 定位失败且屏幕标记命中后使用)。 */
|
||||||
@@ -111,15 +111,24 @@ class ToutiaoArticlePort(
|
|||||||
return all
|
return all
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 滚回正文顶部:反向滑动(指纹下移=内容上移),内容签名稳定即到顶。 */
|
/** 滚回正文顶部:反向滑动(指纹下移=内容上移),内容签名稳定即到顶。
|
||||||
private fun scrollToTop(maxSwipes: Int = 10) {
|
* ⚠️ 2026-11-17 真机(AI 正文 1431 字):10 次预算不够——8~10 屏文档反向滑
|
||||||
|
* 恰好耗尽,顶未到就下扫 → 首锚点永不入视野 → 回读必失败。预算提到 25;
|
||||||
|
* 且用「连续两次滑动后签名相同」判定(单次相同可能是滚动动画中的采样抖动)。 */
|
||||||
|
private fun scrollToTop(maxSwipes: Int = 25) {
|
||||||
var prevSignature = ""
|
var prevSignature = ""
|
||||||
|
var stableCount = 0
|
||||||
for (i in 0 until maxSwipes) {
|
for (i in 0 until maxSwipes) {
|
||||||
val signature = screen().map { it.text.trim() }.joinToString("|")
|
val signature = screen().map { it.text.trim() }.joinToString("|")
|
||||||
if (signature == prevSignature) {
|
if (signature == prevSignature) {
|
||||||
log("回读:已滚动到顶部(第 $i 次反向滑)")
|
stableCount++
|
||||||
|
if (stableCount >= 2) {
|
||||||
|
log("回读:已滚动到顶部(第 $i 次反向滑,连续 $stableCount 次稳定)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
stableCount = 0
|
||||||
|
}
|
||||||
prevSignature = signature
|
prevSignature = signature
|
||||||
val ok = kotlinx.coroutines.runBlocking {
|
val ok = kotlinx.coroutines.runBlocking {
|
||||||
service.gestures.swipe(0.5f, 0.30f, 0.5f, 0.70f)
|
service.gestures.swipe(0.5f, 0.30f, 0.5f, 0.70f)
|
||||||
@@ -162,6 +171,25 @@ class ToutiaoArticlePort(
|
|||||||
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
||||||
Thread.sleep(1_500); continue
|
Thread.sleep(1_500); continue
|
||||||
}
|
}
|
||||||
|
// ⓪′ 信用分门控遗留深层页(处罚中心/全部服务等)→ BACK 收拢回首页。
|
||||||
|
// 2026-11-17 真机两轮实锤:
|
||||||
|
// - 处罚中心 BACK 一跳到「全部服务」(有作品管理锚点但无顶部「发布」,
|
||||||
|
// 判据③不命中)→ 锚点须覆盖门控导航链沿途页面;
|
||||||
|
// - ⚠️ 创作中心页同样含「作品管理/创作工具/收益提现」字样但方向相反
|
||||||
|
// (要点「+发布」不是 BACK)——这些词不能进本判据;判据锚点限定
|
||||||
|
// 处罚中心专属词 + 「全部服务」页专属标题,且无首页底栏。
|
||||||
|
val deepAnchor = lines.any {
|
||||||
|
it.text.contains("处罚记录") || it.text.contains("账号处罚中心") ||
|
||||||
|
it.text.contains("全部服务") || it.text.contains("信用分") ||
|
||||||
|
it.text.contains("治理公告")
|
||||||
|
} && !lines.any { it.text.trim() == "首页" && (it.boundingBox?.top ?: 0) > height * 0.85 } &&
|
||||||
|
// 排除创作中心:有顶部「发布」或「作品管理+数据助手」组合走判据③
|
||||||
|
!lines.any { it.text.contains("发布") && (it.boundingBox?.top ?: Int.MAX_VALUE) < height * 0.12 }
|
||||||
|
if (deepAnchor) {
|
||||||
|
log("导航:信用分门控遗留深层页,BACK 回首页")
|
||||||
|
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
||||||
|
Thread.sleep(1_500); continue
|
||||||
|
}
|
||||||
// ① 已在编辑器空稿
|
// ① 已在编辑器空稿
|
||||||
if (editorMarkers(lines)) return true
|
if (editorMarkers(lines)) return true
|
||||||
// ② 发布面板(微头条撰写页)→「文章」Tab(底部)。
|
// ② 发布面板(微头条撰写页)→「文章」Tab(底部)。
|
||||||
|
|||||||
@@ -22,7 +22,14 @@ object SourceRegistry {
|
|||||||
SourceDefinition("zhihu", "知乎", "com.zhihu.android"),
|
SourceDefinition("zhihu", "知乎", "com.zhihu.android"),
|
||||||
SourceDefinition("xiaohongshu", "小红书", "com.xingin.xhs"),
|
SourceDefinition("xiaohongshu", "小红书", "com.xingin.xhs"),
|
||||||
SourceDefinition("weibo", "微博", "com.sina.weibo"),
|
SourceDefinition("weibo", "微博", "com.sina.weibo"),
|
||||||
SourceDefinition("douyin", "抖音", "com.ss.android.ugc.aweme"),
|
// 抖音(2026-11-17 验收):MediaProjection 数据源+OCR 解析+单条详情采集全链通过
|
||||||
|
// 能力:HOT_LIST(热榜解析 4~6 条)+ DETAIL(详情观察 outcome=已观察 phase=DONE)
|
||||||
|
// SHARE_LINK/MEDIA_IMPORT 未取证,不列入
|
||||||
|
SourceDefinition(
|
||||||
|
id = "douyin", label = "抖音", packageName = "com.ss.android.ugc.aweme",
|
||||||
|
verifiedVersions = setOf("39.8.0"),
|
||||||
|
capabilities = setOf(SourceCapability.HOT_LIST, SourceCapability.DETAIL),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun find(id: String): SourceDefinition? = definitions.firstOrNull { it.id == id }
|
fun find(id: String): SourceDefinition? = definitions.firstOrNull { it.id == id }
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音详情页解析结果(2026-11-16 e1 取证口径)。
|
||||||
|
*
|
||||||
|
* 详情页 = 搜索结果页(词条自动填入搜索框):
|
||||||
|
* 热榜 TOP10 横条(5630.1万人在看)+ 综合/视频/图文/用户/直播/商品 Tab + 内容卡。
|
||||||
|
* 作者/正文/相对时间「3天前」在自绘区(e1 截图实证)——OCR 行为唯一输入源,
|
||||||
|
* 树内字段(互动数等)形态尚未 e2 核验,核验前一律 null。
|
||||||
|
*/
|
||||||
|
data class DouyinDetail(
|
||||||
|
val author: String? = null,
|
||||||
|
val content: String? = null,
|
||||||
|
val publishedAtText: String? = null,
|
||||||
|
val publishedAtMs: Long? = null,
|
||||||
|
val unknownReason: String = "",
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 单条抖音观察结果(采集机输出)。 */
|
||||||
|
data class DouyinPostObservation(
|
||||||
|
val hotEntry: DouyinHotEntry? = null,
|
||||||
|
val author: String? = null,
|
||||||
|
val content: String? = null,
|
||||||
|
val publishedAtText: String? = null,
|
||||||
|
val publishedAtMs: Long? = null,
|
||||||
|
val sourceUrl: String? = null,
|
||||||
|
val fetchedAtMs: Long = 0,
|
||||||
|
val runGeneration: Long = 0,
|
||||||
|
val unknowns: List<String> = emptyList(),
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音详情解析器(骨架:只落已核验口径,未核验字段显式留 null)。
|
||||||
|
*
|
||||||
|
* 时间白名单(e1 实测「3天前」相对时间形态):相对时间折算绝对时刻;
|
||||||
|
* 「昨天」「X小时前」「X分钟前」为常见形态一并支持;绝对日期形态(如「11-15」)未取证,不认。
|
||||||
|
* 作者行启发式(OCR 行首「@昵称」)未核验——暂不启用,作者恒 null 待 e2 取证。
|
||||||
|
*/
|
||||||
|
object DouyinDetailParser {
|
||||||
|
private val RELATIVE_PATTERNS = listOf(
|
||||||
|
Regex("^(\\d+)分钟前$") to 60_000L,
|
||||||
|
Regex("^(\\d+)小时前$") to 3_600_000L,
|
||||||
|
Regex("^(\\d+)天前$") to 86_400_000L,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun parse(tree: com.haorui.app.crossplatform.source.SourceNode, ocrLines: List<String>, nowMs: Long): DouyinDetail {
|
||||||
|
// 树内字段形态未核验(e2 待做):不从树读任何字段,全部留 null。
|
||||||
|
val published = parseRelativeTime(ocrLines, nowMs)
|
||||||
|
return DouyinDetail(
|
||||||
|
author = null,
|
||||||
|
content = null,
|
||||||
|
publishedAtText = published?.first,
|
||||||
|
publishedAtMs = published?.second,
|
||||||
|
unknownReason = if (published == null) "详情 OCR 未读到已核验时间形态" else "",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** OCR 行内取第一个命中白名单的相对时间;形态未核验不认。 */
|
||||||
|
internal fun parseRelativeTime(ocrLines: List<String>, nowMs: Long): Pair<String, Long>? {
|
||||||
|
ocrLines.forEach { raw ->
|
||||||
|
val line = raw.trim()
|
||||||
|
RELATIVE_PATTERNS.forEach { (pattern, unitMs) ->
|
||||||
|
val match = pattern.matchEntire(line) ?: return@forEach
|
||||||
|
val value = match.groupValues[1].toIntOrNull() ?: return@forEach
|
||||||
|
if (value < 0 || value > 365) return@forEach
|
||||||
|
return line to (nowMs - value * unitMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,500 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.os.SystemClock
|
||||||
|
import android.view.accessibility.AccessibilityNodeInfo
|
||||||
|
import com.haorui.app.automation.HaoRuiAccessibilityService
|
||||||
|
import com.haorui.app.automation.NodeLocator
|
||||||
|
import com.haorui.app.automation.RunLogger
|
||||||
|
import com.haorui.app.crossplatform.source.SourceBounds
|
||||||
|
import com.haorui.app.crossplatform.source.SourceNode
|
||||||
|
import com.haorui.app.crossplatform.source.SourceNodeAccessibility
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音采集真机驱动([DouyinHotListCollector.Port] 实现,2026-11-16 e1 取证口径)。
|
||||||
|
*
|
||||||
|
* 入口链锚点(e1 dump 实证):
|
||||||
|
* - 首页右上「搜索」按钮:content-desc="搜索"、clickable、x>900、y<300;
|
||||||
|
* - 搜索页「抖音热榜」Tab:content-desc 以“抖音热榜”开头(选中态带“已选中”后缀),
|
||||||
|
* **页内切换不换 Activity**(e1 实证:focus 恒为 SearchResultActivity);
|
||||||
|
* - 热榜列表自绘渲染(XML 树无词条文本)→ OCR 行解析;
|
||||||
|
* - 词条点按按解析行 bounds 定位(e1 教训:屏上估算行位偏移一行,禁止盲估)。
|
||||||
|
*
|
||||||
|
* 详情页「投稿」「分享」按钮为外发动作红线,Port 不提供任何触发它们的方法。
|
||||||
|
*/
|
||||||
|
internal class DouyinDevicePort(
|
||||||
|
private val service: HaoRuiAccessibilityService,
|
||||||
|
) : DouyinHotListCollector.Port {
|
||||||
|
private companion object {
|
||||||
|
const val TAG = "Douyin-Port"
|
||||||
|
const val DOUYIN_PKG = "com.ss.android.ugc.aweme"
|
||||||
|
const val WAIT_STEP_MS = 400L
|
||||||
|
/** 榜单 Tab 行 y 区间(e1 实测 [299,1118][531,1190] 一带;键盘/弹层遮挡时此区间无匹配)。 */
|
||||||
|
const val TAB_Y_MIN = 900
|
||||||
|
const val TAB_Y_MAX = 1500
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 基础工具(与知乎/微博 Port 同型) ─────────────────────
|
||||||
|
|
||||||
|
private fun log(message: String) = RunLogger.i(TAG, message)
|
||||||
|
|
||||||
|
private fun tree(): SourceNode? = service.root()?.let { SourceNodeAccessibility.from(it) }
|
||||||
|
|
||||||
|
private fun waitTree(timeoutMs: Long, until: (SourceNode) -> Boolean): Boolean {
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + timeoutMs
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline) {
|
||||||
|
val t = tree()
|
||||||
|
if (t != null && until(t)) return true
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 活树有界遍历找节点(供坐标点击;抖音热榜 Tab 为不可点击 ViewGroup,需按 bounds 手势点)。 */
|
||||||
|
private fun liveFind(
|
||||||
|
root: AccessibilityNodeInfo?,
|
||||||
|
budget: Int = 3_000,
|
||||||
|
predicate: (AccessibilityNodeInfo, android.graphics.Rect) -> Boolean,
|
||||||
|
): android.graphics.Rect? {
|
||||||
|
if (root == null) return null
|
||||||
|
var visited = 0
|
||||||
|
val rect = android.graphics.Rect()
|
||||||
|
fun walk(node: AccessibilityNodeInfo): android.graphics.Rect? {
|
||||||
|
if (visited++ > budget) return null
|
||||||
|
runCatching { node.getBoundsInScreen(rect) }
|
||||||
|
if (predicate(node, rect)) return android.graphics.Rect(rect)
|
||||||
|
for (i in 0 until node.childCount) {
|
||||||
|
val child = node.getChild(i) ?: continue
|
||||||
|
val found = try { walk(child) } finally { runCatching { child.recycle() } }
|
||||||
|
if (found != null) return found
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return walk(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单屏截屏(MediaProjection 优先,回退 takeScreenshot)。
|
||||||
|
* ⚠️ r27 实锤:投影就绪时**不回退 takeScreenShot**——runBlocking+Dispatchers.Main
|
||||||
|
* 在前台协程中会死锁(主线程被 runBlocking 堵住,withContext(Main) 截屏永远排队不上)。
|
||||||
|
* 投影就绪但无帧时返回 null,由调用方处理(不走 runBlocking)。
|
||||||
|
*/
|
||||||
|
private fun captureScreen(): Bitmap? {
|
||||||
|
val projFrame = com.haorui.app.ocr.ProjectionCapturer.capture()
|
||||||
|
if (projFrame != null) {
|
||||||
|
log("截屏走投影通道 ${projFrame.width}x${projFrame.height}")
|
||||||
|
return projFrame
|
||||||
|
}
|
||||||
|
// 投影未就绪才走 takeScreenshot(runBlocking 在后台线程安全)
|
||||||
|
if (com.haorui.app.ocr.ProjectionHolder.isReady) {
|
||||||
|
log("投影已就绪但无帧(frameCount 可能为 0),返回 null 不走 runBlocking")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
log("投影未就绪,走 takeScreenshot")
|
||||||
|
return kotlinx.coroutines.runBlocking {
|
||||||
|
com.haorui.app.ocr.ScreenCapturer(service).capture()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ocrCurrentScreen(): List<String> {
|
||||||
|
val bitmap: Bitmap = captureScreen() ?: return emptyList()
|
||||||
|
return try {
|
||||||
|
val blocks = try {
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
kotlinx.coroutines.withTimeout(8_000) {
|
||||||
|
com.haorui.app.ocr.OcrProcessor.recognize(bitmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) { emptyList() }
|
||||||
|
blocks.flatMap { it.lines }.map { it.text.trim() }.filter { it.isNotEmpty() }
|
||||||
|
} finally {
|
||||||
|
bitmap.recycle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** OCR 行轮询等待:until 命中即返回 true(有上限)。超时打印末轮采样辅助诊断。 */
|
||||||
|
private fun waitOcr(timeoutMs: Long, until: (List<String>) -> Boolean, tagForDebug: String = ""): Boolean {
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + timeoutMs
|
||||||
|
var lastLines: List<String> = emptyList()
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline) {
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
lastLines = lines
|
||||||
|
if (lines.isNotEmpty() && until(lines)) return true
|
||||||
|
Thread.sleep(1_000) // OCR 有成本,轮询间隔放宽
|
||||||
|
}
|
||||||
|
if (tagForDebug.isNotEmpty()) {
|
||||||
|
log("OCR 判据超时[$tagForDebug] 末轮 ${lastLines.size} 行采样: ${lastLines.take(8)}")
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** OCR 定位含指定文本的行,返回该行 bounds(截屏坐标系);找不到返回 null。 */
|
||||||
|
private fun ocrFindLine(fragment: String): android.graphics.Rect? =
|
||||||
|
ocrFindLineWithBounds(fragment)?.second
|
||||||
|
|
||||||
|
/** OCR 定位含指定文本的行,返回(行文本, 行 bounds);找不到返回 null。 */
|
||||||
|
private fun ocrFindLineWithBounds(fragment: String): Pair<String, android.graphics.Rect>? {
|
||||||
|
val bitmap: Bitmap = captureScreen() ?: return null
|
||||||
|
return try {
|
||||||
|
val blocks = kotlinx.coroutines.runBlocking { com.haorui.app.ocr.OcrProcessor.recognize(bitmap) }
|
||||||
|
blocks.asSequence()
|
||||||
|
.flatMap { it.lines.asSequence() }
|
||||||
|
.mapNotNull { line -> line.boundingBox?.let { rect -> line to rect } }
|
||||||
|
.firstOrNull { (line, _) -> line.text.replace(" ", "").contains(fragment) }
|
||||||
|
?.let { (line, rect) -> line.text to rect }
|
||||||
|
} finally {
|
||||||
|
bitmap.recycle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Port 实现 ────────────────────────────────────────────
|
||||||
|
|
||||||
|
override fun ensureAppForeground(): Boolean {
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + 25_000
|
||||||
|
var backs = 0
|
||||||
|
var launches = 0
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline) {
|
||||||
|
// ⚠️ 包名判断兜底:抖音 Splash 常驻壳/沉浸视频页下 root().packageName 可能为 null
|
||||||
|
// (首跑实锤:launchApp 成功后 currentPackage() 仍判非抖音 → 死循环拉起)。
|
||||||
|
// 策略:只拉起一次,之后改用「树内有底栏 Tab」判定就绪——树读得到就是前台可操作。
|
||||||
|
val pkg = service.currentPackage()
|
||||||
|
if (pkg != DOUYIN_PKG) {
|
||||||
|
if (launches >= 1) {
|
||||||
|
// 已拉起过仍读不到包名:用树就绪判据直接验证(Splash 壳下的视频页是常态)
|
||||||
|
val readyByTree = tree()?.let { t ->
|
||||||
|
val flat = t.selfAndDescendants()
|
||||||
|
flat.any { n -> n.text == "首页" && (n.bounds?.top ?: 0) > 2_000 } &&
|
||||||
|
flat.any { n -> n.text == "我" && (n.bounds?.top ?: 0) > 2_000 }
|
||||||
|
} == true
|
||||||
|
if (readyByTree) {
|
||||||
|
log("包名不可读但树就绪(Splash 壳),按前台处理")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
launches++
|
||||||
|
service.launchApp(DOUYIN_PKG)
|
||||||
|
Thread.sleep(1_500)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val root = service.root()
|
||||||
|
if (root == null) {
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 开屏广告/弹窗:只点「跳过」,不点广告本体(知乎同款口径)
|
||||||
|
val skip = NodeLocator.byTextContains(root, "跳过")
|
||||||
|
if (skip != null) {
|
||||||
|
runCatching { kotlinx.coroutines.runBlocking { service.gestures.tapNode(skip) } }
|
||||||
|
.onSuccess { log("开屏广告跳过") }
|
||||||
|
runCatching { skip.recycle() }
|
||||||
|
Thread.sleep(1_000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 就绪判据:底栏「首页」+「我」同在屏(y>2000,e1 实测底栏 y≈2175)
|
||||||
|
val ready = tree()?.let { t ->
|
||||||
|
val flat = t.selfAndDescendants()
|
||||||
|
flat.any { n -> n.text == "首页" && (n.bounds?.top ?: 0) > 2_000 } &&
|
||||||
|
flat.any { n -> n.text == "我" && (n.bounds?.top ?: 0) > 2_000 }
|
||||||
|
} == true
|
||||||
|
if (ready) return true
|
||||||
|
// 过渡态残留:有界 BACK 收拢
|
||||||
|
if (backs < 3) {
|
||||||
|
backs++
|
||||||
|
service.gestures.back()
|
||||||
|
log("残留页面收拢:第 $backs 次返回")
|
||||||
|
Thread.sleep(1_000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
}
|
||||||
|
log("进入抖音前台失败")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun openSearch(): Boolean {
|
||||||
|
// 右上「搜索」:desc="搜索"、clickable、x>900、y<300(e1 dump 实证 [924,108][1080,240])。
|
||||||
|
// 搜索钮本身在首页树可达(desc 形态);就绪判据走 OCR(搜索页内容树不可达,r4 实证)。
|
||||||
|
// ⚠️ r12 实锤:上次采集残留的词条详情页会让点搜索钮直接跳详情——先 OCR 检测
|
||||||
|
// 详情页特征(热榜TOP/万人在看),命中则 BACK 回搜索主页再继续。
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + 15_000
|
||||||
|
var logged = false
|
||||||
|
var backs = 0
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline) {
|
||||||
|
// 详情残留排除:BACK 收拢(有上限)
|
||||||
|
val onDetail = runCatching { ocrCurrentScreen() }.getOrDefault(emptyList()).any {
|
||||||
|
it.replace(" ", "").contains("热榜TOP") || it.contains("万人在看")
|
||||||
|
}
|
||||||
|
if (onDetail && backs < 3) {
|
||||||
|
backs++
|
||||||
|
service.gestures.back()
|
||||||
|
log("检测到词条详情残留,BACK $backs 次收拢")
|
||||||
|
Thread.sleep(1_000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val root = service.root()
|
||||||
|
val rect = root?.let {
|
||||||
|
liveFind(it, budget = 2_000) { node, r ->
|
||||||
|
node.contentDescription?.toString() == "搜索" &&
|
||||||
|
node.isClickable && r.left > 900 && r.top < 300
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rect != null) {
|
||||||
|
if (!logged) { log("定位到搜索钮 bounds=$rect"); logged = true }
|
||||||
|
// r27 实锤:runBlocking+tapAt 在前台协程可能死锁——加超时兜底
|
||||||
|
val ok = try {
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
kotlinx.coroutines.withTimeout(5_000) {
|
||||||
|
service.gestures.tapAt(rect.centerX(), rect.centerY(), retry = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) { false }
|
||||||
|
if (ok) {
|
||||||
|
// 就绪判据走 OCR:搜索页特有锚点「猜你想看」在屏,且**详情页特征不在屏**。
|
||||||
|
// ⚠️ r33 实锤:搜索按钮点击后可能停留在「上热门」页(Tab 行=「上热门话題榜|宁波榜|直播榜」)——
|
||||||
|
// 必须等「猜你想看」出现(搜索页 Tab 行锚点)才算进入搜索页。
|
||||||
|
val entered = waitOcr(12_000, until = { lines ->
|
||||||
|
val hasSearchAnchor = lines.any { line ->
|
||||||
|
val clean = line.replace(" ", "")
|
||||||
|
clean.contains("猜你想看") || clean.contains("语音搜索") || clean.contains("展开更多历史")
|
||||||
|
}
|
||||||
|
val onDetail = lines.any { it.replace(" ", "").contains("热榜TOP") || it.contains("万人在看") }
|
||||||
|
hasSearchAnchor && !onDetail
|
||||||
|
}, tagForDebug = "search-page")
|
||||||
|
if (entered) return true
|
||||||
|
}
|
||||||
|
} else if (!logged) {
|
||||||
|
log("搜索钮未定位(树${if (root == null) "空" else "有"},抖音可能未落首页)")
|
||||||
|
}
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
}
|
||||||
|
log("搜索入口未打开")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun openHotListTab(): Boolean {
|
||||||
|
// 「抖音热榜」Tab:树不可达(r4 实证),按 OCR 行 bounds 定位点击;
|
||||||
|
// 选中态判据 = 热榜列表行出现(「排名+标题+热度」形态,见 DouyinHotListParser)。
|
||||||
|
// ⚠️ r9 实锤:OCR 把 Tab 行识别为「猜你想看 抖音热榜」(行只含前两词),
|
||||||
|
// 「抖音热榜」词中心≈行宽 76%(e1 校准 x=404/行宽 530)。
|
||||||
|
// ⚠️ r10 实锤:BACK 收键盘可能连搜索页一起退出(OCR 找不到 Tab 行)——
|
||||||
|
// 此时返回 false 让采集机归 OPEN_HOT_TAB 失败;改为**不主动 BACK**,
|
||||||
|
// 先直接尝试找 Tab 行(r9 已证浮层下的 Tab 行 OCR 仍可读可点),
|
||||||
|
// 只有连续找不到才 BACK 一次重试。
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + 60_000
|
||||||
|
// ⚠️ r30 实锤:Tab 行 y 位置随搜索词/广告横幅动态变化(e1 校准 y=1154 不可靠)。
|
||||||
|
// 修法:OCR 动态定位 Tab 行,按行 bounds 中心点击;找不到则点顶部空白区重试。
|
||||||
|
// ⚠️ r32:OCR 对「抖音热榜」可能误读为「抖音热板」「抖音热様」等——用「热榜」宽松匹配。
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
service.gestures.tapAt(540, 80, retry = false)
|
||||||
|
}
|
||||||
|
Thread.sleep(1_500)
|
||||||
|
log("进入热榜 Tab 前点顶部空白区关浮层")
|
||||||
|
var attempt = 0
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline && attempt < 5) {
|
||||||
|
// 宽松匹配:「热榜」比「抖音热榜」更抗 OCR 误读
|
||||||
|
val line = ocrFindLineWithBounds("热榜")
|
||||||
|
if (line == null) {
|
||||||
|
// 诊断:打印含"榜"的行(定位 OCR 读到了什么)
|
||||||
|
val sample = ocrCurrentScreen().filter { it.contains("榜") }.take(3)
|
||||||
|
log("Tab 行不可读,含「榜」行采样: $sample")
|
||||||
|
Thread.sleep(2_000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val (text, rect) = line
|
||||||
|
// 按 OCR 行 bounds 中心点击(行含「猜你想看 抖音热榜」两词,中心偏右命中「抖音热榜」)
|
||||||
|
val x = rect.left + (rect.width() * 0.7).toInt()
|
||||||
|
val y = rect.centerY()
|
||||||
|
log("点热榜 Tab:attempt=$attempt x=$x y=$y 行文本=${text.take(30)} 行bounds=$rect")
|
||||||
|
val ok = try {
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
kotlinx.coroutines.withTimeout(5_000) {
|
||||||
|
service.gestures.tapAt(x, y, retry = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) { false }
|
||||||
|
if (ok) {
|
||||||
|
attempt++
|
||||||
|
log("Tab 点击已发(信任直行),静默 12 秒后推进")
|
||||||
|
Thread.sleep(12_000)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
Thread.sleep(WAIT_STEP_MS)
|
||||||
|
}
|
||||||
|
log("「抖音热榜」Tab 未切换成功")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readHotListOcrLines(): List<String> {
|
||||||
|
// 榜单渲染稳定后采集。
|
||||||
|
// 【帧追赶·Tab 点触版】r22 实证:滚动(半屏×5)推不动缓存(49 行全旧帧),
|
||||||
|
// r21 微手势同样无效;r20 唯一命中的刷新源是 **Tab 点击事件本身**。
|
||||||
|
// 策略:第 0 屏直读(Tab 点击刚推过一帧)→ 后续每轮**轻点 Tab 坐标**
|
||||||
|
// (点击已选中的 Tab 无副作用,不切页不滚动)→ 静默 → 直读收新行。
|
||||||
|
// 直到解析 ≥8 条或连续 2 轮无新行或 5 轮用尽。
|
||||||
|
val collected = linkedSetOf<String>()
|
||||||
|
var bestParsed = 0
|
||||||
|
val maxRounds = 5
|
||||||
|
val targetParsed = 8
|
||||||
|
// 第 0 屏:不动作直接读(信任直行的静默刚过,帧最新)
|
||||||
|
run {
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
collected.addAll(lines)
|
||||||
|
val merged = com.haorui.app.crossplatform.source.douyin.DouyinHotListParser.mergeAdjacentLines(collected.toList())
|
||||||
|
val parsed = com.haorui.app.crossplatform.source.douyin.DouyinHotListParser.parse(collected.toList())
|
||||||
|
bestParsed = maxOf(bestParsed, parsed.size)
|
||||||
|
log("帧追赶第 0 屏(直读):${lines.size} 行,合并后 ${merged.size} 行,解析 ${bestParsed} 条")
|
||||||
|
// 诊断:打印合并后含数字的行(定位解析失败原因)
|
||||||
|
val digitLines = merged.filter { it.any { c -> c.isDigit() } }
|
||||||
|
log("合并后含数字行(${digitLines.size} 条): ${digitLines.take(10).joinToString(" | ")}")
|
||||||
|
}
|
||||||
|
var noFreshRounds = 0
|
||||||
|
for (round in 1..maxRounds) {
|
||||||
|
if (bestParsed >= targetParsed || noFreshRounds >= 2) break
|
||||||
|
// 轻点「抖音热榜」Tab:e1 dump 校准的**绝对坐标** (404,1154)。
|
||||||
|
// ⚠️ r23 实锤:OCR 行内比例定位不稳定(行内容每次解读不同),比例点过界
|
||||||
|
// 会切回「猜你想看」页——改绝对坐标主攻;且只点一次成功后不再补点。
|
||||||
|
kotlinx.coroutines.runBlocking {
|
||||||
|
service.gestures.tapAt(404, 1154, retry = false)
|
||||||
|
}
|
||||||
|
Thread.sleep(4_000) // 点击事件传播+快照刷新窗口
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
val fresh = lines.count { collected.add(it) }
|
||||||
|
bestParsed = maxOf(bestParsed, DouyinHotListParser.parse(collected.toList()).size)
|
||||||
|
log("帧追赶第 $round 轮(点 Tab 后):本屏 ${lines.size} 行(新 $fresh),累计 ${collected.size},解析 ${bestParsed} 条")
|
||||||
|
if (fresh == 0) noFreshRounds++ else noFreshRounds = 0
|
||||||
|
}
|
||||||
|
log("帧追赶完成:累计 ${collected.size} 行,最优解析 $bestParsed 条")
|
||||||
|
return collected.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun openEntry(index: Int): Boolean {
|
||||||
|
// ⚠️ r31 实锤:collectOne 和 openEntry 读不同帧导致 entry 不一致——
|
||||||
|
// collectOne 挑的 entry[0] 到 openEntry 时序号变了。
|
||||||
|
// 修法:openEntry 自己重读解析,按**标题碎片**匹配 OCR 行块(不依赖 index)。
|
||||||
|
// ⚠️ 2026-11-17 真机:帧追赶末轮截屏后立即再拍命中 takeScreenshot 限流
|
||||||
|
// (errorCode=3)→ 重读解析 0 条直接失败。先退避再拍,空解析重试一次。
|
||||||
|
val parsed: List<com.haorui.app.crossplatform.source.douyin.DouyinHotEntry> = buildList {
|
||||||
|
for (attempt in 1..2) {
|
||||||
|
Thread.sleep(1_300) // 截屏限流退避(系统配额约 1s+)
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
val p = DouyinHotListParser.parse(lines)
|
||||||
|
if (p.isNotEmpty()) {
|
||||||
|
addAll(p); break
|
||||||
|
}
|
||||||
|
log("openEntry 重读解析 0 条(第 $attempt 次)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parsed.isEmpty()) {
|
||||||
|
log("openEntry 重读两次均 0 条,放弃")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 优先用 index 对应的 entry,找不到则用第 0 条
|
||||||
|
val entry = parsed.getOrNull(index) ?: parsed[0]
|
||||||
|
val titleFragment = entry.title.take(8)
|
||||||
|
val bitmap: Bitmap? = captureScreen()
|
||||||
|
val target = bitmap?.let { bmp ->
|
||||||
|
try {
|
||||||
|
val blocks = kotlinx.coroutines.runBlocking { com.haorui.app.ocr.OcrProcessor.recognize(bmp) }
|
||||||
|
blocks.asSequence()
|
||||||
|
.flatMap { it.lines.asSequence() }
|
||||||
|
.mapNotNull { line -> line.boundingBox?.let { rect -> line to rect } }
|
||||||
|
.firstOrNull { (line, _) -> line.text.replace(" ", "").contains(titleFragment) }
|
||||||
|
?.second
|
||||||
|
} finally {
|
||||||
|
bmp.recycle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target == null || target.width() <= 0) {
|
||||||
|
log("词条「${entry.title.take(12)}」OCR 行块定位失败")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val ok = kotlinx.coroutines.runBlocking {
|
||||||
|
service.gestures.tapAt(target.centerX(), target.centerY(), retry = false)
|
||||||
|
}
|
||||||
|
if (!ok) return false
|
||||||
|
// 就绪判据走 OCR:热榜 TOP10 横条出现(详情页=搜索结果页顶部横条,e1 实证「热榜 TOP10 5630.1万人在看」)
|
||||||
|
val entered = waitOcr(8_000, until = { lines ->
|
||||||
|
lines.any { it.replace(" ", "").contains("热榜TOP") || it.contains("万人在看") }
|
||||||
|
}, tagForDebug = "entry-detail")
|
||||||
|
if (!entered) {
|
||||||
|
log("词条详情未打开(热榜 TOP 横条未出现)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readDetailOcrLines(): List<String> {
|
||||||
|
Thread.sleep(800) // 详情渲染稳定
|
||||||
|
return ocrCurrentScreen()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情页逐屏全文 OCR(AI 创作链材料,2026-11-17):半屏上滑+行序去重,最多 [maxScreens] 屏。
|
||||||
|
* 仿微博 readPostOcrFullText;滑动幅度 0.72→0.34(抖音详情=搜索结果页,卡片密集防跨卡)。
|
||||||
|
* 调用时机:必须在详情页仍在前台时(collectOne 的 onDetail 钩子)——EXIT 后读到的是榜单。
|
||||||
|
*/
|
||||||
|
fun readDetailOcrFullText(maxScreens: Int = 4): List<String> {
|
||||||
|
val allLines = mutableListOf<String>()
|
||||||
|
val seen = HashSet<String>()
|
||||||
|
var noNewCount = 0
|
||||||
|
for (screen in 0 until maxScreens) {
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
if (lines.isEmpty()) {
|
||||||
|
log("详情全文 OCR 第 $screen 屏识别失败,继续尝试")
|
||||||
|
Thread.sleep(1_000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var appended = 0
|
||||||
|
lines.forEach { line ->
|
||||||
|
val text = line.trim()
|
||||||
|
if (text.isNotEmpty() && seen.add(text)) {
|
||||||
|
allLines.add(text)
|
||||||
|
appended++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("详情全文 OCR 第 $screen 屏:识别 ${lines.size} 行,新增 $appended 行")
|
||||||
|
// 页底判定:连续两屏无新行(微博同款口径)
|
||||||
|
if (appended == 0) {
|
||||||
|
noNewCount++
|
||||||
|
if (noNewCount >= 2) {
|
||||||
|
log("详情全文 OCR 连续两屏无新行,判定到页底")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
noNewCount = 0
|
||||||
|
}
|
||||||
|
val scrolled = kotlinx.coroutines.runBlocking {
|
||||||
|
service.gestures.swipe(0.5f, 0.72f, 0.5f, 0.34f)
|
||||||
|
}
|
||||||
|
if (!scrolled) {
|
||||||
|
log("详情全文 OCR 第 $screen 屏滑动失败,终止")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
Thread.sleep(1_200)
|
||||||
|
}
|
||||||
|
return allLines
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readDetailTree(): SourceNode = tree() ?: SourceNode()
|
||||||
|
|
||||||
|
override fun backToHotList(): Boolean {
|
||||||
|
// 详情→热榜:一次 BACK(详情=搜索结果页内的词条视图)。
|
||||||
|
// 判据走 OCR:「抖音热榜」Tab 行回到屏上(树不可达,r4 实证)。
|
||||||
|
val deadline = SystemClock.elapsedRealtime() + 10_000
|
||||||
|
var backs = 0
|
||||||
|
while (SystemClock.elapsedRealtime() < deadline && backs < 4) {
|
||||||
|
if (service.currentPackage() != DOUYIN_PKG && service.currentPackage() != null) return false
|
||||||
|
val backOnList = runCatching { ocrFindLine("抖音热榜") }.getOrNull() != null
|
||||||
|
if (backOnList) return true
|
||||||
|
service.gestures.back()
|
||||||
|
backs++
|
||||||
|
Thread.sleep(1_000)
|
||||||
|
}
|
||||||
|
// 收尾不强求回热榜:BACK 兜底收拢弹层后让出前台(采集机 finally 口径)
|
||||||
|
runCatching { service.gestures.back() }
|
||||||
|
log("退出导航:BACK $backs 次后收尾")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+178
@@ -0,0 +1,178 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
import com.haorui.app.crossplatform.source.SourceNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音热榜采集状态机(骨架,2026-11-16 e1 取证口径)。
|
||||||
|
*
|
||||||
|
* 入口链(e1 实测):
|
||||||
|
* 首页右上「搜索」按钮 → 搜索页(SearchResultActivity)→「抖音热榜」Tab(**页内切换不换 Activity**,
|
||||||
|
* content-desc 带“已选中”状态可读)→ 热榜列表(自绘渲染,OCR 主路线)→ 点词条 → 详情(同为搜索结果页)。
|
||||||
|
*
|
||||||
|
* 约束(继承微博/知乎经验 + e1 教训):
|
||||||
|
* - 一次候选完成才让出前台,失败都走 EXIT 安全退出;
|
||||||
|
* - 缺失字段保留未知(进 unknowns),不从行序、图标或无关文本推断;
|
||||||
|
* - 词条点按必须按解析结果的行 bounds 定位(e1 教训:屏上估算行位偏移一行);
|
||||||
|
* - 详情页「投稿」按钮与「分享」按钮是外发动作红线,未取证前一律不可点击。
|
||||||
|
*
|
||||||
|
* 真机驱动通过 [Port] 接入;未完成真机适配前不注册任何能力,入口由 SourceRegistry 门控拦截。
|
||||||
|
*/
|
||||||
|
class DouyinHotListCollector(
|
||||||
|
private val port: Port,
|
||||||
|
private val nowMs: () -> Long = System::currentTimeMillis,
|
||||||
|
) {
|
||||||
|
/** 真机驱动接口:每个方法都是一次页面操作,实现方负责可见性核对,禁止盲点。 */
|
||||||
|
interface Port {
|
||||||
|
fun ensureAppForeground(): Boolean
|
||||||
|
/** 首页右上搜索按钮进入搜索页。 */
|
||||||
|
fun openSearch(): Boolean
|
||||||
|
/** 点「抖音热榜」Tab(页内切换);须核对“已选中”状态后才返回 true。 */
|
||||||
|
fun openHotListTab(): Boolean
|
||||||
|
/** 逐屏滚动采集热榜 OCR 文本行(含半屏上滑与行序去重,参照微博 readPostOcrFullText)。 */
|
||||||
|
fun readHotListOcrLines(): List<String>
|
||||||
|
/** 按解析出的条目行 bounds 点词条进详情;实现方必须先核对节点可见性。 */
|
||||||
|
fun openEntry(index: Int): Boolean
|
||||||
|
/** 详情页 OCR 文本行(作者/正文/相对时间在自绘区)。 */
|
||||||
|
fun readDetailOcrLines(): List<String>
|
||||||
|
/** 详情页可读节点树(互动数等树内字段,形态待 e2 核验)。 */
|
||||||
|
fun readDetailTree(): SourceNode
|
||||||
|
/** 安全退出:详情→热榜→(必要时)离开抖音前台收尾。 */
|
||||||
|
fun backToHotList(): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Phase {
|
||||||
|
OPEN_APP, OPEN_SEARCH, OPEN_HOT_TAB, READ_LIST,
|
||||||
|
OPEN_ENTRY, READ_DETAIL, SAVE_OBSERVATION, EXIT, DONE, FAILED,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 热榜清单结果:entries 为当屏快照(用户勾选/确认的数据源)。 */
|
||||||
|
data class ListResult(
|
||||||
|
val outcome: String,
|
||||||
|
val phase: Phase,
|
||||||
|
val entries: List<DouyinHotEntry> = emptyList(),
|
||||||
|
val reason: String = "",
|
||||||
|
val exitedSafely: Boolean = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 单条内容采集结果;失败相位即 [phase],观察到的未知字段进 unknowns。 */
|
||||||
|
data class Result(
|
||||||
|
val outcome: String,
|
||||||
|
val phase: Phase,
|
||||||
|
val observation: DouyinPostObservation? = null,
|
||||||
|
val reason: String = "",
|
||||||
|
val exitedSafely: Boolean = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 运行代际:停止/重启后递增,迟到的观察不得混入新代际。 */
|
||||||
|
var runGeneration: Long = 0
|
||||||
|
|
||||||
|
var phase: Phase = Phase.OPEN_APP
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** 拉取抖音热榜词条清单(OPEN_APP→…→READ_LIST→EXIT)。 */
|
||||||
|
fun collectHotList(): ListResult {
|
||||||
|
var entries: List<DouyinHotEntry> = emptyList()
|
||||||
|
var failure: String? = null
|
||||||
|
var failedAt: Phase? = null
|
||||||
|
var exitedSafely = false
|
||||||
|
try {
|
||||||
|
phase = Phase.OPEN_APP
|
||||||
|
if (!port.ensureAppForeground()) fail("抖音未能进入前台")
|
||||||
|
phase = Phase.OPEN_SEARCH
|
||||||
|
if (!port.openSearch()) fail("搜索入口未打开")
|
||||||
|
phase = Phase.OPEN_HOT_TAB
|
||||||
|
if (!port.openHotListTab()) fail("「抖音热榜」Tab 未切换成功")
|
||||||
|
phase = Phase.READ_LIST
|
||||||
|
entries = DouyinHotListParser.parse(port.readHotListOcrLines())
|
||||||
|
if (entries.isEmpty()) fail("热榜清单为空或 OCR 未读到合格行")
|
||||||
|
} catch (stop: StopRequest) {
|
||||||
|
failure = stop.message
|
||||||
|
failedAt = phase
|
||||||
|
} finally {
|
||||||
|
phase = Phase.EXIT
|
||||||
|
exitedSafely = runCatching { port.backToHotList() }.getOrDefault(false)
|
||||||
|
}
|
||||||
|
return ListResult(
|
||||||
|
outcome = if (failure == null) "已取得" else "失败",
|
||||||
|
phase = failedAt ?: Phase.DONE,
|
||||||
|
entries = entries,
|
||||||
|
reason = failure.orEmpty(),
|
||||||
|
exitedSafely = exitedSafely,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采集热榜第 [entryIndex] 条词条的详情观察。
|
||||||
|
* 详情页时间多为相对时间(「3天前」),唯一合法来源是详情 OCR 行;解析不出保留 null。
|
||||||
|
*
|
||||||
|
* @param onDetail 详情页仍在前台时回调(SAVE_OBSERVATION 之后、EXIT 之前),供调用方取全文材料。
|
||||||
|
* 回调异常吞掉,不影响采集结果。
|
||||||
|
*/
|
||||||
|
fun collectOne(entryIndex: Int, onDetail: (() -> Unit)? = null): Result {
|
||||||
|
var observation: DouyinPostObservation? = null
|
||||||
|
var failure: String? = null
|
||||||
|
var failedAt: Phase? = null
|
||||||
|
var exitedSafely = false
|
||||||
|
try {
|
||||||
|
phase = Phase.OPEN_APP
|
||||||
|
if (!port.ensureAppForeground()) fail("抖音未能进入前台")
|
||||||
|
phase = Phase.OPEN_SEARCH
|
||||||
|
if (!port.openSearch()) fail("搜索入口未打开")
|
||||||
|
phase = Phase.OPEN_HOT_TAB
|
||||||
|
if (!port.openHotListTab()) fail("「抖音热榜」Tab 未切换成功")
|
||||||
|
phase = Phase.READ_LIST
|
||||||
|
val entries = DouyinHotListParser.parse(port.readHotListOcrLines())
|
||||||
|
val entry = entries.getOrNull(entryIndex) ?: fail("热榜第 $entryIndex 条不存在")
|
||||||
|
|
||||||
|
phase = Phase.OPEN_ENTRY
|
||||||
|
if (!port.openEntry(entryIndex)) fail("词条「${entry.title.take(12)}」未打开")
|
||||||
|
phase = Phase.READ_DETAIL
|
||||||
|
// 先读 OCR 行再读树:详情页自绘内容以 OCR 为主,读取顺序固定(与相位记录一致)
|
||||||
|
val detailOcrLines = port.readDetailOcrLines()
|
||||||
|
val detail = DouyinDetailParser.parse(port.readDetailTree(), detailOcrLines, nowMs())
|
||||||
|
|
||||||
|
phase = Phase.SAVE_OBSERVATION
|
||||||
|
observation = DouyinPostObservation(
|
||||||
|
hotEntry = entry,
|
||||||
|
author = detail.author,
|
||||||
|
content = detail.content,
|
||||||
|
publishedAtText = detail.publishedAtText,
|
||||||
|
publishedAtMs = detail.publishedAtMs,
|
||||||
|
fetchedAtMs = nowMs(),
|
||||||
|
runGeneration = runGeneration,
|
||||||
|
unknowns = buildUnknowns(entry, detail),
|
||||||
|
)
|
||||||
|
// 详情页仍在前台:回调调用方取全文材料(异常吞掉——采集结果不受附属动作影响)
|
||||||
|
runCatching { onDetail?.invoke() }
|
||||||
|
} catch (stop: StopRequest) {
|
||||||
|
failure = stop.message
|
||||||
|
failedAt = phase
|
||||||
|
} finally {
|
||||||
|
phase = Phase.EXIT
|
||||||
|
exitedSafely = runCatching { port.backToHotList() }.getOrDefault(false)
|
||||||
|
}
|
||||||
|
return Result(
|
||||||
|
outcome = if (observation != null) "已观察" else "失败",
|
||||||
|
phase = failedAt ?: Phase.DONE,
|
||||||
|
observation = observation,
|
||||||
|
reason = failure.orEmpty(),
|
||||||
|
exitedSafely = exitedSafely,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class StopRequest(message: String) : RuntimeException(message)
|
||||||
|
|
||||||
|
private fun fail(reason: String): Nothing = throw StopRequest(reason)
|
||||||
|
|
||||||
|
/** 未知口径清单:把“没读到什么”显式记录,供筛选阶段按“缺值不伪造”处置。 */
|
||||||
|
private fun buildUnknowns(entry: DouyinHotEntry, detail: DouyinDetail): List<String> {
|
||||||
|
val unknowns = mutableListOf<String>()
|
||||||
|
if (entry.rank == null) unknowns += "排名未知(置顶行或 OCR 未读到独立排名)"
|
||||||
|
if (entry.heatValue == null) unknowns += "热度数值未知(原文=${entry.heatRaw ?: "缺失"})"
|
||||||
|
if (entry.label == null) unknowns += "标签未知(OCR 未读到独立标签词)"
|
||||||
|
if (detail.publishedAtMs == null) unknowns += "发布时间未知:${detail.unknownReason}"
|
||||||
|
if (detail.author == null) unknowns += "作者未知(详情 OCR 未读到)"
|
||||||
|
if (detail.content == null) unknowns += "正文未知(详情 OCR 未读到)"
|
||||||
|
return unknowns
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音热榜解析器(com.ss.android.ugc.aweme,2026-11-16 e1 取证形态)。
|
||||||
|
*
|
||||||
|
* 输入是 OCR 文本行(热榜列表自绘渲染,XML 树无词条文本——与微博排名/标签图片化同理,
|
||||||
|
* 但抖音连标题都只在 OCR 里)。
|
||||||
|
*
|
||||||
|
* 行形态(e1 实测):
|
||||||
|
* `1 习近平将同普京特朗普会晤 1165.9万`
|
||||||
|
* `2 第一视角记录APEC瞬间 热 1165.7万`
|
||||||
|
* `12 茉茉手势舞 挑战 918.4万`
|
||||||
|
* `习近平主席这样推介中国深圳`(置顶行:无排名、无热度)
|
||||||
|
*
|
||||||
|
* 解析口径:
|
||||||
|
* - 标题 = 行内去掉行首排名、行尾热度、独立标签词后的剩余文本;为空则整行拒绝(不伪造条目);
|
||||||
|
* - 排名 = 行首 1~2 位独立数字(跟空格分隔);置顶行无排名 → null,不按行序推断;
|
||||||
|
* - 标签 = 行中的独立词 热/新/挑战/辟谣(前后有空白分隔才认,标题内嵌“热”字不算);
|
||||||
|
* OCR 把标签与标题粘连(如「第一视角记录APEC瞬间热」无空格)时不剥离 → 标题保持原样、label=null;
|
||||||
|
* - 热度 = 行尾「数值+万」(1165.9万 → 11659000);纯「数值」不带万不认(可能是页码等噪音);
|
||||||
|
* 正常榜单行必有排名徽章(e1 实测):无排名的行一律拒绝(置顶行/官宣行/搜索历史/OCR 混入的
|
||||||
|
* 非榜单内容);有排名无热度保留条目并标 heatMissing。
|
||||||
|
*/
|
||||||
|
object DouyinHotListParser {
|
||||||
|
const val PACKAGE = "com.ss.android.ugc.aweme"
|
||||||
|
|
||||||
|
/** e1 实测标签词全集;未核验的新标签词不剥离,留在标题里待取证后补充。 */
|
||||||
|
internal val LABELS = setOf("热", "新", "挑战", "辟谣")
|
||||||
|
|
||||||
|
private val RANK_PREFIX = Regex("^(\\d{1,2})\\s*(.+)$")
|
||||||
|
private val HEAT_SUFFIX = Regex("[\\s]*([\\d]+(?:\\.[\\d]+)?)万\\s*$")
|
||||||
|
|
||||||
|
/** 解析 OCR 文本行为热榜条目;无条目返回空表,噪音行静默跳过。 */
|
||||||
|
fun parse(ocrLines: List<String>): List<DouyinHotEntry> {
|
||||||
|
val merged = mergeAdjacentLines(ocrLines)
|
||||||
|
return merged.mapIndexedNotNull { index, line -> parseLine(line, index) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OCR 行合并预处理:热榜一行「排名+标题+热度」常被 OCR 拆成 2~3 行
|
||||||
|
* (排名/标题/热度各一行),单独每行都匹配不到 RANK_PREFIX+标题+热度 → 全被拒。
|
||||||
|
* 合并规则(保守,只合并确定性的拆行形态):
|
||||||
|
* 1) 纯排名行(`^\d{1,2}$`)+ 纯标题行(无排名无热度)→ 拼成「排名 标题」;
|
||||||
|
* 2) 上一步结果 + 纯热度行(`^\d+(\.\d+)?万$`)→ 拼成「排名 标题 热度」;
|
||||||
|
* 3) 纯热度行紧跟已有条目行(含排名)→ 追加到该行末尾。
|
||||||
|
* 不确定的行原样保留(交给 parseLine 按原有规则判定)。
|
||||||
|
*/
|
||||||
|
internal fun mergeAdjacentLines(ocrLines: List<String>): List<String> {
|
||||||
|
val result = mutableListOf<String>()
|
||||||
|
var i = 0
|
||||||
|
while (i < ocrLines.size) {
|
||||||
|
val line = ocrLines[i].trim()
|
||||||
|
if (line.isEmpty()) { i++; continue }
|
||||||
|
|
||||||
|
// 纯排名行(1~2 位数字)
|
||||||
|
if (RANK_ONLY.matches(line)) {
|
||||||
|
val titleCandidate = ocrLines.getOrNull(i + 1)?.trim().orEmpty()
|
||||||
|
if (titleCandidate.isNotEmpty() && !RANK_ONLY.matches(titleCandidate) && !HEAT_ONLY.matches(titleCandidate)) {
|
||||||
|
var merged = "$line $titleCandidate"
|
||||||
|
var next = i + 2
|
||||||
|
// 紧跟纯热度行则追加
|
||||||
|
val heatCandidate = ocrLines.getOrNull(next)?.trim().orEmpty()
|
||||||
|
if (HEAT_ONLY.matches(heatCandidate)) {
|
||||||
|
merged = "$merged $heatCandidate"
|
||||||
|
next++
|
||||||
|
}
|
||||||
|
result += merged
|
||||||
|
i = next
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 纯热度行紧跟已有条目行(含排名)→ 追加到上一行
|
||||||
|
if (HEAT_ONLY.matches(line) && result.isNotEmpty() && RANK_PREFIX.matches(result.last())) {
|
||||||
|
result[result.size - 1] = result.last() + " " + line
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
result += line
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private val RANK_ONLY = Regex("^\\d{1,2}$")
|
||||||
|
private val HEAT_ONLY = Regex("^\\d+(?:\\.\\d+)?万$")
|
||||||
|
|
||||||
|
internal fun parseLine(rawLine: String, order: Int): DouyinHotEntry? {
|
||||||
|
var line = rawLine.trim()
|
||||||
|
if (line.isEmpty()) return null
|
||||||
|
|
||||||
|
// 0) 清洗排名前非数字前缀(OCR 常把 "|"、"。" 等混入排名前)
|
||||||
|
line = line.trimStart('|', '。', '·', '、', ' ', ' ')
|
||||||
|
|
||||||
|
var rest = line
|
||||||
|
// 1) 行首排名:1~2 位数字 + 可选空白。置顶/官宣行无排名。
|
||||||
|
// 标题首字符必须非数字(防「2026年APEC…」误匹配排名「2」)。
|
||||||
|
// 标题首字符不能是「:」(防时间戳「16:06」误匹配排名「16」)。
|
||||||
|
val rank = RANK_PREFIX.matchEntire(rest)?.let { m ->
|
||||||
|
val titlePart = m.groupValues[2]
|
||||||
|
if (titlePart.isEmpty() || titlePart[0].isDigit() || titlePart[0] == ':') null
|
||||||
|
else {
|
||||||
|
rest = titlePart
|
||||||
|
m.groupValues[1].toIntOrNull()?.takeIf { it in 1..99 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) 行尾热度:「数值+万」。纯数值不带万不认。
|
||||||
|
var heatRaw: String? = null
|
||||||
|
var heatValue: Long? = null
|
||||||
|
HEAT_SUFFIX.find(rest)?.let { m ->
|
||||||
|
heatRaw = m.groupValues[1] + "万"
|
||||||
|
rest = rest.removeRange(m.range)
|
||||||
|
}
|
||||||
|
heatValue = parseHeat(heatRaw)
|
||||||
|
|
||||||
|
// 3) 独立标签词:按空白分词后整词匹配;不剥离粘连词。
|
||||||
|
val words = rest.split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||||
|
var label: String? = null
|
||||||
|
val titleWords = words.filter { word ->
|
||||||
|
if (label == null && word in LABELS) { label = word; false } else true
|
||||||
|
}
|
||||||
|
val title = titleWords.joinToString(" ").trim()
|
||||||
|
// 标题最短 2 字符(防单字符噪音如「G」);标题中残留热度样式文本清理
|
||||||
|
val cleanedTitle = title.replace(Regex("\\d+(?:\\.\\d+)?万"), "").trim()
|
||||||
|
// 拒绝纯数字/小数点标题(OCR 噪音如「32.9」「.9」「100」)
|
||||||
|
if (cleanedTitle.length < 2 || cleanedTitle.all { it.isDigit() || it == '.' || it == ',' }) return null
|
||||||
|
|
||||||
|
// 无排名:正常榜单行必有排名徽章(e1 实测);置顶行/官宣行/搜索历史等均无排名 → 拒绝。
|
||||||
|
// 有热度无排名的行同样视为噪音(OCR 混入的非榜单内容),宁缺不滥。
|
||||||
|
if (rank == null) return null
|
||||||
|
|
||||||
|
return DouyinHotEntry(
|
||||||
|
title = cleanedTitle,
|
||||||
|
heatRaw = heatRaw,
|
||||||
|
heatValue = heatValue,
|
||||||
|
rank = rank,
|
||||||
|
label = label,
|
||||||
|
order = order,
|
||||||
|
heatMissing = heatValue == null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 「1165.9万」→ 11659000;非法形态返回 null。 */
|
||||||
|
internal fun parseHeat(raw: String?): Long? {
|
||||||
|
if (raw.isNullOrBlank()) return null
|
||||||
|
val text = raw.trim()
|
||||||
|
if (!text.endsWith("万")) return null
|
||||||
|
val number = text.removeSuffix("万").toDoubleOrNull() ?: return null
|
||||||
|
if (number < 0) return null
|
||||||
|
return (number * 10_000).toLong()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音采集解析结果模型(2026-11-16 e1 取证口径)。
|
||||||
|
*
|
||||||
|
* 口径约束(缺值不伪造):解析不到的字段一律保留 null,
|
||||||
|
* 不从行序、图标或无关文本推断补齐。
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音热榜条目(e1 实测形态:排名徽章 + 标题 + 热/新/挑战/辟谣彩色标签 + 热度值「1165.9万」)。
|
||||||
|
*
|
||||||
|
* 热榜列表为自绘渲染(XML 树无词条文本),OCR 文本行为唯一输入源:
|
||||||
|
* - [rank] 只认行首 1~2 位独立数字;置顶/官宣行无排名 → null;
|
||||||
|
* - [label] 只认 OCR 读出的独立标签词(热/新/挑战/辟谣);OCR 粘连时保留 null 不强行剥离;
|
||||||
|
* - [heatValue] 只认「数值+万」形态(1165.9万 → 11659000);无热度行不构成条目(OCR 无结构,
|
||||||
|
* 无法区分置顶行与搜索历史/Tab 名等噪音,宁缺不滥);
|
||||||
|
* - [order] 仅为展示序(行序),不是排名。
|
||||||
|
*/
|
||||||
|
data class DouyinHotEntry(
|
||||||
|
val title: String,
|
||||||
|
val heatRaw: String? = null,
|
||||||
|
val heatValue: Long? = null,
|
||||||
|
val rank: Int? = null,
|
||||||
|
val label: String? = null,
|
||||||
|
val order: Int = 0,
|
||||||
|
val heatMissing: Boolean = true,
|
||||||
|
)
|
||||||
@@ -105,17 +105,20 @@ fun rememberSourceVersions(): Map<String, String?> {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CrossWorkspaceOverview(config: AppConfig, tasks: List<CrossPublishTask>, loaded: Boolean, onNavigate: (String) -> Unit) {
|
fun CrossWorkspaceOverview(config: AppConfig, tasks: List<CrossPublishTask>, loaded: Boolean, onNavigate: (String) -> Unit) {
|
||||||
|
// 品牌 Hero:渐变主卡 + 指标行;文案克制,一眼看清工作台状态
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
Text("浩瑞", style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold)
|
Surface(
|
||||||
Text("手机里的创作工作台", style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
shape = RoundedCornerShape(24.dp),
|
||||||
Surface(color = MaterialTheme.colorScheme.primaryContainer, shape = RoundedCornerShape(20.dp)) {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
Column(Modifier.fillMaxWidth().padding(18.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
color = com.haorui.app.ui.theme.BrandPurple,
|
||||||
Text("内容发现 · 创作 · 发布", style = MaterialTheme.typography.titleLarge)
|
) {
|
||||||
Text("跨平台来源待真机适配,当前不会自动采集或发布。既有头条视频任务从下方启动。", style = MaterialTheme.typography.bodyMedium)
|
Column(Modifier.fillMaxWidth().padding(horizontal = 22.dp, vertical = 24.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
Text("浩瑞", style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold, color = androidx.compose.ui.graphics.Color.White)
|
||||||
OverviewMetric("来源选择", SourceRegistry.definitions.count { config.crossPlatform.sourceEnabled(it.id) }.toString())
|
Text("热点 → 创作 → 发布,手机上的内容工作台", style = MaterialTheme.typography.bodyMedium, color = androidx.compose.ui.graphics.Color.White.copy(alpha = .85f))
|
||||||
OverviewMetric("本地任务", if (loaded) tasks.size.toString() else "—")
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||||
OverviewMetric("待核对", if (loaded) tasks.count { it.state in unknownStates }.toString() else "—")
|
HeroMetric(if (loaded) tasks.size.toString() else "—", "本地任务")
|
||||||
|
HeroMetric(if (loaded) tasks.count { it.state in unknownStates }.toString() else "—", "待核对")
|
||||||
|
HeroMetric(SourceRegistry.definitions.count { config.crossPlatform.sourceEnabled(it.id) }.toString(), "启用来源")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,19 +130,19 @@ fun CrossWorkspaceOverview(config: AppConfig, tasks: List<CrossPublishTask>, loa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun OverviewMetric(label: String, value: String) {
|
private fun HeroMetric(value: String, label: String) {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||||
Text(value, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.SemiBold)
|
Text(value, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.SemiBold, color = androidx.compose.ui.graphics.Color.White)
|
||||||
Text(label, style = MaterialTheme.typography.bodySmall)
|
Text(label, style = MaterialTheme.typography.bodySmall, color = androidx.compose.ui.graphics.Color.White.copy(alpha = .75f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CrossSettingsEntries(onNavigate: (String) -> Unit) {
|
fun CrossSettingsEntries(onNavigate: (String) -> Unit) {
|
||||||
Section(title = "创作工作台", help = "来源与发布设置;选题筛选与热点词条已并入首页") {
|
// 来源 App 管理入口已并入首页「管理来源」;此处不再放任何链接。
|
||||||
SettingsLink("来源 App 管理", "安装版本与适配状态", { onNavigate(Routes.CROSS_SOURCES) })
|
Section(title = "通用配置", help = "自动化与采集设置的调整入口") {
|
||||||
SettingsLink("自动化设置", "作品形式、每日额度与草稿模式", { onNavigate(Routes.CROSS_AUTOMATION) })
|
SettingsLink("自动化设置", "作品形式、每日额度与草稿模式", { onNavigate(Routes.CROSS_AUTOMATION) })
|
||||||
SettingsLink("既有视频采集设置", "头条 / 百度配置、时段与每日重置", { onNavigate(Routes.COLLECT) })
|
SettingsLink("既有视频采集设置", "头条配置、时段与每日重置", { onNavigate(Routes.COLLECT) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,13 +194,13 @@ fun SourcesScreen(config: AppConfig, versions: Map<String, String?>, onConfigCha
|
|||||||
ScreenHeading("来源 App", "在本机管理来源选择,安装与适配状态分别显示")
|
ScreenHeading("来源 App", "在本机管理来源选择,安装与适配状态分别显示")
|
||||||
StatusBanner("来源均待真机适配。勾选仅保存使用偏好,不代表已接通。", StatusLevel.WARN)
|
StatusBanner("来源均待真机适配。勾选仅保存使用偏好,不代表已接通。", StatusLevel.WARN)
|
||||||
Section(title = "内容来源") {
|
Section(title = "内容来源") {
|
||||||
SourceRegistry.definitions.forEach { source ->
|
// 小红书已搁置(用户判定内容调性不适合头条),不提供启用项
|
||||||
|
SourceRegistry.definitions.filter { it.id != "xiaohongshu" }.forEach { source ->
|
||||||
val installed = versions[source.id]
|
val installed = versions[source.id]
|
||||||
val reason = SourceRegistry.executionStatus(source.id, installed, draft).reason
|
val reason = SourceRegistry.executionStatus(source.id, installed, draft).reason
|
||||||
ToggleRow(source.label, "${installed?.let { "已安装 $it" } ?: "未安装或版本不可读"} · ${if (source.verified) reason else "待真机适配"}", draft.sourceEnabled(source.id)) { checked ->
|
ToggleRow(source.label, "${installed?.let { "已安装 $it" } ?: "未安装或版本不可读"} · ${if (source.verified) reason else "待真机适配"}", draft.sourceEnabled(source.id)) { checked ->
|
||||||
draft = when (source.id) {
|
draft = when (source.id) {
|
||||||
"zhihu" -> draft.copy(zhihuEnabled = checked)
|
"zhihu" -> draft.copy(zhihuEnabled = checked)
|
||||||
"xiaohongshu" -> draft.copy(xiaohongshuEnabled = checked)
|
|
||||||
"weibo" -> draft.copy(weiboEnabled = checked)
|
"weibo" -> draft.copy(weiboEnabled = checked)
|
||||||
"douyin" -> draft.copy(douyinEnabled = checked)
|
"douyin" -> draft.copy(douyinEnabled = checked)
|
||||||
else -> draft
|
else -> draft
|
||||||
@@ -220,46 +223,6 @@ fun SourcesScreen(config: AppConfig, versions: Map<String, String?>, onConfigCha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
|
||||||
@Composable
|
|
||||||
fun TopicFilterSection(config: AppConfig, onConfigChange: (AppConfig) -> Unit) {
|
|
||||||
// 各数值字段以文本草稿编辑,失焦即按范围归一化写回配置(改即生效,无保存按钮)
|
|
||||||
var maxAge by rememberSaveable(config.crossPlatform.maxAgeHours) { mutableStateOf(config.crossPlatform.maxAgeHours.toString()) }
|
|
||||||
var likes by rememberSaveable(config.crossPlatform.likesMin) { mutableStateOf(config.crossPlatform.likesMin.toString()) }
|
|
||||||
var fans by rememberSaveable(config.crossPlatform.fansMax) { mutableStateOf(config.crossPlatform.fansMax.toString()) }
|
|
||||||
Section(title = "选题筛选", help = "先满足分类、时效与指标条件,再进行候选排序;修改立即生效") {
|
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
||||||
CrossPlatformConfig.CATEGORY_CATALOGUE.forEach { category ->
|
|
||||||
val selected = category in config.crossPlatform.categories
|
|
||||||
FilterChip(selected = selected, onClick = {
|
|
||||||
val next = if (selected) config.crossPlatform.categories - category else config.crossPlatform.categories + category
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(categories = next)))
|
|
||||||
}, label = { Text(category) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FieldHelp("分类选择与图文 / 视频形式分开设置,素材许可、事实核验与账号条件仍需通过。")
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
|
||||||
OutlinedNumberField("时效不超过(小时)", maxAge, 1..72, { maxAge = it }) {
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(maxAgeHours = it)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ToggleRow("点赞数限制", "启用后,点赞数未知的候选不放行", config.crossPlatform.likesGateEnabled) {
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(likesGateEnabled = it)))
|
|
||||||
}
|
|
||||||
OutlinedNumberField("作品点赞至少", likes, 0..1_000_000_000, { likes = it }) {
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(likesMin = it)))
|
|
||||||
}
|
|
||||||
ToggleRow("作者粉丝数限制", "启用后,粉丝数未知的候选不放行", config.crossPlatform.fansGateEnabled) {
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(fansGateEnabled = it)))
|
|
||||||
}
|
|
||||||
OutlinedNumberField("作者粉丝不超过", fans, 0..1_000_000_000, { fans = it }) {
|
|
||||||
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(fansMax = it)))
|
|
||||||
}
|
|
||||||
Text("优选与去重按来源与指标口径比较热度;增长需要两次真实快照。同一事件在图文与视频之间共用去重记录。",
|
|
||||||
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 带范围归一化的数字输入:编辑中文本自由变化,归一化成功后回写配置 */
|
/** 带范围归一化的数字输入:编辑中文本自由变化,归一化成功后回写配置 */
|
||||||
@Composable
|
@Composable
|
||||||
private fun OutlinedNumberField(label: String, value: String, range: IntRange, onText: (String) -> Unit, onCommit: (Int) -> Unit) {
|
private fun OutlinedNumberField(label: String, value: String, range: IntRange, onText: (String) -> Unit, onCommit: (Int) -> Unit) {
|
||||||
@@ -363,23 +326,87 @@ private val topicStates = setOf(CrossTaskState.DISCOVERED, CrossTaskState.FILTER
|
|||||||
@Composable
|
@Composable
|
||||||
fun TopicSourceSection(config: AppConfig, tasks: List<CrossPublishTask>, loaded: Boolean, loadError: String?,
|
fun TopicSourceSection(config: AppConfig, tasks: List<CrossPublishTask>, loaded: Boolean, loadError: String?,
|
||||||
onConfigChange: (AppConfig) -> Unit, onNavigate: (String) -> Unit) {
|
onConfigChange: (AppConfig) -> Unit, onNavigate: (String) -> Unit) {
|
||||||
var source by rememberSaveable { mutableStateOf("all") }
|
var source by rememberSaveable { mutableStateOf("weibo") }
|
||||||
var kind by rememberSaveable { mutableStateOf("all") }
|
var kind by rememberSaveable { mutableStateOf("all") }
|
||||||
var selected by remember { mutableStateOf<CrossPublishTask?>(null) }
|
var selected by remember { mutableStateOf<CrossPublishTask?>(null) }
|
||||||
val candidates = tasks.filter { it.state in topicStates && (source == "all" || it.sourcePlatform == source) && (kind == "all" || it.contentKind.name == kind) }
|
val candidates = tasks.filter { it.state in topicStates && it.sourcePlatform == source && (kind == "all" || it.contentKind.name == kind) }
|
||||||
Section(title = "来源与热点候选", help = "管理来源 App、筛选条件与可采集的热点词条;候选按选择的内容分类积累") {
|
Section(title = "热点选题", help = "选来源 → 配置该来源的选题条件 → 勾选词条采集") {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
TextButton({ onNavigate(Routes.CROSS_SOURCES) }) { Text("管理来源") }
|
TextButton({ onNavigate(Routes.CROSS_SOURCES) }) { Text("管理来源") }
|
||||||
}
|
}
|
||||||
|
// ── 来源切换:决定下方显示哪个来源的专属筛选(小红书已搁置,不提供) ────
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(7.dp)) {
|
FlowRow(horizontalArrangement = Arrangement.spacedBy(7.dp)) {
|
||||||
FilterChip(selected = source == "all", onClick = { source = "all" }, label = { Text("全部来源") })
|
listOf("zhihu", "weibo", "douyin").forEach { id ->
|
||||||
SourceRegistry.definitions.forEach { item -> FilterChip(selected = source == item.id, onClick = { source = item.id }, label = { Text(item.label) }) }
|
val def = SourceRegistry.find(id) ?: return@forEach
|
||||||
|
FilterChip(selected = source == id, onClick = { source = id }, label = { Text(def.label) })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// ── 来源专属筛选:不同来源的选题维度不同 ────
|
||||||
|
when (source) {
|
||||||
|
"zhihu" -> ZhihuSourceFilter(config, onConfigChange)
|
||||||
|
"weibo" -> WeiboSourceFilter(config, onConfigChange)
|
||||||
|
"douyin" -> DouyinSourceFilter(config, onConfigChange)
|
||||||
|
}
|
||||||
|
// ── 作品形式过滤 + 候选列表 ────
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(7.dp)) {
|
FlowRow(horizontalArrangement = Arrangement.spacedBy(7.dp)) {
|
||||||
listOf("all" to "全部形式", "ARTICLE" to "图文", "VIDEO" to "视频").forEach { (id, label) ->
|
listOf("all" to "全部形式", "ARTICLE" to "图文", "VIDEO" to "视频").forEach { (id, label) ->
|
||||||
FilterChip(selected = kind == id, onClick = { kind = id }, label = { Text(label) })
|
FilterChip(selected = kind == id, onClick = { kind = id }, label = { Text(label) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
when {
|
||||||
|
loadError != null -> StatusBanner("本地任务读取失败:$loadError", StatusLevel.BAD)
|
||||||
|
!loaded -> EmptyPanel("正在读取本地候选", "请稍候")
|
||||||
|
candidates.isEmpty() -> EmptyPanel("此来源暂无热点候选", "采集落库后,这里将显示真实候选记录。")
|
||||||
|
else -> candidates.forEach { TaskCard(it, { selected = it }) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selected?.let { prior -> TaskPreview(tasks.firstOrNull { it.id == prior.id } ?: prior) { selected = null } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 知乎来源专属筛选:热榜卡片范围(按榜单序号区间采集)。 */
|
||||||
|
@Composable
|
||||||
|
private fun ZhihuSourceFilter(config: AppConfig, onConfigChange: (AppConfig) -> Unit) {
|
||||||
|
var rangeStart by rememberSaveable(config.crossPlatform.zhihuCardRangeStart) { mutableStateOf(config.crossPlatform.zhihuCardRangeStart.toString()) }
|
||||||
|
var rangeEnd by rememberSaveable(config.crossPlatform.zhihuCardRangeEnd) { mutableStateOf(config.crossPlatform.zhihuCardRangeEnd.toString()) }
|
||||||
|
Section(title = "知乎热榜范围", help = "采集热榜第 N~M 条卡片;卡片序号按榜单展示序(1 起)") {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
|
OutlinedNumberField("起始条(1~50)", rangeStart, 1..50, { rangeStart = it }) {
|
||||||
|
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(zhihuCardRangeStart = it)))
|
||||||
|
}
|
||||||
|
OutlinedNumberField("结束条(起始~50)", rangeEnd, 1..50, { rangeEnd = it }) {
|
||||||
|
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(zhihuCardRangeEnd = it)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 抖音来源专属筛选:榜单前 N 条 + 标签过滤(OCR 可读标签:热/新/挑战/辟谣)。 */
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
private fun DouyinSourceFilter(config: AppConfig, onConfigChange: (AppConfig) -> Unit) {
|
||||||
|
var topN by rememberSaveable(config.crossPlatform.douyinTopN) { mutableStateOf(config.crossPlatform.douyinTopN.toString()) }
|
||||||
|
val selectedLabels = config.crossPlatform.douyinLabelFilter.toSet()
|
||||||
|
Section(title = "抖音热榜范围", help = "采集榜单前 N 条;标签过滤为空表示不过滤(全部标签都采)") {
|
||||||
|
OutlinedNumberField("只采前(1~50)条", topN, 1..50, { topN = it }) {
|
||||||
|
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(douyinTopN = it)))
|
||||||
|
}
|
||||||
|
FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
|
listOf("热", "新", "挑战", "辟谣").forEach { label ->
|
||||||
|
FilterChip(selected = label in selectedLabels, onClick = {
|
||||||
|
val next = if (label in selectedLabels) selectedLabels - label else selectedLabels + label
|
||||||
|
// 保持稳定顺序(热/新/挑战/辟谣)
|
||||||
|
onConfigChange(config.copy(crossPlatform = config.crossPlatform.copy(
|
||||||
|
douyinLabelFilter = listOf("热", "新", "挑战", "辟谣").filter { it in next },
|
||||||
|
)))
|
||||||
|
}, label = { Text(label) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 微博来源专属筛选:热搜类目多选 + 词条勾选器(选什么采什么)。 */
|
||||||
|
@Composable
|
||||||
|
private fun WeiboSourceFilter(config: AppConfig, onConfigChange: (AppConfig) -> Unit) {
|
||||||
// 微博热搜类目:下拉多选(全部实测类目),选择持久化到配置;所选类目决定去微博热搜拉哪些榜单
|
// 微博热搜类目:下拉多选(全部实测类目),选择持久化到配置;所选类目决定去微博热搜拉哪些榜单
|
||||||
val selectedCategoryIds: Set<String> = config.crossPlatform.weiboHotCategories.toSet()
|
val selectedCategoryIds: Set<String> = config.crossPlatform.weiboHotCategories.toSet()
|
||||||
Section(title = "微博热搜类目", tag = "下拉可选",
|
Section(title = "微博热搜类目", tag = "下拉可选",
|
||||||
@@ -408,19 +435,9 @@ fun TopicSourceSection(config: AppConfig, tasks: List<CrossPublishTask>, loaded:
|
|||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
Text("分类:${config.crossPlatform.categories.joinToString("、").ifBlank { "未选择" }} · ${config.crossPlatform.maxAgeHours} 小时内", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
|
||||||
// 微博热搜词条清单:按已选类目拉取真机榜单 → 勾选词条 → 持久化到配置(勾选后系统按所选词条采集)
|
// 微博热搜词条清单:按已选类目拉取真机榜单 → 勾选词条 → 持久化到配置(勾选后系统按所选词条采集)
|
||||||
WeiboHotTopicPicker(config, onConfigChange)
|
WeiboHotTopicPicker(config, onConfigChange)
|
||||||
when {
|
|
||||||
loadError != null -> StatusBanner("本地任务读取失败:$loadError", StatusLevel.BAD)
|
|
||||||
!loaded -> EmptyPanel("正在读取本地候选", "请稍候")
|
|
||||||
candidates.isEmpty() -> EmptyPanel("暂时没有热点候选", "来源适配通过后,这里将显示真实采集结果。可以先保存分类、作品形式和指标条件。")
|
|
||||||
else -> candidates.forEach { TaskCard(it, { selected = it }) }
|
|
||||||
}
|
}
|
||||||
FieldHelp("本页读取真实本地记录,不填充演示热榜或虚构热度。当前来源均待真机适配。")
|
|
||||||
}
|
|
||||||
selected?.let { prior -> TaskPreview(tasks.firstOrNull { it.id == prior.id } ?: prior) { selected = null } }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.haorui.app.ocr
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MediaProjection 截屏器(抖音专用,2026-11-17 r20~r24 定案的缓存绕行)。
|
||||||
|
*
|
||||||
|
* 与 [ScreenCapturer] 的 capture() 签名对齐:调用方先试本类(实时帧),
|
||||||
|
* 返回 null(未授权/无帧)回退 takeScreenshot(fail-open)。
|
||||||
|
* 头条/微博不受截图缓存影响,继续用 ScreenCapturer——不改动它们的链路。
|
||||||
|
*/
|
||||||
|
object ProjectionCapturer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取当前屏幕实时帧。
|
||||||
|
* @return 投影未就绪/无新帧返回 null(调用方回退无障碍截图)
|
||||||
|
*/
|
||||||
|
fun capture(): Bitmap? {
|
||||||
|
if (!ProjectionHolder.isReady) return null
|
||||||
|
return ProjectionHolder.captureLatest()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
package com.haorui.app.ocr
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.PixelFormat
|
||||||
|
import android.hardware.display.DisplayManager
|
||||||
|
import android.hardware.display.VirtualDisplay
|
||||||
|
import android.media.Image
|
||||||
|
import android.media.ImageReader
|
||||||
|
import android.media.projection.MediaProjection
|
||||||
|
import android.media.projection.MediaProjectionManager
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.HandlerThread
|
||||||
|
import android.util.DisplayMetrics
|
||||||
|
import android.view.WindowManager
|
||||||
|
import com.haorui.app.automation.RunLogger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MediaProjection 投影持有者(单例)。
|
||||||
|
*
|
||||||
|
* 背景(2026-11-17 r20~r24 定案):抖音对无障碍 takeScreenshot 通道主动缓存,
|
||||||
|
* 服务内树/截屏在搜索页永远读到旧帧——MediaProjection 走独立 SurfaceFlinger
|
||||||
|
* 通道拿实时帧,完全绕开该防护。
|
||||||
|
*
|
||||||
|
* 生命周期:授权一次(用户在系统弹窗点同意)→ createProjection 持有
|
||||||
|
* VirtualDisplay+ImageReader → 抖音采集期间按需取帧 → stopProjection 释放。
|
||||||
|
* ⚠️ Android 14+ 投影在 App 进程重启后失效(系统回收),需重新授权——
|
||||||
|
* 失效时 capture() 返回 null,调用方回退无障碍截图(fail-open)。
|
||||||
|
*
|
||||||
|
* 授权结果 Intent 由 MainActivity 的系统弹窗回调传入(用户亲手操作)。
|
||||||
|
*/
|
||||||
|
object ProjectionHolder {
|
||||||
|
private const val TAG = "HaoRui-Projection"
|
||||||
|
|
||||||
|
@Volatile private var projection: MediaProjection? = null
|
||||||
|
@Volatile private var virtualDisplay: VirtualDisplay? = null
|
||||||
|
@Volatile private var imageReader: ImageReader? = null
|
||||||
|
@Volatile private var callbackThread: HandlerThread? = null
|
||||||
|
@Volatile private var width = 0
|
||||||
|
@Volatile private var height = 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听器持有的最新帧(消费式:ImageReader 队列必须被消费才有新帧,
|
||||||
|
* acquireLatestImage 惰性模式在无消费时拿不到帧——r25 实证)。
|
||||||
|
* ⚠️ 回调线程写、capture 读——必须加锁防「回收中的位图被拷贝」竞态(r29 崩溃实证)。
|
||||||
|
*/
|
||||||
|
private val frameLock = Any()
|
||||||
|
private var latestBitmap: Bitmap? = null
|
||||||
|
private var frameCount = 0
|
||||||
|
|
||||||
|
/** 投影是否就绪(可取帧) */
|
||||||
|
val isReady: Boolean
|
||||||
|
get() = imageReader != null && projection != null
|
||||||
|
|
||||||
|
/** 当前投影实例(用于 onStop 回调识别:旧投影的迟到回调不得清掉新投影的状态) */
|
||||||
|
@Volatile private var currentProjection: MediaProjection? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用系统弹窗授权结果创建投影。
|
||||||
|
* @param resultCode onActivityResult 的 resultCode
|
||||||
|
* @param data onActivityResult 的 data(含授权令牌)
|
||||||
|
* @return 创建是否成功(用户拒绝/令牌无效返回 false)
|
||||||
|
*/
|
||||||
|
fun createProjection(context: Context, resultCode: Int, data: Intent): Boolean {
|
||||||
|
stopProjection() // 先清理旧投影
|
||||||
|
return try {
|
||||||
|
val manager = context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
||||||
|
val p = manager.getMediaProjection(resultCode, data) ?: return false
|
||||||
|
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||||
|
val metrics: DisplayMetrics = DisplayMetrics()
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
wm.defaultDisplay.getRealMetrics(metrics)
|
||||||
|
width = metrics.widthPixels
|
||||||
|
height = metrics.heightPixels
|
||||||
|
// 帧回调在独立线程(ImageReader 要求非主线程 Handler)
|
||||||
|
val thread = HandlerThread("haorui-projection").apply { start() }
|
||||||
|
callbackThread = thread
|
||||||
|
val reader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2)
|
||||||
|
// 消费式监听:每来一帧立即转 Bitmap 存 latestBitmap(不消费队列会停摆,r25 实证)
|
||||||
|
reader.setOnImageAvailableListener({
|
||||||
|
val img = try { reader.acquireLatestImage() } catch (_: Exception) { null }
|
||||||
|
if (img != null) {
|
||||||
|
try {
|
||||||
|
convertImage(img)?.let { bmp ->
|
||||||
|
synchronized(frameLock) {
|
||||||
|
latestBitmap?.recycle()
|
||||||
|
latestBitmap = bmp
|
||||||
|
frameCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
RunLogger.w(TAG, "帧转换异常: ${e.javaClass.simpleName}:${e.message}")
|
||||||
|
} finally {
|
||||||
|
runCatching { img.close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Handler(thread.looper))
|
||||||
|
val display = p.createVirtualDisplay(
|
||||||
|
"haorui-capture", width, height, metrics.densityDpi,
|
||||||
|
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
||||||
|
reader.surface, null, null,
|
||||||
|
)
|
||||||
|
projection = p
|
||||||
|
currentProjection = p
|
||||||
|
virtualDisplay = display
|
||||||
|
imageReader = reader
|
||||||
|
// 投影停止回调:**只认当前投影**——旧投影的迟到 onStop 不得清掉新投影状态
|
||||||
|
//(r26 崩溃实证:旧投影 onStop 排队到新投影创建后执行,把新投影连带清空)
|
||||||
|
p.registerCallback(object : MediaProjection.Callback() {
|
||||||
|
override fun onStop() {
|
||||||
|
if (currentProjection === p) {
|
||||||
|
RunLogger.w(TAG, "MediaProjection 被停止(通知栏/系统回收),清空持有状态")
|
||||||
|
stopProjection()
|
||||||
|
} else {
|
||||||
|
RunLogger.i(TAG, "旧投影 onStop 迟到回调(已换代),忽略")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Handler(thread.looper))
|
||||||
|
RunLogger.i(TAG, "MediaProjection 就绪 ${width}x${height}")
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
RunLogger.w(TAG, "创建投影失败: ${e.javaClass.simpleName}:${e.message}")
|
||||||
|
stopProjection()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取最新帧位图(监听器持续消费帧存 latestBitmap,capture 直接取现成的)。
|
||||||
|
* @return 无投影/尚无帧返回 null(调用方回退 takeScreenshot)
|
||||||
|
*/
|
||||||
|
fun captureLatest(): Bitmap? {
|
||||||
|
if (imageReader == null) return null
|
||||||
|
synchronized(frameLock) {
|
||||||
|
val bmp = latestBitmap ?: run {
|
||||||
|
RunLogger.w(TAG, "投影尚无帧(frameCount=$frameCount,VirtualDisplay 未渲染或队列未消费)")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
// 返回副本:latestBitmap 会被下一帧替换回收,调用方持有必须独立
|
||||||
|
val copy = bmp.copy(Bitmap.Config.ARGB_8888, false)
|
||||||
|
if (frameCount % 30 == 0) RunLogger.i(TAG, "投影取帧 #${frameCount} → ${copy.width}x${copy.height}")
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Image → Bitmap(RGBA_8888 → ARGB_8888,处理行 padding)。img 由调用方 close。 */
|
||||||
|
private fun convertImage(image: Image): Bitmap? {
|
||||||
|
return try {
|
||||||
|
val plane = image.planes[0]
|
||||||
|
val rowStride = plane.rowStride
|
||||||
|
val pixelStride = plane.pixelStride
|
||||||
|
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||||
|
val buffer = plane.buffer
|
||||||
|
if (rowStride == width * pixelStride) {
|
||||||
|
buffer.rewind()
|
||||||
|
bitmap.copyPixelsFromBuffer(buffer)
|
||||||
|
} else {
|
||||||
|
buffer.rewind()
|
||||||
|
val packed = java.nio.ByteBuffer.allocate(width * height * pixelStride)
|
||||||
|
val rowBytes = ByteArray(width * pixelStride)
|
||||||
|
for (row in 0 until height) {
|
||||||
|
buffer.position(row * rowStride)
|
||||||
|
buffer.get(rowBytes)
|
||||||
|
packed.put(rowBytes)
|
||||||
|
}
|
||||||
|
packed.rewind()
|
||||||
|
bitmap.copyPixelsFromBuffer(packed)
|
||||||
|
}
|
||||||
|
bitmap
|
||||||
|
} catch (e: Exception) {
|
||||||
|
RunLogger.w(TAG, "帧转位图失败: ${e.javaClass.simpleName}:${e.message}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 释放全部资源(幂等)。 */
|
||||||
|
fun stopProjection() {
|
||||||
|
runCatching { imageReader?.close() }
|
||||||
|
runCatching { virtualDisplay?.release() }
|
||||||
|
runCatching { projection?.stop() }
|
||||||
|
imageReader = null
|
||||||
|
virtualDisplay = null
|
||||||
|
projection = null
|
||||||
|
currentProjection = null
|
||||||
|
latestBitmap?.recycle()
|
||||||
|
latestBitmap = null
|
||||||
|
callbackThread?.quitSafely()
|
||||||
|
callbackThread = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,6 @@ import com.haorui.app.ui.screens.ApiScreen
|
|||||||
import com.haorui.app.ui.screens.BrowseScreen
|
import com.haorui.app.ui.screens.BrowseScreen
|
||||||
import com.haorui.app.ui.screens.CollectScreen
|
import com.haorui.app.ui.screens.CollectScreen
|
||||||
import com.haorui.app.ui.screens.HomeScreen
|
import com.haorui.app.ui.screens.HomeScreen
|
||||||
import com.haorui.app.ui.screens.InteractScreen
|
|
||||||
import com.haorui.app.ui.screens.LogsScreen
|
import com.haorui.app.ui.screens.LogsScreen
|
||||||
import com.haorui.app.ui.screens.MineScreen
|
import com.haorui.app.ui.screens.MineScreen
|
||||||
import com.haorui.app.ui.screens.ToutiaoConfigScreen
|
import com.haorui.app.ui.screens.ToutiaoConfigScreen
|
||||||
@@ -62,7 +61,6 @@ object Routes {
|
|||||||
const val TASKS = "tasks"
|
const val TASKS = "tasks"
|
||||||
const val CROSS_SOURCES = "cross_sources"
|
const val CROSS_SOURCES = "cross_sources"
|
||||||
const val CROSS_AUTOMATION = "cross_automation"
|
const val CROSS_AUTOMATION = "cross_automation"
|
||||||
const val INTERACT = "interact"
|
|
||||||
const val MINE = "mine"
|
const val MINE = "mine"
|
||||||
const val TOUTIAO = "toutiao"
|
const val TOUTIAO = "toutiao"
|
||||||
const val API = "api"
|
const val API = "api"
|
||||||
@@ -77,7 +75,6 @@ object Routes {
|
|||||||
TASKS to "任务",
|
TASKS to "任务",
|
||||||
CROSS_SOURCES to "来源 App 管理",
|
CROSS_SOURCES to "来源 App 管理",
|
||||||
CROSS_AUTOMATION to "自动化设置",
|
CROSS_AUTOMATION to "自动化设置",
|
||||||
INTERACT to "互动",
|
|
||||||
MINE to "我的",
|
MINE to "我的",
|
||||||
TOUTIAO to "头条采集设置",
|
TOUTIAO to "头条采集设置",
|
||||||
API to "解析 / 大模型",
|
API to "解析 / 大模型",
|
||||||
@@ -90,7 +87,6 @@ object Routes {
|
|||||||
val subtitles = mapOf(
|
val subtitles = mapOf(
|
||||||
HOME to "今日头条 18.3.0 · 全流程自动采集发布",
|
HOME to "今日头条 18.3.0 · 全流程自动采集发布",
|
||||||
COLLECT to "选择采集源并进入详细参数",
|
COLLECT to "选择采集源并进入详细参数",
|
||||||
INTERACT to "新粉谢谢关注 / 随机回关 · 每日配额",
|
|
||||||
MINE to "设置入口与本机数据管理",
|
MINE to "设置入口与本机数据管理",
|
||||||
TOUTIAO to "18 项筛选参数 · 类目 / 作品声明",
|
TOUTIAO to "18 项筛选参数 · 类目 / 作品声明",
|
||||||
API to "标题改写供应商 · 解析线路",
|
API to "标题改写供应商 · 解析线路",
|
||||||
@@ -100,7 +96,7 @@ object Routes {
|
|||||||
)
|
)
|
||||||
|
|
||||||
/** 底部 tab */
|
/** 底部 tab */
|
||||||
val tabs = listOf(HOME, TASKS, INTERACT, MINE)
|
val tabs = listOf(HOME, TASKS, MINE)
|
||||||
|
|
||||||
/** 路由 → 所属 tab(用于返回键回落) */
|
/** 路由 → 所属 tab(用于返回键回落) */
|
||||||
fun tabOf(route: String): String = when (route) {
|
fun tabOf(route: String): String = when (route) {
|
||||||
@@ -114,7 +110,6 @@ private data class TabDef(val route: String, val label: String, val icon: ImageV
|
|||||||
private val tabDefs = listOf(
|
private val tabDefs = listOf(
|
||||||
TabDef(Routes.HOME, "首页", Icons.Filled.Home),
|
TabDef(Routes.HOME, "首页", Icons.Filled.Home),
|
||||||
TabDef(Routes.TASKS, "任务", Icons.Filled.Assignment),
|
TabDef(Routes.TASKS, "任务", Icons.Filled.Assignment),
|
||||||
TabDef(Routes.INTERACT, "互动", Icons.Filled.Settings),
|
|
||||||
TabDef(Routes.MINE, "我的", Icons.Filled.Person),
|
TabDef(Routes.MINE, "我的", Icons.Filled.Person),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -275,11 +270,10 @@ fun HaoRuiApp(config: AppConfig, onConfigChange: (AppConfig) -> Unit) {
|
|||||||
onConfigChange = onConfigChange,
|
onConfigChange = onConfigChange,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(Routes.INTERACT) {
|
|
||||||
InteractScreen(config, onConfigChange, ::toast)
|
|
||||||
}
|
|
||||||
composable(Routes.MINE) {
|
composable(Routes.MINE) {
|
||||||
MineScreen(
|
MineScreen(
|
||||||
|
config = config,
|
||||||
|
onConfigChange = onConfigChange,
|
||||||
onNavigate = { nav.navigate(it) },
|
onNavigate = { nav.navigate(it) },
|
||||||
onToast = ::toast,
|
onToast = ::toast,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -137,26 +137,20 @@ fun ToutiaoConfigScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 互动设置 — 新粉互动 / 随机回关 / 信用分门控 / 评论辅助
|
* 互动设置区块(原「互动」tab 内容,2026-11-16 并入「我的」页)——
|
||||||
* 对照 docs/技术架构与代码说明.md
|
* 新粉互动 / 信用分门控 / 评论辅助,三个 Section 平铺嵌入宿主页。
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun InteractScreen(
|
fun InteractSettingsSections(
|
||||||
config: AppConfig,
|
config: AppConfig,
|
||||||
onConfigChange: (AppConfig) -> Unit,
|
onConfigChange: (AppConfig) -> Unit,
|
||||||
onToast: (String) -> Unit,
|
onToast: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val i = config.interact
|
val i = config.interact
|
||||||
val c = config.credit
|
val c = config.credit
|
||||||
val ctx = androidx.compose.ui.platform.LocalContext.current
|
|
||||||
fun updI(v: com.haorui.app.data.model.InteractConfig) = onConfigChange(config.copy(interact = v))
|
fun updI(v: com.haorui.app.data.model.InteractConfig) = onConfigChange(config.copy(interact = v))
|
||||||
fun updC(v: com.haorui.app.data.model.CreditConfig) = onConfigChange(config.copy(credit = v))
|
fun updC(v: com.haorui.app.data.model.CreditConfig) = onConfigChange(config.copy(credit = v))
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())
|
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
|
||||||
) {
|
|
||||||
Section(title = "每日新粉互动") {
|
Section(title = "每日新粉互动") {
|
||||||
CheckRow("每日启动前先执行新粉互动", i.dailyEnabled, { updI(i.copy(dailyEnabled = it)) })
|
CheckRow("每日启动前先执行新粉互动", i.dailyEnabled, { updI(i.copy(dailyEnabled = it)) })
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
@@ -227,4 +221,3 @@ fun InteractScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import androidx.compose.ui.unit.dp
|
|||||||
import com.haorui.app.data.model.AppConfig
|
import com.haorui.app.data.model.AppConfig
|
||||||
import com.haorui.app.crossplatform.model.CrossPublishTask
|
import com.haorui.app.crossplatform.model.CrossPublishTask
|
||||||
import com.haorui.app.crossplatform.ui.CrossWorkspaceOverview
|
import com.haorui.app.crossplatform.ui.CrossWorkspaceOverview
|
||||||
import com.haorui.app.crossplatform.ui.TopicFilterSection
|
|
||||||
import com.haorui.app.crossplatform.ui.TopicSourceSection
|
import com.haorui.app.crossplatform.ui.TopicSourceSection
|
||||||
import com.haorui.app.ui.components.CheckRow
|
import com.haorui.app.ui.components.CheckRow
|
||||||
import com.haorui.app.ui.components.NumberField
|
import com.haorui.app.ui.components.NumberField
|
||||||
@@ -47,23 +46,15 @@ import com.haorui.app.ui.components.PrimaryButton
|
|||||||
import com.haorui.app.ui.components.Section
|
import com.haorui.app.ui.components.Section
|
||||||
import com.haorui.app.ui.components.StatusBanner
|
import com.haorui.app.ui.components.StatusBanner
|
||||||
import com.haorui.app.ui.components.StatusLevel
|
import com.haorui.app.ui.components.StatusLevel
|
||||||
import com.haorui.app.ui.components.StepHint
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 首页 —— **运行与启动**(唯一启动点)
|
* 首页 —— 工作台总览 + 唯一启动点 + 热点选题
|
||||||
*
|
*
|
||||||
* ## 功能去重原则(2026-10-29 重构)
|
* ## 功能布局(2026-11-16 重构)
|
||||||
* 每个功能只在一处设置,避免用户困惑「该在哪里改」:
|
* ① 品牌 Hero(工作台指标 + 视觉焦点)
|
||||||
* 启动/停止 → **本页**(唯一)
|
* ② 运行卡(唯一启动/停止入口 + 发布模式 + 限额)
|
||||||
* 采集参数 → 「采集」tab
|
* ③ 热点选题(来源切换 → 来源专属筛选 → 词条勾选 → 候选)
|
||||||
* 互动参数 → 「互动」tab
|
* ④ 通用筛选(分类/时效/点赞/粉丝,全来源共用)
|
||||||
* 接口/无障碍/浏览/记录 → 「我的」tab
|
|
||||||
* 本页**不做**其它功能的入口,只在需要时给文字指引。
|
|
||||||
*
|
|
||||||
* 信息层次:
|
|
||||||
* ① 状态大卡(一眼看懂 + 启动/停止)
|
|
||||||
* ② 三步上手引导(跳转到各配置页,不是重复入口)
|
|
||||||
* ③ 高级设置(模式 / 分时段 / 每日重置)
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeScreen(
|
fun HomeScreen(
|
||||||
@@ -81,9 +72,8 @@ fun HomeScreen(
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(18.dp),
|
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
CrossWorkspaceOverview(config, crossTasks, crossTasksLoaded, onNavigate)
|
CrossWorkspaceOverview(config, crossTasks, crossTasksLoaded, onNavigate)
|
||||||
|
|
||||||
// 唯一的既有视频启动/停止入口。
|
// 唯一的既有视频启动/停止入口。
|
||||||
@@ -94,20 +84,8 @@ fun HomeScreen(
|
|||||||
onConfigChange = onConfigChange,
|
onConfigChange = onConfigChange,
|
||||||
)
|
)
|
||||||
|
|
||||||
// ── ② 三步上手引导:指向各配置页,不是重复入口 ────
|
// ── ③ 热点选题(来源切换:知乎/微博/抖音各自专属筛选;小红书已搁置不提供) ────
|
||||||
StepHint(
|
|
||||||
title = "开始使用前,请先完成这三步",
|
|
||||||
steps = listOf(
|
|
||||||
"在「我的」开启无障碍服务(必需)" to "a11y",
|
|
||||||
"在「我的」进入既有视频采集设置" to "collect",
|
|
||||||
"在「我的」配置大模型 Key(可选)" to "api",
|
|
||||||
),
|
|
||||||
onNavigate = onNavigate,
|
|
||||||
)
|
|
||||||
|
|
||||||
// ── ③ 选题与来源(原热点 tab 全部功能并入首页;筛选与微博词条即改即生效) ────
|
|
||||||
TopicSourceSection(config, crossTasks, crossTasksLoaded, crossTasksError, onConfigChange, onNavigate)
|
TopicSourceSection(config, crossTasks, crossTasksLoaded, crossTasksError, onConfigChange, onNavigate)
|
||||||
TopicFilterSection(config, onConfigChange)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,11 @@ import com.haorui.app.ui.components.StatusBanner
|
|||||||
import com.haorui.app.ui.components.StatusLevel
|
import com.haorui.app.ui.components.StatusLevel
|
||||||
import com.haorui.app.ui.components.TextRow
|
import com.haorui.app.ui.components.TextRow
|
||||||
|
|
||||||
/** 我的 — 设置入口与本机数据管理 */
|
/** 我的 — 设置入口与本机数据管理(互动设置已并入本页) */
|
||||||
@Composable
|
@Composable
|
||||||
fun MineScreen(
|
fun MineScreen(
|
||||||
|
config: AppConfig,
|
||||||
|
onConfigChange: (AppConfig) -> Unit,
|
||||||
onNavigate: (String) -> Unit,
|
onNavigate: (String) -> Unit,
|
||||||
onToast: (String) -> Unit,
|
onToast: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -66,8 +68,11 @@ fun MineScreen(
|
|||||||
) {
|
) {
|
||||||
CrossSettingsEntries(onNavigate)
|
CrossSettingsEntries(onNavigate)
|
||||||
|
|
||||||
|
// ── 互动设置(原「互动」tab 内容,并入本页通用配置) ────
|
||||||
|
InteractSettingsSections(config, onConfigChange, onToast)
|
||||||
|
|
||||||
Section(
|
Section(
|
||||||
title = "系统设置",
|
title = "通用配置 · 系统开关",
|
||||||
help = "影响任务能否正常运行的关键配置",
|
help = "影响任务能否正常运行的关键配置",
|
||||||
) {
|
) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
@@ -105,8 +110,11 @@ fun MineScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 屏幕采集授权(抖音独立截屏通道;绕开无障碍截图缓存) ────
|
||||||
|
ScreenProjectionSection(onToast)
|
||||||
|
|
||||||
Section(
|
Section(
|
||||||
title = "本机数据",
|
title = "通用配置 · 本机数据",
|
||||||
help = "清理本地缓存与去重记录",
|
help = "清理本地缓存与去重记录",
|
||||||
) {
|
) {
|
||||||
StatusBanner("已发布去重索引:$dedupCount 条", StatusLevel.NEUTRAL)
|
StatusBanner("已发布去重索引:$dedupCount 条", StatusLevel.NEUTRAL)
|
||||||
@@ -129,6 +137,38 @@ fun MineScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 屏幕采集授权区块(MediaProjection)。
|
||||||
|
* 抖音搜索页对无障碍截图通道有缓存防护(r13~r24 定案),投影通道拿实时帧绕开;
|
||||||
|
* 授权需用户在系统弹窗亲手点同意,进程重启后投影失效需重新授权。
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun ScreenProjectionSection(onToast: (String) -> Unit) {
|
||||||
|
var ready by remember { mutableStateOf(com.haorui.app.automation.RunState.projectionReady) }
|
||||||
|
val scope = androidx.compose.runtime.rememberCoroutineScope()
|
||||||
|
val activity = androidx.compose.ui.platform.LocalContext.current as? com.haorui.app.MainActivity
|
||||||
|
Section(title = "屏幕采集授权", help = "抖音采集需要;授权后 App 可截取屏幕实时画面") {
|
||||||
|
StatusBanner(
|
||||||
|
text = if (ready) "屏幕采集已授权(投影就绪)"
|
||||||
|
else "未授权——抖音采集将退化为无障碍截图(读不到实时画面)",
|
||||||
|
level = if (ready) StatusLevel.OK else StatusLevel.WARN,
|
||||||
|
)
|
||||||
|
HaoRuiButton(if (ready) "重新授权屏幕采集" else "授权屏幕采集", {
|
||||||
|
if (activity == null) {
|
||||||
|
onToast("授权入口异常(非主窗口),请重启 App 后再试")
|
||||||
|
} else {
|
||||||
|
activity.requestProjection()
|
||||||
|
// 授权结果异步回调(projectionLauncher),按钮状态延迟刷新
|
||||||
|
scope.launch {
|
||||||
|
kotlinx.coroutines.delay(3_000)
|
||||||
|
ready = com.haorui.app.automation.RunState.projectionReady
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Modifier.fillMaxWidth())
|
||||||
|
FieldHelp("授权弹窗由系统弹出,请勾选「整个屏幕」后点立即开始;进程重启后需重新授权")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 接口 / 大模型 — 供应商切换、密钥、标题字数、解析源 */
|
/** 接口 / 大模型 — 供应商切换、密钥、标题字数、解析源 */
|
||||||
@Composable
|
@Composable
|
||||||
fun ApiScreen(
|
fun ApiScreen(
|
||||||
|
|||||||
@@ -14,14 +14,36 @@ class SourceRegistryTest {
|
|||||||
|
|
||||||
@Test fun selectingEverySourceDoesNotInventVerifiedCapabilities() {
|
@Test fun selectingEverySourceDoesNotInventVerifiedCapabilities() {
|
||||||
assertEquals(4, SourceRegistry.definitions.size)
|
assertEquals(4, SourceRegistry.definitions.size)
|
||||||
SourceRegistry.definitions.forEach { source ->
|
// 抖音已验收放行(2026-11-17);其余来源仍未验证
|
||||||
assertFalse(source.verified)
|
val verifiedIds = SourceRegistry.definitions.filter { it.verified }.map { it.id }
|
||||||
|
assertEquals(listOf("douyin"), verifiedIds)
|
||||||
|
SourceRegistry.definitions.filter { !it.verified }.forEach { source ->
|
||||||
SourceCapability.entries.forEach { capability ->
|
SourceCapability.entries.forEach { capability ->
|
||||||
assertFalse(SourceRegistry.executionStatus(source.id, "99.99", requested, capability).canExecute)
|
assertFalse(SourceRegistry.executionStatus(source.id, "99.99", requested, capability).canExecute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun douyinIsVerifiedWithHotListAndDetailCapabilities() {
|
||||||
|
val douyin = SourceRegistry.find("douyin")!!
|
||||||
|
assertTrue(douyin.verified)
|
||||||
|
assertTrue(douyin.verifiedVersions.contains("39.8.0"))
|
||||||
|
assertTrue(douyin.capabilities.contains(SourceCapability.HOT_LIST))
|
||||||
|
assertTrue(douyin.capabilities.contains(SourceCapability.DETAIL))
|
||||||
|
// 未取证能力不列入
|
||||||
|
assertFalse(douyin.capabilities.contains(SourceCapability.SHARE_LINK))
|
||||||
|
assertFalse(douyin.capabilities.contains(SourceCapability.MEDIA_IMPORT))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun douyinExecutesWithVerifiedVersionAndCapability() {
|
||||||
|
assertTrue(SourceRegistry.executionStatus("douyin", "39.8.0", requested, SourceCapability.HOT_LIST).canExecute)
|
||||||
|
assertTrue(SourceRegistry.executionStatus("douyin", "39.8.0", requested, SourceCapability.DETAIL).canExecute)
|
||||||
|
// 未验证版本拒绝
|
||||||
|
assertFalse(SourceRegistry.executionStatus("douyin", "39.7.0", requested, SourceCapability.HOT_LIST).canExecute)
|
||||||
|
// 未验证能力拒绝
|
||||||
|
assertFalse(SourceRegistry.executionStatus("douyin", "39.8.0", requested, SourceCapability.SHARE_LINK).canExecute)
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun moduleAndPerSourceSwitchesBothGateExecution() {
|
@Test fun moduleAndPerSourceSwitchesBothGateExecution() {
|
||||||
assertEquals("跨平台模块未启用", SourceRegistry.executionStatus("zhihu", "1", requested.copy(enabled = false)).reason)
|
assertEquals("跨平台模块未启用", SourceRegistry.executionStatus("zhihu", "1", requested.copy(enabled = false)).reason)
|
||||||
assertEquals("来源未启用", SourceRegistry.executionStatus("zhihu", "1", requested.copy(zhihuEnabled = false)).reason)
|
assertEquals("来源未启用", SourceRegistry.executionStatus("zhihu", "1", requested.copy(zhihuEnabled = false)).reason)
|
||||||
|
|||||||
@@ -98,16 +98,54 @@ class ArticleTextPolicyTest {
|
|||||||
assertFalse(ArticleTextPolicy.bodyMatches("", listOf("任意")))
|
assertFalse(ArticleTextPolicy.bodyMatches("", listOf("任意")))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 分片模糊命中(2026-11-15 真机修订:OCR 误读「请输→清輪」逐字精确不可行)──────
|
@Test fun bodyMatchesViaHeadSkippedCandidate() {
|
||||||
|
// 2026-11-17 AI 正文真机:段首前几字 OCR 误读率高(「e國e中」式替换只伤段首),
|
||||||
|
// 段尾 30 字第二候选命中即放行(真机复算 skip 固定窗口 0~1/6 不可行,段尾 5/6)。
|
||||||
|
// 尾锚点不变,双候选都未命中仍拒绝——不放行假一致。
|
||||||
|
val firstPara = "首段内容足够长用于锚点定位,开场句第一句先被OCR误读污染,这里写满三十个字符以上的中段句,确保锚点稳健可靠。"
|
||||||
|
val ocrWithCorruptHead = listOf(
|
||||||
|
"取消 草稿已保存",
|
||||||
|
"e國e中这里写满三十个字符以上的中段句,确保锚点稳健可靠。中间段落被编辑",
|
||||||
|
"尾段内容同样足够长用于尾部锚点定位,结尾句写满三十个字符以上,确保双锚点都能命中。",
|
||||||
|
)
|
||||||
|
val ocrOnlyTail = listOf(
|
||||||
|
"尾段内容同样足够长用于尾部锚点定位,结尾句写满三十个字符以上,确保双锚点都能命中。",
|
||||||
|
)
|
||||||
|
val bodyWithLongHead = firstPara + System.lineSeparator() +
|
||||||
|
"中间段落。" + System.lineSeparator() +
|
||||||
|
"尾段内容同样足够长用于尾部锚点定位,结尾句写满三十个字符以上,确保双锚点都能命中。"
|
||||||
|
assertTrue(ArticleTextPolicy.bodyMatches(bodyWithLongHead, ocrWithCorruptHead))
|
||||||
|
// 双候选都未命中仍拒绝
|
||||||
|
assertFalse(ArticleTextPolicy.bodyMatches(bodyWithLongHead, ocrOnlyTail))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── bigram 模糊命中(2026-11-17 修订:分片方案 OCR 错 1 字毁整片,bigram 错 1 字最多毁 2 组)───
|
||||||
|
|
||||||
@Test fun fuzzyContainsToleratesLocalizedOcrErrors() {
|
@Test fun fuzzyContainsToleratesLocalizedOcrErrors() {
|
||||||
// 真机实测误读形态:整行精确匹配失败,分片命中 4/6 ≥ 0.6 放行(0.7 会误拒)
|
// 真机实测误读形态:整行精确匹配失败,bigram 重合率仍远超阈值(分片 0.5 会拒、bigram 0.83 过)
|
||||||
val haystack = "浩瑞机器链路验证正文开始。本段验证文章发布机真机链路:标题写入、正文写入"
|
val haystack = "浩瑞机器链路验证正文开始。本段验证文章发布机真机链路:标题写入、正文写入"
|
||||||
assertTrue(ArticleTextPolicy.fuzzyContains(haystack, "浩瑞机器链路验证正文开始。本段验证文章"))
|
assertTrue(ArticleTextPolicy.fuzzyContains(haystack, "浩瑞机器链路验证正文开始。本段验证文章"))
|
||||||
// 无关内容 0 命中:仍拒绝
|
// 无关内容 0 命中:仍拒绝
|
||||||
assertFalse(ArticleTextPolicy.fuzzyContains("完全无关的页面内容文字", "浩瑞机器链路验证正文"))
|
assertFalse(ArticleTextPolicy.fuzzyContains("完全无关的页面内容文字", "浩瑞机器链路验证正文"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun fuzzyContainsWithScatteredOcrErrors() {
|
||||||
|
// 模拟 OCR 散布形近错字:「请输→清輪」「正文→正女」「已→己」——
|
||||||
|
// 30 字锚点错 3 字,bigram 重合 ~0.79 过 0.5 阈值(分片 3/6=0.5 拒绝)
|
||||||
|
val expected = "标题写入成功正文内容完整回读锚点可定位确保字数对账一致的完整段落"
|
||||||
|
val ocrCorrupted = "标题写入成功正女内容完整回读锚点可定位确保字数对账一致的完整段落"
|
||||||
|
.replace("正女", "正女") // 模拟「正文→正女」
|
||||||
|
// 至少 1 个 bigram 被毁但整体 >0.5
|
||||||
|
assertTrue(ArticleTextPolicy.fuzzyContains(ocrCorrupted, expected))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun fuzzyContainsRejectsUnrelatedText() {
|
||||||
|
// 短锚点退回精确包含:无关文本必须拒绝
|
||||||
|
assertFalse(ArticleTextPolicy.fuzzyContains("完全不同的内容", "标题写入"))
|
||||||
|
// 长锚点 bigram 无关文本必须拒绝
|
||||||
|
assertFalse(ArticleTextPolicy.fuzzyContains("完全无关的页面内容文字与锚点毫无关系", "标题写入成功正文内容完整回读"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun bodyMatchesWithFuzzyAnchorAfterOcrMisread() {
|
@Test fun bodyMatchesWithFuzzyAnchorAfterOcrMisread() {
|
||||||
// 锚点内混入误读字(「清輪入标题」式),分片命中率仍过阈
|
// 锚点内混入误读字(「清輪入标题」式),分片命中率仍过阈
|
||||||
val body = "首段内容足够长用于锚点定位,这里写满三十个字符以上的开场句,确保锚点稳健可靠。" +
|
val body = "首段内容足够长用于锚点定位,这里写满三十个字符以上的开场句,确保锚点稳健可靠。" +
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/** 抖音详情相对时间白名单验收(e1 实测「3天前」形态)。 */
|
||||||
|
class DouyinDetailParserTest {
|
||||||
|
private val nowMs = 1_763_100_000_000L
|
||||||
|
|
||||||
|
@Test fun relativeDayFormFoldsToAbsoluteMs() {
|
||||||
|
val parsed = DouyinDetailParser.parseRelativeTime(listOf("168阿源并不矮", "3天前", "正文行"), nowMs)
|
||||||
|
assertNotNull(parsed)
|
||||||
|
assertEquals("3天前", parsed!!.first)
|
||||||
|
assertEquals(nowMs - 3 * 86_400_000L, parsed.second)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hourAndMinuteFormsFold() {
|
||||||
|
assertEquals(nowMs - 4 * 3_600_000L, DouyinDetailParser.parseRelativeTime(listOf("4小时前"), nowMs)!!.second)
|
||||||
|
assertEquals(nowMs - 12 * 60_000L, DouyinDetailParser.parseRelativeTime(listOf("12分钟前"), nowMs)!!.second)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun unverifiedFormsStayUnknown() {
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(listOf("昨天"), nowMs))
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(listOf("11-15"), nowMs))
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(listOf("2026-11-15"), nowMs))
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(listOf("366天前"), nowMs))
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(listOf("三天前"), nowMs))
|
||||||
|
assertNull(DouyinDetailParser.parseRelativeTime(emptyList(), nowMs))
|
||||||
|
}
|
||||||
|
}
|
||||||
+112
@@ -0,0 +1,112 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
import com.haorui.app.crossplatform.source.SourceNode
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音采集状态机验收:相位顺序、失败相位、安全退出、未知口径与缺值不伪造。
|
||||||
|
*/
|
||||||
|
class DouyinHotListCollectorTest {
|
||||||
|
private val nowMs = 1_763_100_000_000L
|
||||||
|
|
||||||
|
private class FakePort : DouyinHotListCollector.Port {
|
||||||
|
val calls = mutableListOf<String>()
|
||||||
|
var foregroundOk = true
|
||||||
|
var searchOk = true
|
||||||
|
var hotTabOk = true
|
||||||
|
var openEntryOk = true
|
||||||
|
val ocrLines = mutableListOf(
|
||||||
|
"1 习近平将同普京特朗普会晤 1165.9万",
|
||||||
|
"2 第一视角记录APEC瞬间 热 1165.7万",
|
||||||
|
)
|
||||||
|
val detailOcr = mutableListOf("168阿源并不矮", "3天前", "是谁说矮男生学穿搭不好看了")
|
||||||
|
|
||||||
|
override fun ensureAppForeground(): Boolean { calls += "OPEN_APP"; return foregroundOk }
|
||||||
|
override fun openSearch(): Boolean { calls += "OPEN_SEARCH"; return searchOk }
|
||||||
|
override fun openHotListTab(): Boolean { calls += "OPEN_HOT_TAB"; return hotTabOk }
|
||||||
|
override fun readHotListOcrLines(): List<String> { calls += "READ_LIST"; return ocrLines }
|
||||||
|
override fun openEntry(index: Int): Boolean { calls += "OPEN_ENTRY($index)"; return openEntryOk }
|
||||||
|
override fun readDetailOcrLines(): List<String> { calls += "READ_DETAIL"; return detailOcr }
|
||||||
|
override fun readDetailTree(): SourceNode { calls += "READ_DETAIL_TREE"; return SourceNode() }
|
||||||
|
override fun backToHotList(): Boolean { calls += "EXIT/backToHotList"; return true }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun collector(port: FakePort) = DouyinHotListCollector(port) { nowMs }
|
||||||
|
|
||||||
|
@Test fun collectHotListParsesEntriesThroughVerifiedPhases() {
|
||||||
|
val port = FakePort()
|
||||||
|
val result = collector(port).collectHotList()
|
||||||
|
assertEquals("已取得", result.outcome)
|
||||||
|
assertEquals(DouyinHotListCollector.Phase.DONE, result.phase)
|
||||||
|
assertEquals(2, result.entries.size)
|
||||||
|
assertEquals("习近平将同普京特朗普会晤", result.entries[0].title)
|
||||||
|
assertTrue(result.exitedSafely)
|
||||||
|
assertEquals(
|
||||||
|
listOf("OPEN_APP", "OPEN_SEARCH", "OPEN_HOT_TAB", "READ_LIST", "EXIT/backToHotList"),
|
||||||
|
port.calls,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun emptyListFailsAtReadListAndExitsSafely() {
|
||||||
|
val port = FakePort().apply { ocrLines.clear(); ocrLines += "抖音热榜" }
|
||||||
|
val result = collector(port).collectHotList()
|
||||||
|
assertEquals("失败", result.outcome)
|
||||||
|
assertEquals(DouyinHotListCollector.Phase.READ_LIST, result.phase)
|
||||||
|
assertEquals("热榜清单为空或 OCR 未读到合格行", result.reason)
|
||||||
|
assertTrue(result.exitedSafely)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun foregroundFailureFailsAtOpenAppWithoutFurtherNavigation() {
|
||||||
|
val port = FakePort().apply { foregroundOk = false }
|
||||||
|
val result = collector(port).collectHotList()
|
||||||
|
assertEquals(DouyinHotListCollector.Phase.OPEN_APP, result.phase)
|
||||||
|
assertEquals("抖音未能进入前台", result.reason)
|
||||||
|
assertEquals(listOf("OPEN_APP", "EXIT/backToHotList"), port.calls)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun hotTabFailureFailsAtOpenHotTab() {
|
||||||
|
val port = FakePort().apply { hotTabOk = false }
|
||||||
|
val result = collector(port).collectHotList()
|
||||||
|
assertEquals(DouyinHotListCollector.Phase.OPEN_HOT_TAB, result.phase)
|
||||||
|
assertEquals("「抖音热榜」Tab 未切换成功", result.reason)
|
||||||
|
assertFalse(port.calls.contains("READ_LIST"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun collectOneProducesObservationWithUnknowns() {
|
||||||
|
val port = FakePort()
|
||||||
|
val result = collector(port).collectOne(1)
|
||||||
|
assertEquals("已观察", result.outcome)
|
||||||
|
val obs = result.observation!!
|
||||||
|
assertEquals("第一视角记录APEC瞬间", obs.hotEntry!!.title)
|
||||||
|
assertEquals("热", obs.hotEntry!!.label)
|
||||||
|
// 详情 OCR 含「3天前」:相对时间折算
|
||||||
|
assertEquals("3天前", obs.publishedAtText)
|
||||||
|
assertEquals(nowMs - 3 * 86_400_000L, obs.publishedAtMs)
|
||||||
|
// 作者/正文未核验口径 → 显式未知
|
||||||
|
assertTrue(obs.unknowns.any { it.startsWith("作者未知") })
|
||||||
|
assertTrue(obs.unknowns.any { it.startsWith("正文未知") })
|
||||||
|
// SAVE_OBSERVATION 是内部相位赋值(不触发 Port),不出现在调用记录里
|
||||||
|
assertEquals(
|
||||||
|
listOf("OPEN_APP", "OPEN_SEARCH", "OPEN_HOT_TAB", "READ_LIST", "OPEN_ENTRY(1)", "READ_DETAIL", "READ_DETAIL_TREE", "EXIT/backToHotList"),
|
||||||
|
port.calls,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun entryIndexOutOfRangeFailsAtOpenEntry() {
|
||||||
|
val port = FakePort()
|
||||||
|
val result = collector(port).collectOne(9)
|
||||||
|
assertEquals("失败", result.outcome)
|
||||||
|
assertEquals(DouyinHotListCollector.Phase.READ_LIST, result.phase)
|
||||||
|
assertEquals("热榜第 9 条不存在", result.reason)
|
||||||
|
assertFalse(port.calls.any { it.startsWith("OPEN_ENTRY") })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun runGenerationIsRecordedOnObservation() {
|
||||||
|
val port = FakePort()
|
||||||
|
val machine = collector(port)
|
||||||
|
machine.runGeneration = 7
|
||||||
|
val result = machine.collectOne(0)
|
||||||
|
assertEquals(7, result.observation!!.runGeneration)
|
||||||
|
}
|
||||||
|
}
|
||||||
+219
@@ -0,0 +1,219 @@
|
|||||||
|
package com.haorui.app.crossplatform.source.douyin
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抖音热榜解析器验收(2026-11-16 e1 取证形态,OCR 行输入)。
|
||||||
|
* 样本行来自 e1 截图实测词条(排名/标题/标签/热度形态)。
|
||||||
|
*/
|
||||||
|
class DouyinHotListParserTest {
|
||||||
|
|
||||||
|
@Test fun parsesVerifiedListRows() {
|
||||||
|
val entries = DouyinHotListParser.parse(listOf(
|
||||||
|
"1 习近平将同普京特朗普会晤 1165.9万",
|
||||||
|
"2 第一视角记录APEC瞬间 热 1165.7万",
|
||||||
|
"12 茉茉手势舞 挑战 918.4万",
|
||||||
|
))
|
||||||
|
assertEquals(3, entries.size)
|
||||||
|
assertEquals("习近平将同普京特朗普会晤", entries[0].title)
|
||||||
|
assertEquals(1, entries[0].rank)
|
||||||
|
assertEquals(null, entries[0].label)
|
||||||
|
assertEquals("1165.9万", entries[0].heatRaw)
|
||||||
|
assertEquals(11_659_000L, entries[0].heatValue)
|
||||||
|
assertFalse(entries[0].heatMissing)
|
||||||
|
assertEquals("热", entries[1].label)
|
||||||
|
assertEquals("第一视角记录APEC瞬间", entries[1].title)
|
||||||
|
assertEquals("挑战", entries[2].label)
|
||||||
|
assertEquals(12, entries[2].rank)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun topRowWithoutRankOrHeatIsRejected() {
|
||||||
|
// e1 实测置顶行「习近平主席这样推介中国深圳」:无排名无热度 → 噪音拒绝
|
||||||
|
assertNull(DouyinHotListParser.parseLine("习近平主席这样推介中国深圳", 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rankedRowWithoutHeatKeepsEntryMarkedMissing() {
|
||||||
|
val entry = DouyinHotListParser.parseLine("9 詹皇迎里程碑 76人力克步行者 热", 8)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals(9, entry!!.rank)
|
||||||
|
assertEquals("热", entry.label)
|
||||||
|
assertNull(entry.heatValue)
|
||||||
|
assertTrue(entry.heatMissing)
|
||||||
|
assertEquals("詹皇迎里程碑 76人力克步行者", entry.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun gluedLabelStaysInTitleAndLabelStaysUnknown() {
|
||||||
|
// OCR 粘连:标签与标题无空格分隔 → 不剥离,label=null(缺值不伪造)
|
||||||
|
val entry = DouyinHotListParser.parseLine("3 第一视角记录APEC瞬间热 1141.7万", 2)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals("第一视角记录APEC瞬间热", entry!!.title)
|
||||||
|
assertNull(entry.label)
|
||||||
|
assertEquals(11_417_000L, entry.heatValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun plainNumberSuffixWithoutWanIsNotHeat() {
|
||||||
|
// 「922」不带万:可能是页码等噪音 → 不认热度
|
||||||
|
val entry = DouyinHotListParser.parseLine("10 不穿贵的只穿帅的 922", 9)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertNull(entry!!.heatRaw)
|
||||||
|
assertTrue(entry.heatMissing)
|
||||||
|
assertEquals("不穿贵的只穿帅的 922", entry.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun multiWordTitlesKeepSpacing() {
|
||||||
|
val entry = DouyinHotListParser.parseLine("11 DeepSeek因算力不足限额 新 919.3万", 10)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals("DeepSeek因算力不足限额", entry!!.title)
|
||||||
|
assertEquals("新", entry.label)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun nonListLinesAreSkipped() {
|
||||||
|
val entries = DouyinHotListParser.parse(listOf(
|
||||||
|
"",
|
||||||
|
"猜你想看",
|
||||||
|
"抖音热榜",
|
||||||
|
"宁波榜",
|
||||||
|
"办公桌下的鞋子",
|
||||||
|
"语音搜索",
|
||||||
|
"15 司空震FMVP新皮肤 900.1万",
|
||||||
|
))
|
||||||
|
// Tab 名/搜索历史/按钮等噪音行全部静默跳过;只留合格榜单行
|
||||||
|
assertEquals(1, entries.size)
|
||||||
|
assertEquals("司空震FMVP新皮肤", entries[0].title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun heatConversionCoversVerifiedForms() {
|
||||||
|
assertEquals(11_659_000L, DouyinHotListParser.parseHeat("1165.9万"))
|
||||||
|
assertEquals(9_000_000L, DouyinHotListParser.parseHeat("900万"))
|
||||||
|
assertEquals(921_100_000L, DouyinHotListParser.parseHeat("92110万"))
|
||||||
|
assertNull(DouyinHotListParser.parseHeat("922"))
|
||||||
|
assertNull(DouyinHotListParser.parseHeat("1165.9"))
|
||||||
|
assertNull(DouyinHotListParser.parseHeat("万"))
|
||||||
|
assertNull(DouyinHotListParser.parseHeat(null))
|
||||||
|
assertNull(DouyinHotListParser.parseHeat("-5万"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rankRangeIsBounded() {
|
||||||
|
// 3 位以上数字开头不是排名(如年份「2026 某某」),无排名即拒绝(有热度也不留)
|
||||||
|
assertNull(DouyinHotListParser.parseLine("2026 新年первый 900万", 0))
|
||||||
|
// 99 上限:100+ 不认
|
||||||
|
assertNull(DouyinHotListParser.parseLine("100 远超榜单上限的行 900万", 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 行合并预处理(OCR 拆行修复) ──────────────────────────
|
||||||
|
|
||||||
|
@Test fun mergesSplitRankTitleHeatRows() {
|
||||||
|
// OCR 把一行拆成 3 行:排名/标题/热度
|
||||||
|
val merged = DouyinHotListParser.mergeAdjacentLines(listOf(
|
||||||
|
"1", "习近平将同普京特朗普会晤", "1165.9万",
|
||||||
|
))
|
||||||
|
assertEquals(1, merged.size)
|
||||||
|
assertEquals("1 习近平将同普京特朗普会晤 1165.9万", merged[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun mergesSplitRankTitleRows() {
|
||||||
|
// OCR 把一行拆成 2 行:排名/标题(无热度)
|
||||||
|
val merged = DouyinHotListParser.mergeAdjacentLines(listOf(
|
||||||
|
"7", "APEC普逼人秒僅指南",
|
||||||
|
))
|
||||||
|
assertEquals(1, merged.size)
|
||||||
|
assertEquals("7 APEC普逼人秒僅指南", merged[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun mergesHeatOntoPreviousEntryLine() {
|
||||||
|
// 已有条目行(含排名)+ 纯热度行 → 追加
|
||||||
|
val merged = DouyinHotListParser.mergeAdjacentLines(listOf(
|
||||||
|
"3 中国贸易伙伴网越织越密", "1112.4万",
|
||||||
|
))
|
||||||
|
assertEquals(1, merged.size)
|
||||||
|
assertEquals("3 中国贸易伙伴网越织越密 1112.4万", merged[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun standaloneLinesPassThrough() {
|
||||||
|
// 噪音行/整行条目原样保留
|
||||||
|
val merged = DouyinHotListParser.mergeAdjacentLines(listOf(
|
||||||
|
"上热门",
|
||||||
|
"1 习近平将同普京特朗普会晤 1209.8万",
|
||||||
|
"猜你想看 抖音热榜",
|
||||||
|
))
|
||||||
|
assertEquals(3, merged.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun mergesMultipleSplitEntries() {
|
||||||
|
// 连续多条拆行条目依次合并
|
||||||
|
val merged = DouyinHotListParser.mergeAdjacentLines(listOf(
|
||||||
|
"1", "标题一", "1000万",
|
||||||
|
"2", "标题二", "900万",
|
||||||
|
"3", "标题三",
|
||||||
|
))
|
||||||
|
assertEquals(3, merged.size)
|
||||||
|
assertEquals("1 标题一 1000万", merged[0])
|
||||||
|
assertEquals("2 标题二 900万", merged[1])
|
||||||
|
assertEquals("3 标题三", merged[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── OCR 容错解析(排名无空格/前缀清洗/热度无空格) ──────────
|
||||||
|
|
||||||
|
@Test fun parsesRankWithoutSpaceBeforeTitle() {
|
||||||
|
// OCR 把排名和标题粘连:「5APEC参会嘉宾陆续抵达…1050.3万」
|
||||||
|
val entry = DouyinHotListParser.parseLine("5APEC参会嘉宾陆续抵达…1050.3万", 0)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals(5, entry!!.rank)
|
||||||
|
assertEquals("APEC参会嘉宾陆续抵达…", entry.title)
|
||||||
|
assertEquals(10_503_000L, entry.heatValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun stripsNonDigitPrefixBeforeRank() {
|
||||||
|
// OCR 混入 "|" 前缀:「|4在深圳读懂APEC中国故事家1109.7万」
|
||||||
|
val entry = DouyinHotListParser.parseLine("|4在深圳读懂APEC中国故事家1109.7万", 0)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals(4, entry!!.rank)
|
||||||
|
assertEquals("在深圳读懂APEC中国故事家", entry.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rejectsTitleStartingWithDigitToPreventRankFalseMatch() {
|
||||||
|
// 「2026年APECI商领导人…:日1138.6万」——排名"2026"不是 1~2 位,标题以数字开头
|
||||||
|
val entry = DouyinHotListParser.parseLine("2026年APECI商领导人…:日1138.6万", 0)
|
||||||
|
// 排名 2026 超范围 → null;即使误匹配排名 2,标题"026年…"以数字开头也被拒
|
||||||
|
assertNull(entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun parsesHeatWithoutSpaceBeforeIt() {
|
||||||
|
// 热度前无空格:「7 APEC普通人秒懂指南 1209.8万」vs「7 APEC普通人秒懂指南1209.8万」
|
||||||
|
val entry = DouyinHotListParser.parseLine("7 APEC普通人秒懂指南1209.8万", 0)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals(7, entry!!.rank)
|
||||||
|
assertEquals(12_098_000L, entry.heatValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rejectsTimestampAsRank() {
|
||||||
|
// 时间戳「16:06 P車區中A」——排名"16"后跟冒号=时间戳,拒绝
|
||||||
|
assertNull(DouyinHotListParser.parseLine("16:06 P車區中A", 0))
|
||||||
|
assertNull(DouyinHotListParser.parseLine("16:07 困中A", 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rejectsSingleCharTitleAsNoise() {
|
||||||
|
// 单字符标题「G」= OCR 噪音,拒绝
|
||||||
|
assertNull(DouyinHotListParser.parseLine("5 G", 0))
|
||||||
|
assertNull(DouyinHotListParser.parseLine("5G", 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun rejectsNumericOnlyTitlesAsNoise() {
|
||||||
|
// 纯数字/小数点标题 = OCR 噪音(如「32.9」「.9」「100」),拒绝
|
||||||
|
assertNull(DouyinHotListParser.parseLine("32.9", 0))
|
||||||
|
assertNull(DouyinHotListParser.parseLine("32 .9", 0))
|
||||||
|
assertNull(DouyinHotListParser.parseLine("5 100", 0))
|
||||||
|
assertNull(DouyinHotListParser.parseLine("5 .9", 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun cleansHeatFromTitle() {
|
||||||
|
// 标题中残留热度样式文本清理:「7 APEC峰会有哪些国家元首…留936.9万 1049.5万」
|
||||||
|
val entry = DouyinHotListParser.parseLine("7 APEC峰会有哪些国家元首…留936.9万 1049.5万", 0)
|
||||||
|
assertNotNull(entry)
|
||||||
|
assertEquals(7, entry!!.rank)
|
||||||
|
// 标题中"936.9万"被清理,热度取行尾"1049.5万"
|
||||||
|
assertEquals("APEC峰会有哪些国家元首…留", entry.title)
|
||||||
|
assertEquals(10_495_000L, entry.heatValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-1
@@ -29,7 +29,7 @@
|
|||||||
| 共享账户额度 | 共享事务与旧快照已实现;本轮新增 LegacyPublishSession,并接入旧 PublishMachine 的准备、指纹、单次点击、取消与未知回执分支。事务已提交而返回值因取消丢失时,按预生成 ID 定位;库中已领取点击许可的预占不释放。M6 强回执未接通,混合正式入口继续关闭;草稿及无共享历史的旧独立模式保留 |
|
| 共享账户额度 | 共享事务与旧快照已实现;本轮新增 LegacyPublishSession,并接入旧 PublishMachine 的准备、指纹、单次点击、取消与未知回执分支。事务已提交而返回值因取消丢失时,按预生成 ID 定位;库中已领取点击许可的预占不释放。M6 强回执未接通,混合正式入口继续关闭;草稿及无共享历史的旧独立模式保留 |
|
||||||
| 旧视频草稿 | **新版真机复测通过(2026-11-14 17:31)**:有效声明→回读→单次保存→明确“保存草稿成功”回执→草稿箱持久化(`浩瑞草稿回归 1004aef5`);testDraftInvalid 在 PREPARE 即暂停“不受当前版本支持”;未知结果保护有 14:38/16:11/16:41 三次证据(暂停、素材保留、`files/pending-drafts/` 记录保留,核对后清除)。OCR 回执判定为“非汉字承接”规则(⊙ 图标实测被误读为 0/O/。 并与位置卡片文本同行合并)。待核对处置界面仍未实现(现为人工核对后清理记录);旧配置“内容为原创”仍待用户改选 |
|
| 旧视频草稿 | **新版真机复测通过(2026-11-14 17:31)**:有效声明→回读→单次保存→明确“保存草稿成功”回执→草稿箱持久化(`浩瑞草稿回归 1004aef5`);testDraftInvalid 在 PREPARE 即暂停“不受当前版本支持”;未知结果保护有 14:38/16:11/16:41 三次证据(暂停、素材保留、`files/pending-drafts/` 记录保留,核对后清除)。OCR 回执判定为“非汉字承接”规则(⊙ 图标实测被误读为 0/O/。 并与位置卡片文本同行合并)。待核对处置界面仍未实现(现为人工核对后清理记录);旧配置“内容为原创”仍待用户改选 |
|
||||||
| 稳定账号读取 | 18.3.0 自身主页、名片及二维码读取代码已实现,唯一数字 user_id 哈希为账户键;两次独立取证并复核自身资料,昵称和分享追踪字段不作为身份。只读核验不绑定预算,不授予后续运行发布许可 |
|
| 稳定账号读取 | 18.3.0 自身主页、名片及二维码读取代码已实现,唯一数字 user_id 哈希为账户键;两次独立取证并复核自身资料,昵称和分享追踪字段不作为身份。只读核验不绑定预算,不授予后续运行发布许可 |
|
||||||
| 知乎、小红书、微博、抖音采集 | **知乎(M2 完成)**:四解析器+采集状态机+Port 真机实现,177 项 JVM,e2e 验收通过;能力门控按用户决定暂不放行。**小红书(搁置)**:用户判定内容调性不适合头条,e1 取证存档。**微博(M2 完成,e2e 验收通过 2026-11-15)**:热搜清单解析器+树/OCR 双源详情解析+采集状态机+`WeiboDevicePort`(37 轮 e2e 收敛出 12 项真机缺陷修复:弹窗拒绝项/残留页收拢/大页面有界探测/desc 渲染/双详情布局/离屏节点/原生滚动/搜索框兜底等);**单条内容全链实测**:`已观察 phase=DONE`,时间=「添加了问题」同款实测、互动数树提取、分享链 `weibo.com/<UID>/<博文ID>` 解析配对成功。**产品口径(用户定)**:类目下拉多选(9 类)→按类目拉榜单→人工勾选→图文/视频独立开关发头条。抖音未动 |
|
| 知乎、小红书、微博、抖音采集 | **知乎(M2 完成)**:四解析器+采集状态机+Port 真机实现,177 项 JVM,e2e 验收通过;能力门控按用户决定暂不放行。**小红书(搁置)**:用户判定内容调性不适合头条,e1 取证存档。**微博(M2 完成,e2e 验收通过 2026-11-15)**:热搜清单解析器+树/OCR 双源详情解析+采集状态机+`WeiboDevicePort`(37 轮 e2e 收敛出 12 项真机缺陷修复)。**抖音(2026-11-17 🎉 全链 Confirmed)**:SourceRegistry→OCR 采集→AI 创作(事实包→正文→标题)→落库→状态推进→门控→图文机器→**bigram 长文回读→草稿回执→Confirmed**。全链全自动闭环达成(2 分 24 秒)。残留:openEntry 间歇失败、OCR 热度形近错字 |
|
||||||
| 头条图文与跨平台视频 | 事实补全、标题生成、正文生成、**编辑器写入/回读/草稿核对全链真机跑通**(ArticlePublishMachine,outcome=草稿已核对);**M5 视频闭环全部完成**:媒体层四件+导入器(真机 22 项 0 失败)+草稿车道端到端(ACTION_SEND→标题/声明→存草稿→明确回执→素材核销,4 轮修 3 缺陷);**M6 协调器全链真机闭环**(门控 ALLOW/credit 100 分→领取→落库→桥接执行→归账 Dispatched+Confirmed,38 秒);M6 剩余:恢复场景(跨日/断网/崩溃核对)+ 混合 4 小时长跑 + 跨日验收;「下一步」二阶段、声明控件、MediaStore 生产导入(待授权)、正式发布(等 M6 长跑验收)未开放;AUTO 未开放,没有执行真实跨平台发布 |
|
| 头条图文与跨平台视频 | 事实补全、标题生成、正文生成、**编辑器写入/回读/草稿核对全链真机跑通**(ArticlePublishMachine,outcome=草稿已核对);**M5 视频闭环全部完成**:媒体层四件+导入器(真机 22 项 0 失败)+草稿车道端到端(ACTION_SEND→标题/声明→存草稿→明确回执→素材核销,4 轮修 3 缺陷);**M6 协调器全链真机闭环**(门控 ALLOW/credit 100 分→领取→落库→桥接执行→归账 Dispatched+Confirmed,38 秒);M6 剩余:恢复场景(跨日/断网/崩溃核对)+ 混合 4 小时长跑 + 跨日验收;「下一步」二阶段、声明控件、MediaStore 生产导入(待授权)、正式发布(等 M6 长跑验收)未开放;AUTO 未开放,没有执行真实跨平台发布 |
|
||||||
|
|
||||||
## 本轮验证与交付物
|
## 本轮验证与交付物
|
||||||
@@ -106,6 +106,24 @@ gradle --offline :app:testDebugUnitTest :app:assembleDebug :app:assembleDebugAnd
|
|||||||
|
|
||||||
| 日期 | 事项 | 验证范围 |
|
| 日期 | 事项 | 验证范围 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
| 2026-11-17 | **🎉 bigram 回读修复——AI 正文全链 Confirmed(a2359b9)**:`fuzzyContains` 5 字分片→bigram 二字组重合率(错 1 字最多毁 2 组 vs 分片毁整片),阈值 0.65(Python 标定:段间共用短语 ≤0.62、污染段尾 0.83)。**真机全链闭环**:采集→事实包 1016 字→AI 创作(标题 17 字+正文 1039 字)→落库 gen=627 三跳全 true→门控 ALLOW→图文机器写入→**bigram 双锚点回读通过**(字数 1017 对账+锚点可定位)→草稿回执→**Confirmed**。真库 `DRAFT_SAVED|CONFIRMED` 实锤。**抖音 AI 创作→图文发布全链全自动闭环达成** | 321 项 JVM 全过(+2 bigram 用例);真机日志 `haorui-20261117-233143.log`(全链 2 分 24 秒);草稿箱 3 条待用户核对(2 条 DRAFT_SAVED+1 条 RESULT_UNKNOWN×2) |
|
||||||
|
| 2026-11-17 | **长文回读修复批次(ebbed5e)**:①scrollToTop 预算 10→25+连续 2 次稳定判定——真机实锤 16 次反向滑到顶(旧 10 次必败=首锚点永不入视野根因),滚顶与下扫到页底均修复;②bodyMatches 首锚点双候选(段首∪段尾,固定跳头窗口真机复算 0~1/6 不可行、段尾 5/6);③confirmNotSubmitted 归 SKIPPED 终态(旧版孤儿 PAUSED 永远卡死);④沙盒孤儿重建(deleteTask+重 enqueue)。**残留**:AI 正文回读锚点仍失败——OCR 对多标点/数字混排(「22:26 @!中A」)形近错字密度超分片 0.6 阈值,归账 Unknown 保护正确;锚点对抗需 bigram 相似度+真机标定(下轮)。**新工具验证**:`ACTION_TEST_CROSS_DISPATCH --ez article true --es accountKey douyin-local` 可直接领取库中 READY 任务(本轮用它重试,门控 HOLD 后 READY 留库下窗领取成功) | 319 项 JVM 全过;真机:滚顶 16 次/下扫页底/归账 Unknown 全链证据 `haorui-20261117-222117.log`;真库 rank7-568040792 RESULT_UNKNOWN 实锤 |
|
||||||
|
| 2026-11-17 | **抖音 AI 创作链接入(d55d41f)**:M4 组件复用——`readDetailOcrFullText`(详情逐屏 OCR 4 屏+行序去重)+ onDetail 钩子取材料(EXIT 后读屏=榜单教训复用)+ 热榜元数据注入材料头部;失败降级模板不阻塞;幂等键不随 AI 标题漂移。**真机全绿**:事实包 885 字→提纲 5 要点→正文 1431 字第 1 稿过三关→标题 3 候选 0 淘汰(AI 修正 OCR 形近错字「责州→贵州」)→gen=617 三跳全 true→写入+回读;1431 字长文回读「反向滑 10 次未稳定」锚点未命中→**宁核对不误判暂停→Unknown 归账**(设计内保护) | 318 项 JVM 全过;真库 `RESULT_UNKNOWN|UNKNOWN` 实锤;日志 `haorui-20261117-220028.log`;**新增待办:长文回读锚点丢失(readBodyOcrFull 对超长文档反向滑不稳)待修;草稿箱待用户核对** |
|
||||||
|
| 2026-11-17 | **抖音全链分发首次真机闭环(11 轮迭代)**:采集→落库→FILTERED→PREPARED→READY→门控 ALLOW→协调器领取→图文机器→草稿回执→归账 **Confirmed**,真库实锤 `douyin-rank7-663302033|DRAFT_SAVED|CONFIRMED`。关键修复:①**代际统一**(根因:三跳/领取共用任务库 run_control 代际,服务 startGeneration 是另一命名空间,混用致 active() 全拒);②**采集分发同沙盒单代际**(beginRun 每次+1 且 READY 全 PAUSED,拆两沙盒永远追不上);③prepare 补 payloadHash(64 位 hex 策略门槛);④旧 PAUSED 残留重采 resumeTask 重绑代际;⑤ARTICLE executor 双处路由(Confirmed/NotSubmitted/Unknown 归账语义);⑥openArticleEditor 深层页 BACK 收拢(处罚中心/全部服务;创作中心同款锚点方向相反已排除);⑦openEntry 截屏限流退避重试 | 318 项 JVM 全过;真机 11 轮日志 `.tmp/douyin-dispatch/`+`haorui-20261117-213237.log`(全链 51 秒);已知残留:openEntry 间歇性失败(榜单排位漂移)、SKIPPED 终态任务不可复活(同条目跨天重采无法重试,策略缺口待定)、NotSubmitted 归账落 PAUSED 非 SKIPPED(库记录待核语义) |
|
||||||
|
| 2026-11-17 | **抖音任务策略检查修复——补齐必备字段**:`sourceUrl=douyin://hot/{rank}`(占位链接)、`publishedAtMs`(OCR 时间或当前时间)、`expiresAtMs=7 天`、`payloadHash=SHA-256(标题+正文)`。策略检查 6 项全通过 | 318 项 JVM 全过;编译通过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音任务状态推进——标准发布流程接入**:落库后自动推进 `DISCOVERED→FILTERED→PREPARED→READY`(走标准发布流程:筛选→准备→就绪)。任务到达 `READY` 后可被 `PublishCoordinator` 领取发布 | 318 项 JVM 全过;编译通过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音图文发布——热榜标题生成模板正文**:落库时生成 `ARTICLE` 任务(模板正文:排名/热度/标签/发布时间)。图文发布路线(用户选定):先用热榜标题生成文章发头条,视频发布链等视频下载方案确定后再接 | 318 项 JVM 全过;编译通过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音采集接入主任务库——落库逻辑**:`startDouyinCollectSandbox` 单条模式采集成功后 `enqueue` 到任务库(仿微博模式:幂等键+evidenceJson 记录 rank/heat/label/unknowns)。**抖音采集链路完整闭环**:SourceRegistry 放行→采集→落库 | 318 项 JVM 全过;编译通过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音 SourceRegistry 放行——采集能力正式验收**:`SourceRegistry` 抖音条目设置 `verifiedVersions=setOf("39.8.0")` + `capabilities=setOf(HOT_LIST, DETAIL)`;未取证能力(SHARE_LINK/MEDIA_IMPORT)不列入。`SourceRegistryTest` 新增 2 项放行用例(验证版本/能力门控正确拒绝未验证组合)。**抖音采集能力正式放行到生产采集链** | 318 项 JVM 全过(新增 2 项);编译通过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音单条详情采集首次跑通(r32~r33)——采集全链里程碑**:①搜索页判据修复(r33:搜索按钮点击后可能停留在「上热门」页 Tab 行=「上热门话題榜\|宁波榜\|直播榜」,必须等「猜你想看」出现才算进入搜索页);②Tab 宽松匹配(「热榜」而非「抖音热榜」抗 OCR 误读);③**单条详情采集成功**:`outcome=已观察 phase=DONE`,标题=APEC普通人秒僅捐南 排名=6,未知字段如实记录(热度/发布时间/作者/正文=OCR 精度限制)。**抖音采集全链首次跑通**:Tab 动态定位→帧追赶→openEntry→详情观察 | 316 项 JVM 全过;真机实测单条详情采集成功;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **抖音 Tab 动态定位+openEntry 修复(r30~r31)**:①Tab 行 y 位置随搜索词/广告横幅动态变化(e1 校准 y=1154 不可靠)→ OCR 动态定位行 bounds 中心点击;②BACK 退出搜索页 bug 修复(不再 BACK,顶部空白区关浮层);③openEntry 与 collectOne 读不同帧导致 entry 不一致 → openEntry 自己重读解析按标题碎片匹配。**17:34 轮实测成功**:Tab 动态定位 `x=362 y=1156 行bounds=Rect(61,1135-491,1177)`、帧追赶解析 5 条(历史最佳)、openEntry 尝试打开词条。**残留**:Tab 点击间歇性失败(17:45 轮 OCR 未找到 Tab 行)——页面状态波动导致,需增加 Tab 行存在性检查与重试 | 316 项 JVM 全过;真机动态定位实测成功一轮;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **OCR 解析优化——抖音热榜解析条数 1→4~6 条**:①行合并预处理(OCR 拆行修复:排名/标题/热度三行拼回一条,5 项用例)②排名容错(无空格「5APEC」→排名 5+标题、非数字前缀「\|4」→排名 4、标题首字符数字/冒号拒绝防「2026年APEC」误匹配排名 2、时间戳「16:06」拒绝)③热度容错(无空格「…1050.3万」提取)④标题热度清理(残留「数字+万」样式清理)⑤噪音过滤(单字符标题「G」拒绝)。真机沙盒实测:解析条数 1→6 条(帧追赶第 3 轮最优 6 条)、时间戳误匹配清零、排名容错生效。**当前残留**:OCR 形近错字致热度误读(「1107,4万」→「4万」)和重复条目——属 OCR 引擎精度问题,解析器层面已到天花板 | 315 项 JVM 全过(新增 12 项 OCR 容错用例);真机沙盒实测解析 4~6 条;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **MediaProjection 独立截屏通道落地——抖音采集数据源问题根本解决**:`ProjectionHolder`(授权→VirtualDisplay+ImageReader 消费式监听→帧锁保护)+`ProjectionCapturer`(对齐 ScreenCapturer 签名)+抖音 Port 三处截屏点投影优先;授权入口挂我的页「屏幕采集授权」(registerForActivityResult→系统弹窗用户亲手点)。**沙盒清单模式全链稳定通过**:OPEN_APP→OPEN_SEARCH→OPEN_HOT_TAB(绝对坐标 (404,1154)+点顶部空白关浮层)→READ_LIST→EXIT,outcome=已取得 phase=DONE entries=1(排名=7 标题逐字可辨)。修复链:①惰性取帧→消费式监听(r25:acquireLatestImage 无消费拿不到帧)②runBlocking+Main 死锁→投影就绪时不回退 takeScreenshot(r27)③旧投影 onStop 迟到回调清掉新投影→currentProjection 换代识别(r26)④回收中位图被拷贝竞态→frameLock(r29 崩溃实证)⑤「语音搜索」浮层压 Tab 点击→点顶部空白区关浮层(r27/r28)⑥Tab 行内比例定位不稳→绝对坐标 (404,1154)(e1 校准)。**当前瓶颈**:OCR 解析质量(51 行累计仅出 1 条,形近错字致标题误读)——下一步优化解析器容错或 OCR 后处理 | 303 项 JVM 全过;真机 11 轮授权+沙盒迭代日志 `.tmp/douyin-evidence/`;投影通道稳定性实证(1590 帧持续产出);手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **帧追赶策略四变体复验(r21~r24)——缓存刷新不可控,方向②在 READ_LIST 相位遇硬墙**:r21 微手势 6 轮 45 行全旧帧(0 条);r22 半屏真实滚动 5 屏 49 行全旧帧(推翻"手势推帧"假设);r23 点 Tab 触发帧推进(每轮 5~11 新行)但 OCR 行内比例定位不稳点过界切回猜你想看页;r24 改绝对坐标后 Tab 行 OCR 不可读空转超时。**收敛判断**:缓存刷新是概率性事件(r20 命中 1 条无法复现),服务内读屏在抖音搜索页**不可作为数据源**——READ_LIST 相位的本质是读屏取数,与判定冻结是同一堵墙。方向②(信任直行)只打通了导航相位,数据采集相位需要数据源替代方案。可行出路:①**无障碍事件流采集**(服务 onAccessibilityEvent 被动收 TYPE_WINDOW_CONTENT_CHANGED——r4 实证搜索页无此事件,此路不通)②**MediaProjection 独立截屏通道**(用户授权一次屏幕录制,App 内实时帧不受无障碍缓存影响——需新增授权流程)③**回到微博/知乎等无防护来源做主力,抖音降级为"手动勾选+服务直行点击"半自动** | r21~r24 全部日志+截屏 `.tmp/douyin-evidence/`;303 项 JVM 全过;手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-17 | **方案②沙盒信任直行落地——抖音采集清单模式全链首次打通(r20)**:`openHotListTab` 改信任直行(OCR 定位点击 retry=true → 静默 12s → 推进,不判定),`readHotListOcrLines` 前置 6px 微手势推进快照;真机实测 **OPEN_APP→OPEN_SEARCH→OPEN_HOT_TAB→READ_LIST→EXIT 全链 outcome=已取得 phase=DONE**,OCR 38 行解析出榜单第 3 条「中国贸易伙伴网越织越密」(标题与截图逐字吻合,热度/标签未解析出——快照部分刷新)。缓存行为量化:点击 Tab 后首帧仍旧、微手势后帧部分推进(能命中 1 条)。⚠️ 信任直行仅限沙盒:生产放行前判定问题(外部桥/换入口)必须解决。下一步:①readHotListOcrLines 多手势推进帧直到解析≥2 条(帧追赶策略)②单条详情模式 entryIndex 复验 ③SourceRegistry 放行决策 | r20 日志(`haorui-20261117-100808.log`:outcome=已取得 phase=DONE entries=1)+ 截图实锤榜单第 3 条逐字吻合;303 项 JVM 全过;手机已 HOME 收尾 |
|
||||||
|
| 2026-11-17 | **抖音热榜 Tab 相位复验 12 轮(r8~r19)——点击全生效、判定被系统性冻结,根因定案**:r9~r11 修 Tab 行内偏移(OCR 行=「猜你想看 抖音热榜」,词中心≈行宽 76%);r12 修搜索框残留词条跳详情(openSearch 判据排除详情页特征);r13/r14 静默等待失败;r15 修冷启动手势被吞(tapAt retry=true);r17 树判据失败;r18 静默 15s 单读失败;r19 事件刷新失败。**每轮失败后 adb screencap 均实锤热榜已切换**(榜单 1~7+热度+热标签完整在屏),而服务内树与 OCR 双通道在静默/轮询/事件制造三种手段下全部读到点击前旧帧——定案:**抖音对无障碍 takeScreenshot 通道主动缓存**(自绘+摘要化页面无内容变更事件,服务侧窗口快照不刷新;头条/微博无此防护),服务内一切判定手段不可用,唯一实时通道是外部 shell screencap。Phase 推进不变:OPEN_APP✓→OPEN_SEARCH✓→OPEN_HOT_TAB「点击成功但判定不可行」。下一步方案(待决策):①判定走外部桥(如 adb 协同/通知回调)②沙盒模式下直接信任点击+固定延时前进(风险:状态漂移)③放弃热榜 Tab 路线改抖音搜索框直搜「热点」等入口 | 12 轮日志+每轮失败后截屏 `.tmp/douyin-evidence/`(r11~r19-after 全留档);303 项 JVM 全过(`.tmp/dy-final-test.log`);手机已 HOME+force-stop 收尾 |
|
||||||
|
| 2026-11-16 | **筛选重构(全来源专属化)+ 抖音 Port 真机接线(6 轮迭代)**:①热点选题区来源 chips 精简为知乎/微博/抖音(通用 chip 删、小红书从来源管理与选题区全部移除),知乎专属筛选落地(热榜卡片区间 start/end,normalized 保证 start≤end)、抖音专属筛选落地(前 N 条 + 标签过滤 热/新/挑战/辟谣),全部"待适配/搁置"提示文字与首页通用筛选区块(分类/时效/点赞/粉丝)删除——通用筛选字段 UI 下线但配置保留(执行链未消费已验证);②我的页:来源 App 管理入口删除(并入首页),自动化设置/既有视频采集/互动三区块/本机数据统一"通用配置"命名;③抖音 Port 真机实现 `DouyinDevicePort`+服务沙盒 `ACTION_TEST_DOUYIN`(listOnly/entryIndex 双模式);6 轮真机迭代修掉 5 个真机缺陷:①Splash 常驻壳包名不可读死循环拉起(改树就绪判据)②openSearch 就绪判据误命中首页顶栏搜索钮(改搜索页特有锚点)③**搜索页节点树对无障碍摘要化**(Tab 行/历史区不可达,r4/r5 截屏实锤——全锚点改 OCR 路线)④OCR 形近错字致判据不命中(单字碎片宽松匹配)⑤**「语音搜索」浮层压住热榜 Tab 致点击无效**(进 Tab 前先 BACK 收键盘,待复验) | 303 项 JVM 全过;真机六轮日志 `.tmp/douyin-evidence/`+服务日志;UI 验收:chips 三来源 ✓、知乎/抖音专属筛选 ✓、我的页通用配置 ✓;沙盒进展:OPEN_APP✓→OPEN_SEARCH✓→OPEN_HOT_TAB 卡浮层遮挡(修复待复验,手机被企业微信占用中断);配置新字段 zhihuCardRangeStart/End、douyinTopN、douyinLabelFilter 双通道 codec |
|
||||||
|
| 2026-11-16 | **UI 二轮整合 + 抖音解析器/状态机落地**:①热点选题区按来源切换——来源 chips(通用/知乎/小红书/微博/抖音)决定显示哪个来源的专属筛选(微博=热搜类目多选+词条勾选器;知乎/抖音=待取证适配提示;小红书=搁置说明),通用筛选(分类/时效/点赞/粉丝)独立区块对全来源生效,候选列表按来源+形式过滤;②首页视觉重做——品牌紫 Hero 卡(工作台指标白字反白)替代旧工作台卡,删三步引导;③互动 tab 并入「我的」——底部三 tab(首页/任务/我的),互动三区块(新粉互动/信用分门控/评论辅助)改为 `InteractSettingsSections` 嵌入我的页;④抖音解析器+状态机:`douyin/` 包四件(DouyinModels/DouyinHotListParser/DouyinDetailParser/DouyinHotListCollector),热榜解析按 e1 取证 OCR 行口径(行首 1~2 位排名+标题+独立标签词 热/新/挑战/辟谣+行尾数值万热度),**正常榜单行必有排名:无排名行一律拒绝**(置顶/官宣/搜索历史/OCR 混入非榜单内容),标签粘连不剥离留 null;详情相对时间白名单(分钟/小时/天前)折算,作者/正文未核验留 null;SourceRegistry 门控未放行 | **303 项 JVM 全过**(284+19 抖音新:解析器 9/采集机 7/详情 3,0 失败,`.tmp/round2-build4.log`);真机验收通过:三 tab ✓、Hero 卡 ✓、热点选题来源切换(微博专属筛选出现/抖音待适配提示)✓、我的页互动三区块 ✓;无障碍绑定装机后完好;迭代修 2 真缺陷(heatValue 恒 null 忘调 parseHeat;READ_DETAIL 相位读取顺序)+2 口径收敛(无排名行拒绝;SAVE_OBSERVATION 非 Port 调用不记 calls) |
|
||||||
| 2026-11-16 | **抖音 e1 取证完成(M2 启动)**:入口链实测——首页右上搜索按钮(content-desc="搜索",[924,108][1080,240])→搜索页(SearchResultActivity,历史/猜你想看/榜单 Tab 行)→「抖音热榜」Tab(ViewGroup content-desc,**页内切换不换 Activity**,"已选中"状态可读)→热榜列表(**自绘渲染 XML 树无词条文本,OCR 主路线**,与微博同款)→词条详情(搜索结果页:热榜 TOP10 横条+综合/视频/图文/用户/直播/商品 Tab+图文/视频卡+作者相对时间+分享 ↗ 按钮)。榜单条目形态:排名徽章+标题+热/新/挑战/辟谣彩色标签+热度值(X万),滚动流畅 Tab 吸顶。样本 7 组落盘 `.tmp/douyin-evidence/`(dy-01~07)。全程只读:未点赞/关注/发布/投稿;BACK+HOME 干净退出 | dump+截图取证;详情页点按偏移一行(点到第 10 条)已记录——后续 Port 实现须按解析结果定位而非屏上估算行位 |
|
| 2026-11-16 | **抖音 e1 取证完成(M2 启动)**:入口链实测——首页右上搜索按钮(content-desc="搜索",[924,108][1080,240])→搜索页(SearchResultActivity,历史/猜你想看/榜单 Tab 行)→「抖音热榜」Tab(ViewGroup content-desc,**页内切换不换 Activity**,"已选中"状态可读)→热榜列表(**自绘渲染 XML 树无词条文本,OCR 主路线**,与微博同款)→词条详情(搜索结果页:热榜 TOP10 横条+综合/视频/图文/用户/直播/商品 Tab+图文/视频卡+作者相对时间+分享 ↗ 按钮)。榜单条目形态:排名徽章+标题+热/新/挑战/辟谣彩色标签+热度值(X万),滚动流畅 Tab 吸顶。样本 7 组落盘 `.tmp/douyin-evidence/`(dy-01~07)。全程只读:未点赞/关注/发布/投稿;BACK+HOME 干净退出 | dump+截图取证;详情页点按偏移一行(点到第 10 条)已记录——后续 Port 实现须按解析结果定位而非屏上估算行位 |
|
||||||
| 2026-11-16 | **UI 整合轮:热点 tab 下线并入首页 + 任务删除 + LazyColumn + 百度空壳下线**:①底部五 tab→四 tab(首页/任务/互动/我的),热点 tab 全部功能并入首页——`TopicSourceSection`(管理来源/来源形式筛选/微博热搜类目/词条勾选器/候选列表)+`TopicFilterSection`(18 分类/时效/点赞/粉丝门槛,改即生效无保存按钮);②`CrossPublishTaskStore.deleteTask(id)` 事务删除(quota_ledger→attempts→assets→tasks 按 FK 依赖顺序),UI 二次确认(UNKNOWN/待核对高危文案明示"放弃核对保护+额度释放"),素材文件删除前核对两份保护清单;③任务页全量组合改 LazyColumn(修数据量大卡顿)+每卡删除按钮;④百度采集确认空壳(BAIDU_FEED 零引用无解析器/Port)下线:采集模式下拉/采集页入口/BaiduConfigScreen/BAIDU 路由全删,AppConfig.baidu 数据字段保留不迁移;⑤任务页"发布设置"入口删除、我的页选题筛选入口删除、自动化设置页死链接删除 | **284 项 JVM 全量重跑全过**(0 失败,`.tmp/ui-consolidate-test.log`);assembleDebug+assembleDebugAndroidTest 通过(`.tmp/ui-consolidate-build.log`);真机验收通过:四 tab 布局 ✓、首页无百度下拉 ✓、任务页 LazyColumn+删除按钮 ✓、删除全链实测(待处理 1057→1056,二次确认弹窗文案正确,vivo「继续安装」弹窗按记忆处置);无障碍绑定装机后完好;仪器测试(deleteTask 2 用例)待下轮随批执行 |
|
| 2026-11-16 | **UI 整合轮:热点 tab 下线并入首页 + 任务删除 + LazyColumn + 百度空壳下线**:①底部五 tab→四 tab(首页/任务/互动/我的),热点 tab 全部功能并入首页——`TopicSourceSection`(管理来源/来源形式筛选/微博热搜类目/词条勾选器/候选列表)+`TopicFilterSection`(18 分类/时效/点赞/粉丝门槛,改即生效无保存按钮);②`CrossPublishTaskStore.deleteTask(id)` 事务删除(quota_ledger→attempts→assets→tasks 按 FK 依赖顺序),UI 二次确认(UNKNOWN/待核对高危文案明示"放弃核对保护+额度释放"),素材文件删除前核对两份保护清单;③任务页全量组合改 LazyColumn(修数据量大卡顿)+每卡删除按钮;④百度采集确认空壳(BAIDU_FEED 零引用无解析器/Port)下线:采集模式下拉/采集页入口/BaiduConfigScreen/BAIDU 路由全删,AppConfig.baidu 数据字段保留不迁移;⑤任务页"发布设置"入口删除、我的页选题筛选入口删除、自动化设置页死链接删除 | **284 项 JVM 全量重跑全过**(0 失败,`.tmp/ui-consolidate-test.log`);assembleDebug+assembleDebugAndroidTest 通过(`.tmp/ui-consolidate-build.log`);真机验收通过:四 tab 布局 ✓、首页无百度下拉 ✓、任务页 LazyColumn+删除按钮 ✓、删除全链实测(待处理 1057→1056,二次确认弹窗文案正确,vivo「继续安装」弹窗按记忆处置);无障碍绑定装机后完好;仪器测试(deleteTask 2 用例)待下轮随批执行 |
|
||||||
| 2026-11-16 | **M6 混合长跑验收通过(M6 最终硬门槛达标)**:`loopHours=4` 长跑 09:26~13:27 实跑——**1053 轮循环、19 单草稿确认(0 失败/0 UNKNOWN/0 PAUSED 残留)**、处理进度 3→21/28(+18 单)、跨 12:00 时段边界正常(时段 1→2 计数切换无异常)、休息期/额度门全程无突破、门控信用分实时读 1000+ 次全过;期间抓出并修复休息期快照续命 bug(相对量跨重启重新计时);全程唯一 Warning 为早期信用分 OCR 瞬时失败 2 次(预算内重试成功,无影响) | 284 项 JVM 全过;回执确认 19 单逐条核对(`收到明确的保存草稿成功提示`);验收依据:日志 `haorui-20261116-092543.log`(1053 轮完整记录)+ 处理进度 21/28 递增实锤;**M6 验收条件全达成**:混合连续运行 4 小时 ✓、休息/额度门 ✓、点击前落库 ✓(每单 attempt 落库)、同次尝试仅点击一次 ✓、未知结果保护 ✓(0 触发=0 需求)、跨时段 ✓;**混合正式发布可按低额度起步开放**(待用户决策) |
|
| 2026-11-16 | **M6 混合长跑验收通过(M6 最终硬门槛达标)**:`loopHours=4` 长跑 09:26~13:27 实跑——**1053 轮循环、19 单草稿确认(0 失败/0 UNKNOWN/0 PAUSED 残留)**、处理进度 3→21/28(+18 单)、跨 12:00 时段边界正常(时段 1→2 计数切换无异常)、休息期/额度门全程无突破、门控信用分实时读 1000+ 次全过;期间抓出并修复休息期快照续命 bug(相对量跨重启重新计时);全程唯一 Warning 为早期信用分 OCR 瞬时失败 2 次(预算内重试成功,无影响) | 284 项 JVM 全过;回执确认 19 单逐条核对(`收到明确的保存草稿成功提示`);验收依据:日志 `haorui-20261116-092543.log`(1053 轮完整记录)+ 处理进度 21/28 递增实锤;**M6 验收条件全达成**:混合连续运行 4 小时 ✓、休息/额度门 ✓、点击前落库 ✓(每单 attempt 落库)、同次尝试仅点击一次 ✓、未知结果保护 ✓(0 触发=0 需求)、跨时段 ✓;**混合正式发布可按低额度起步开放**(待用户决策) |
|
||||||
|
|||||||
Reference in New Issue
Block a user