修复哔哩哔哩评论定位并完成纯文字回复真机闭环
识别并跳过精选评论区,修复原评论线程重开和顶层回执的界面稳定性。记录纯文字同次实发回执和双图顶层评论验收结果。
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId = "com.jieliu.app"
|
applicationId = "com.jieliu.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 32
|
versionCode = 41
|
||||||
versionName = "0.1.31"
|
versionName = "0.1.40"
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ internal class BilibiliAdapter(
|
|||||||
private val ui: AccessibleUi,
|
private val ui: AccessibleUi,
|
||||||
photos: PhotoLibrary,
|
photos: PhotoLibrary,
|
||||||
private val scope: BilibiliCommentScope,
|
private val scope: BilibiliCommentScope,
|
||||||
diagnostic: (String) -> Unit,
|
private val diagnostic: (String) -> Unit,
|
||||||
) : PlatformAdapter {
|
) : PlatformAdapter {
|
||||||
private val navigation = BilibiliVideoNavigation(spec, ui)
|
private val navigation = BilibiliVideoNavigation(spec, ui)
|
||||||
private val comments = BilibiliComments(ui, navigation)
|
private val comments = BilibiliComments(ui, navigation)
|
||||||
@@ -32,19 +32,36 @@ internal class BilibiliAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun openComments(expected: VideoContext): List<String> =
|
override fun openComments(expected: VideoContext): List<String> =
|
||||||
comments.open(expected).map(CommentTarget::text).also { openVideo = expected }
|
eligibleComments(openCommentSurface(expected)).map(CommentTarget::text)
|
||||||
|
|
||||||
override fun scanComments(): List<CommentTarget> {
|
override fun openCommentsForReceipt(expected: VideoContext) {
|
||||||
comments.leaveThread()
|
openCommentSurface(expected)
|
||||||
return comments.scan()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scrollComments(): Boolean = comments.scroll()
|
private fun openCommentSurface(expected: VideoContext): List<CommentTarget> =
|
||||||
|
comments.open(expected).also { openVideo = expected }
|
||||||
|
|
||||||
override fun prepareReply(target: CommentTarget, expectedText: String, requiresImages: Boolean): Boolean = when (scope) {
|
private fun eligibleComments(targets: List<CommentTarget>): List<CommentTarget> {
|
||||||
|
if (!comments.requiresCuration()) return targets
|
||||||
|
diagnostic("哔哩哔哩评论需经 UP 主精选后才公开,已跳过该视频的自动评论")
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun scanComments(): List<CommentTarget> {
|
||||||
|
if (comments.requiresCuration()) return emptyList()
|
||||||
|
comments.leaveThread()
|
||||||
|
return eligibleComments(comments.scan())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun scrollComments(): Boolean = !comments.requiresCuration() && comments.scroll()
|
||||||
|
|
||||||
|
override fun prepareReply(target: CommentTarget, expectedText: String, requiresImages: Boolean): Boolean {
|
||||||
|
if (comments.requiresCuration()) return false
|
||||||
|
return when (scope) {
|
||||||
BilibiliCommentScope.REPLY_TO_ORIGINAL -> replies.prepare(target, expectedText, requiresImages)
|
BilibiliCommentScope.REPLY_TO_ORIGINAL -> replies.prepare(target, expectedText, requiresImages)
|
||||||
BilibiliCommentScope.VIDEO_COMMENT -> replies.prepareTopLevel(checkNotNull(openVideo), target, expectedText, requiresImages)
|
BilibiliCommentScope.VIDEO_COMMENT -> replies.prepareTopLevel(checkNotNull(openVideo), target, expectedText, requiresImages)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun hasPreparedReplyBaseline(targetKey: String, text: String): Boolean =
|
override fun hasPreparedReplyBaseline(targetKey: String, text: String): Boolean =
|
||||||
replies.hasPreparedBaseline(targetKey, text)
|
replies.hasPreparedBaseline(targetKey, text)
|
||||||
|
|||||||
@@ -25,8 +25,28 @@ internal class BilibiliComments(
|
|||||||
internal data class ThreadRows(val original: Row, val replies: List<Row>, val complete: Boolean)
|
internal data class ThreadRows(val original: Row, val replies: List<Row>, val complete: Boolean)
|
||||||
internal data class TopLevelMatches(val rows: List<Row>, val occurrences: Int)
|
internal data class TopLevelMatches(val rows: List<Row>, val occurrences: Int)
|
||||||
|
|
||||||
private data class MainScope(val video: VideoContext, val window: Int, val list: UiNodeSource) : Closeable {
|
private class MainScope(
|
||||||
override fun close() = list.close()
|
val video: VideoContext,
|
||||||
|
val window: Int,
|
||||||
|
list: UiNodeSource,
|
||||||
|
val tab: UiNodeSource,
|
||||||
|
val container: UiNodeSource?,
|
||||||
|
) : Closeable {
|
||||||
|
var list = list
|
||||||
|
private set
|
||||||
|
var requiresCuration = false
|
||||||
|
|
||||||
|
fun rebindList(node: UiNode) {
|
||||||
|
val source = node.retainSource()
|
||||||
|
list.close()
|
||||||
|
list = source
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
list.close()
|
||||||
|
tab.close()
|
||||||
|
container?.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class ThreadScope(val target: CommentTarget, val window: Int, val list: UiNodeSource) : Closeable {
|
private data class ThreadScope(val target: CommentTarget, val window: Int, val list: UiNodeSource) : Closeable {
|
||||||
@@ -53,6 +73,8 @@ internal class BilibiliComments(
|
|||||||
|
|
||||||
fun isOpenFor(video: VideoContext): Boolean = main?.video == video
|
fun isOpenFor(video: VideoContext): Boolean = main?.video == video
|
||||||
|
|
||||||
|
fun requiresCuration(): Boolean = main?.requiresCuration == true
|
||||||
|
|
||||||
fun open(video: VideoContext): List<CommentTarget> {
|
fun open(video: VideoContext): List<CommentTarget> {
|
||||||
check(main == null) { "请先退出上一个哔哩哔哩评论区" }
|
check(main == null) { "请先退出上一个哔哩哔哩评论区" }
|
||||||
ui.pace()
|
ui.pace()
|
||||||
@@ -79,8 +101,9 @@ internal class BilibiliComments(
|
|||||||
if (page.windowId != proof.window || page.hasEditor()) return@inspect null
|
if (page.windowId != proof.window || page.hasEditor()) return@inspect null
|
||||||
val tab = page.videoTabs()?.second ?: return@inspect null
|
val tab = page.videoTabs()?.second ?: return@inspect null
|
||||||
if (!tab.hasSource(proof.tab)) return@inspect null
|
if (!tab.hasSource(proof.tab)) return@inspect null
|
||||||
page.commentList()?.takeIf { page.detailHeader() == null }
|
val list = page.commentList()?.takeIf { page.detailHeader() == null } ?: return@inspect null
|
||||||
?.let { MainScope(video, page.windowId, it.retainSource()) }
|
MainScope(video, page.windowId, list.retainSource(), tab.retainSource(),
|
||||||
|
page.topLevelContainer(list)?.retainSource())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +115,9 @@ internal class BilibiliComments(
|
|||||||
ui.inspect { page ->
|
ui.inspect { page ->
|
||||||
val scope = main ?: return@inspect null
|
val scope = main ?: return@inspect null
|
||||||
val list = mainList(page, scope) ?: return@inspect null
|
val list = mainList(page, scope) ?: return@inspect null
|
||||||
|
if (!scope.requiresCuration && BilibiliComposeComments.requiresCuration(page, list)) {
|
||||||
|
scope.requiresCuration = true
|
||||||
|
}
|
||||||
page.rows(list, scope.video.key).filterNot(Row::own).map(Row::target)
|
page.rows(list, scope.video.key).filterNot(Row::own).map(Row::target)
|
||||||
}
|
}
|
||||||
} ?: throw PlatformException("哔哩哔哩评论区已变化")
|
} ?: throw PlatformException("哔哩哔哩评论区已变化")
|
||||||
@@ -101,18 +127,26 @@ internal class BilibiliComments(
|
|||||||
ui.pace()
|
ui.pace()
|
||||||
val previous = ui.inspect { page ->
|
val previous = ui.inspect { page ->
|
||||||
val list = mainList(page, scope) ?: return@inspect null
|
val list = mainList(page, scope) ?: return@inspect null
|
||||||
val positions = page.rows(list, scope.video.key).associate { it.target.key to it.container.bounds.top }
|
val positions = page.commentViewport(list)
|
||||||
positions.takeIf { list.scrollable && ui.scrollUpInside(list.bounds) }
|
positions.takeIf { it.isNotEmpty() && list.scrollable && ui.scrollUpInside(list.bounds) }
|
||||||
} ?: return false
|
} ?: return false
|
||||||
return ui.await(2_500) {
|
return ui.await(2_500) {
|
||||||
ui.inspect { page ->
|
ui.inspect { page ->
|
||||||
val list = mainList(page, scope) ?: return@inspect null
|
val list = mainList(page, scope) ?: return@inspect null
|
||||||
val positions = page.rows(list, scope.video.key).associate { it.target.key to it.container.bounds.top }
|
val positions = page.commentViewport(list)
|
||||||
true.takeIf { positions.isNotEmpty() && positions != previous }
|
true.takeIf { positions.isNotEmpty() && positions != previous }
|
||||||
}
|
}
|
||||||
} == true
|
} == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun UiPage.commentViewport(list: UiNode): List<Pair<Rect, List<String>>> {
|
||||||
|
// A viewport can contain only clipped comments while the list is still moving.
|
||||||
|
val children = nodes.groupBy(UiNode::directParent)
|
||||||
|
return children[list].orEmpty().map { item ->
|
||||||
|
Rect(item.bounds) to children[item].orEmpty().flatMap(UiNode::labels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun openTopLevel(video: VideoContext): Boolean {
|
fun openTopLevel(video: VideoContext): Boolean {
|
||||||
val scope = main?.takeIf { it.video == video && thread == null } ?: return false
|
val scope = main?.takeIf { it.video == video && thread == null } ?: return false
|
||||||
ui.pace()
|
ui.pace()
|
||||||
@@ -142,6 +176,16 @@ internal class BilibiliComments(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun settleTopLevelAfterSubmit(video: VideoContext): Boolean {
|
||||||
|
val scope = main?.takeIf { it.video == video && thread == null } ?: return false
|
||||||
|
val settled = ui.inspect { page ->
|
||||||
|
val list = anchoredMainList(page, scope) ?: return@inspect false
|
||||||
|
if (!list.hasSource(scope.list)) scope.rebindList(list)
|
||||||
|
true
|
||||||
|
} == true
|
||||||
|
return settled && prepareLatestTopLevel(video)
|
||||||
|
}
|
||||||
|
|
||||||
private fun switchTopLevelOrder(scope: MainScope): Boolean {
|
private fun switchTopLevelOrder(scope: MainScope): Boolean {
|
||||||
ui.pace()
|
ui.pace()
|
||||||
val transition = ui.inspect { page ->
|
val transition = ui.inspect { page ->
|
||||||
@@ -173,17 +217,15 @@ internal class BilibiliComments(
|
|||||||
if (!container.hasSource(proof.container) || BilibiliComposeComments.order(page, list)?.latest != true) {
|
if (!container.hasSource(proof.container) || BilibiliComposeComments.order(page, list)?.latest != true) {
|
||||||
return@inspect null
|
return@inspect null
|
||||||
}
|
}
|
||||||
if (list.hasSource(scope.list)) scope else if (proof.changed) {
|
if (!list.hasSource(scope.list)) {
|
||||||
MainScope(scope.video, scope.window, list.retainSource())
|
if (!proof.changed) return@inspect null
|
||||||
} else null
|
scope.rebindList(list)
|
||||||
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: return false
|
|
||||||
if (current !== scope) {
|
|
||||||
main = current
|
|
||||||
scope.close()
|
|
||||||
}
|
}
|
||||||
return true
|
return current == true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> readTopLevel(
|
fun <T> readTopLevel(
|
||||||
@@ -250,7 +292,10 @@ internal class BilibiliComments(
|
|||||||
val scope = main ?: return null
|
val scope = main ?: return null
|
||||||
val candidate = ui.inspect { page ->
|
val candidate = ui.inspect { page ->
|
||||||
val list = mainList(page, scope) ?: return@inspect null
|
val list = mainList(page, scope) ?: return@inspect null
|
||||||
page.rows(list, scope.video.key).singleOrNull { it.target.key == key && it.target.author == author }?.target
|
page.rows(list, scope.video.key)
|
||||||
|
.singleOrNull { it.target.key == key && it.target.author == author }
|
||||||
|
?.takeIf { it.threadEntry != null }
|
||||||
|
?.target
|
||||||
}
|
}
|
||||||
if (candidate != null) return candidate
|
if (candidate != null) return candidate
|
||||||
if (index == 12 || !scroll()) return null
|
if (index == 12 || !scroll()) return null
|
||||||
@@ -259,11 +304,14 @@ internal class BilibiliComments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun enterThread(target: CommentTarget): Boolean {
|
fun enterThread(target: CommentTarget): Boolean {
|
||||||
if (thread?.target == target) return readThread(target) { _, _ -> true } == true
|
val scope = main ?: return false
|
||||||
if (thread != null) return false
|
thread?.let { opened ->
|
||||||
|
if (opened.target != target) return false
|
||||||
|
if (readThread(target) { _, _ -> true } == true) return true
|
||||||
|
if (!acceptReturnedMain(scope, opened, requireOriginal = true)) return false
|
||||||
|
}
|
||||||
val opened = readOriginal(target) { _, row -> row.threadEntry?.let { ui.click(it) } == true } == true
|
val opened = readOriginal(target) { _, row -> row.threadEntry?.let { ui.click(it) } == true } == true
|
||||||
if (!opened) return false
|
if (!opened) return false
|
||||||
val scope = main ?: return false
|
|
||||||
var movedToRoot = false
|
var movedToRoot = false
|
||||||
thread = ui.await(5_000) {
|
thread = ui.await(5_000) {
|
||||||
ui.inspect { page ->
|
ui.inspect { page ->
|
||||||
@@ -285,35 +333,61 @@ internal class BilibiliComments(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun leaveThread() {
|
fun leaveThread(allowIntroduction: Boolean = false) {
|
||||||
val scope = main ?: return
|
val scope = main ?: return
|
||||||
val opened = thread ?: return
|
val opened = thread ?: return
|
||||||
|
if (acceptReturnedMain(scope, opened, requireOriginal = true)) return
|
||||||
val closed = ui.await(4_000) {
|
val closed = ui.await(4_000) {
|
||||||
ui.inspect { page ->
|
ui.inspect { page ->
|
||||||
if (page.windowId != opened.window || page.hasEditor() || page.detailList()?.hasSource(opened.list) != true) return@inspect null
|
if (page.windowId != opened.window || page.hasEditor()) return@inspect null
|
||||||
|
val list = page.detailList() ?: return@inspect null
|
||||||
|
if (!list.hasSource(opened.list) && (!allowIntroduction || !page.complete ||
|
||||||
|
page.threadRows(list, scope.video.key, opened.target) == null)
|
||||||
|
) return@inspect null
|
||||||
val close = BilibiliComposeComments.detail(page)?.close ?: page.detailHeader()?.let { header ->
|
val close = BilibiliComposeComments.detail(page)?.close ?: page.detailHeader()?.let { header ->
|
||||||
page.nodes.singleOrNull { it.resourceId in setOf("close", "back") && it.isDescendantOf(header) && it.biliClick() }
|
page.nodes.singleOrNull { it.resourceId in setOf("close", "back") && it.isDescendantOf(header) && it.biliClick() }
|
||||||
}
|
}
|
||||||
close?.let { ui.click(it) }
|
true.takeIf { close?.let { ui.click(it) } == true }
|
||||||
}
|
}
|
||||||
} == true
|
} == true
|
||||||
if (!closed || ui.await(4_000) { ui.inspect { page -> true.takeIf { mainList(page, scope) != null } } } != true) {
|
if (!closed || ui.await(4_000) {
|
||||||
|
if (acceptReturnedMain(scope, opened, requireOriginal = false)) true
|
||||||
|
else if (allowIntroduction) ui.inspect { page -> true.takeIf { page.mainIntroduction(scope) != null } }
|
||||||
|
else null
|
||||||
|
} != true) {
|
||||||
throw PlatformException("未能返回哔哩哔哩原视频评论区")
|
throw PlatformException("未能返回哔哩哔哩原视频评论区")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun acceptReturnedMain(scope: MainScope, opened: ThreadScope, requireOriginal: Boolean): Boolean {
|
||||||
|
val accepted = ui.inspect { page ->
|
||||||
|
if (thread !== opened) return@inspect false
|
||||||
|
val list = mainList(page, scope).takeUnless { requireOriginal }
|
||||||
|
?: anchoredMainList(page, scope) ?: return@inspect false
|
||||||
|
val sameList = list.hasSource(scope.list)
|
||||||
|
if ((requireOriginal || !sameList) && page.rows(list, scope.video.key).count { it.target == opened.target } != 1) {
|
||||||
|
return@inspect false
|
||||||
|
}
|
||||||
|
if (!sameList) scope.rebindList(list)
|
||||||
|
true
|
||||||
|
} == true
|
||||||
|
if (!accepted) return false
|
||||||
opened.close()
|
opened.close()
|
||||||
thread = null
|
thread = null
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
val scope = main ?: return
|
val scope = main ?: return
|
||||||
leaveThread()
|
if (thread != null && ui.inspect { it.mainIntroduction(scope) != null } != true) leaveThread(allowIntroduction = true)
|
||||||
val closed = ui.inspect { page ->
|
val closed = ui.inspect { page ->
|
||||||
if (mainList(page, scope) == null) return@inspect false
|
page.mainIntroduction(scope)?.let { ui.click(it) } == true
|
||||||
navigation.introductionEntry(page, scope.video)?.let { ui.click(it) } == true
|
|
||||||
} == true
|
} == true
|
||||||
if (!closed || ui.await(5_000) {
|
if (!closed || ui.await(5_000) {
|
||||||
ui.inspect { page -> true.takeIf { navigation.matchesVideo(page, scope.video) } }
|
ui.inspect { page -> true.takeIf { navigation.matchesVideo(page, scope.video) } }
|
||||||
} != true) throw PlatformException("未能退出哔哩哔哩评论标签")
|
} != true) throw PlatformException("未能退出哔哩哔哩评论标签")
|
||||||
|
thread?.close()
|
||||||
|
thread = null
|
||||||
scope.close()
|
scope.close()
|
||||||
main = null
|
main = null
|
||||||
}
|
}
|
||||||
@@ -331,6 +405,28 @@ internal class BilibiliComments(
|
|||||||
return page.commentList()?.takeIf { it.hasSource(scope.list) }
|
return page.commentList()?.takeIf { it.hasSource(scope.list) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun UiPage.mainIntroduction(scope: MainScope): UiNode? {
|
||||||
|
if (mainList(this, scope) == null) {
|
||||||
|
// The verified player can remain visible after the retained comment nodes have been replaced.
|
||||||
|
if (!complete || windowId != scope.window || detailHeader() != null || hasEditor() ||
|
||||||
|
videoTabs()?.second?.selected != true || commentList() == null
|
||||||
|
) return null
|
||||||
|
}
|
||||||
|
return navigation.introductionEntry(this, scope.video)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun anchoredMainList(page: UiPage, scope: MainScope): UiNode? {
|
||||||
|
if (main !== scope || !page.complete || page.windowId != scope.window || page.hasEditor() ||
|
||||||
|
page.detailHeader() != null
|
||||||
|
) return null
|
||||||
|
val tab = page.videoTabs()?.second ?: return null
|
||||||
|
if (!tab.selected || !tab.hasSource(scope.tab)) return null
|
||||||
|
val list = page.commentList() ?: return null
|
||||||
|
if (list.hasSource(scope.list)) return list
|
||||||
|
val container = scope.container ?: return null
|
||||||
|
return list.takeIf { page.topLevelContainer(it)?.hasSource(container) == true }
|
||||||
|
}
|
||||||
|
|
||||||
private fun UiPage.videoTabs(): Pair<UiNode, UiNode>? {
|
private fun UiPage.videoTabs(): Pair<UiNode, UiNode>? {
|
||||||
val info = nodes.singleOrNull { it.resourceId == "tab_title" && it.labels() == listOf("简介") &&
|
val info = nodes.singleOrNull { it.resourceId == "tab_title" && it.labels() == listOf("简介") &&
|
||||||
it.bounds.centerY() in y(.20f)..y(.70f) }
|
it.bounds.centerY() in y(.20f)..y(.70f) }
|
||||||
|
|||||||
@@ -49,6 +49,24 @@ internal object BilibiliComposeComments {
|
|||||||
|
|
||||||
fun topLevelEntry(page: UiPage, list: UiNode): UiNode? {
|
fun topLevelEntry(page: UiPage, list: UiNode): UiNode? {
|
||||||
if (list(page) !== list || detail(page) != null) return null
|
if (list(page) !== list || detail(page) != null) return null
|
||||||
|
return footerEntry(page, list, ::isTopLevelPrompt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun requiresCuration(page: UiPage, list: UiNode): Boolean {
|
||||||
|
if (list(page) !== list || detail(page) != null) return false
|
||||||
|
if (footerEntry(page, list) { it == CURATED_COMMENT_PROMPT } != null) return true
|
||||||
|
|
||||||
|
val header = page.children(list).firstOrNull()?.takeIf {
|
||||||
|
it.className == VIEW && !it.clickable && !it.scrollable && it.labels().isEmpty() &&
|
||||||
|
list.bounds.contains(it.bounds) && it.bounds.top == list.bounds.top &&
|
||||||
|
it.bounds.width() >= list.bounds.width() * .90
|
||||||
|
} ?: return false
|
||||||
|
val label = page.children(header).singleOrNull() ?: return false
|
||||||
|
return label.className == TEXT_VIEW && !label.clickable && !label.editable &&
|
||||||
|
label.labels() == listOf(CURATED_COMMENT_HEADING) && header.bounds.contains(label.bounds)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun footerEntry(page: UiPage, list: UiNode, acceptsPrompt: (String) -> Boolean): UiNode? {
|
||||||
val content = list.directParent()?.directParent()?.takeIf { it.className == VIEW } ?: return null
|
val content = list.directParent()?.directParent()?.takeIf { it.className == VIEW } ?: return null
|
||||||
val footer = page.children(content).singleOrNull {
|
val footer = page.children(content).singleOrNull {
|
||||||
it.className == VIEW && !it.clickable && !it.scrollable && content.bounds.contains(it.bounds) &&
|
it.className == VIEW && !it.clickable && !it.scrollable && content.bounds.contains(it.bounds) &&
|
||||||
@@ -70,7 +88,7 @@ internal object BilibiliComposeComments {
|
|||||||
page.children(it).filter { child -> child.text.isNotEmpty() || child.description.isNotEmpty() }
|
page.children(it).filter { child -> child.text.isNotEmpty() || child.description.isNotEmpty() }
|
||||||
.singleOrNull { marker ->
|
.singleOrNull { marker ->
|
||||||
marker.className == TEXT_VIEW && !marker.clickable && !marker.editable &&
|
marker.className == TEXT_VIEW && !marker.clickable && !marker.editable &&
|
||||||
input.bounds.contains(marker.bounds) && isTopLevelPrompt(marker.text) &&
|
input.bounds.contains(marker.bounds) && acceptsPrompt(marker.text) &&
|
||||||
(marker.description.isEmpty() || marker.description == marker.text)
|
(marker.description.isEmpty() || marker.description == marker.text)
|
||||||
} != null
|
} != null
|
||||||
}
|
}
|
||||||
@@ -92,8 +110,13 @@ internal object BilibiliComposeComments {
|
|||||||
|
|
||||||
fun order(page: UiPage, list: UiNode): Order? {
|
fun order(page: UiPage, list: UiNode): Order? {
|
||||||
if (list(page) !== list || detail(page) != null) return null
|
if (list(page) !== list || detail(page) != null) return null
|
||||||
val header = page.children(list).singleOrNull {
|
val siblings = page.children(list)
|
||||||
it.className == VIEW && !it.clickable && it.bounds.top == list.bounds.top &&
|
val poll = siblings.firstOrNull()?.takeIf { isLeadingPoll(page, list, it) }
|
||||||
|
val header = siblings.singleOrNull {
|
||||||
|
val atStart = it.bounds.top == list.bounds.top && it !== poll
|
||||||
|
val afterPoll = poll != null && it === siblings.getOrNull(1) &&
|
||||||
|
it.bounds.top >= poll.bounds.centerY() && it.bounds.top <= poll.bounds.bottom + poll.bounds.height() / 8
|
||||||
|
it.className == VIEW && !it.clickable && (atStart || afterPoll) &&
|
||||||
it.bounds.width() >= list.bounds.width() * .90 && list.bounds.contains(it.bounds)
|
it.bounds.width() >= list.bounds.width() * .90 && list.bounds.contains(it.bounds)
|
||||||
} ?: return null
|
} ?: return null
|
||||||
val heading = page.children(header).singleOrNull {
|
val heading = page.children(header).singleOrNull {
|
||||||
@@ -116,6 +139,19 @@ internal object BilibiliComposeComments {
|
|||||||
return Order(control, latest).takeIf { confirms }
|
return Order(control, latest).takeIf { confirms }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isLeadingPoll(page: UiPage, list: UiNode, node: UiNode): Boolean {
|
||||||
|
if (node.className != VIEW || node.clickable || node.bounds.top != list.bounds.top ||
|
||||||
|
node.bounds.width() < list.bounds.width() * .90 || !list.bounds.contains(node.bounds)
|
||||||
|
) return false
|
||||||
|
val children = page.children(node)
|
||||||
|
if (children.count { it.className == TEXT_VIEW && !it.clickable && POLL_PARTICIPANTS.matches(it.text) &&
|
||||||
|
node.bounds.contains(it.bounds) } != 1
|
||||||
|
) return false
|
||||||
|
val choices = children.filter { it.className == VIEW && it.biliClick() && node.bounds.contains(it.bounds) }
|
||||||
|
return choices.size == 2 && sameLine(choices[0].bounds, choices[1].bounds) &&
|
||||||
|
!Rect.intersects(choices[0].bounds, choices[1].bounds)
|
||||||
|
}
|
||||||
|
|
||||||
fun rows(
|
fun rows(
|
||||||
page: UiPage,
|
page: UiPage,
|
||||||
list: UiNode,
|
list: UiNode,
|
||||||
@@ -195,9 +231,13 @@ internal object BilibiliComposeComments {
|
|||||||
it.className == BUTTON && it.biliClick() && row.bounds.contains(it.bounds) &&
|
it.className == BUTTON && it.biliClick() && row.bounds.contains(it.bounds) &&
|
||||||
it.text.isNotBlank() && it.text == it.description
|
it.text.isNotBlank() && it.text == it.description
|
||||||
} ?: return null
|
} ?: return null
|
||||||
|
// A short author name has a square touch target that extends past the rendered label.
|
||||||
|
val bodyTop = if (author.bounds.width() == author.bounds.height()) {
|
||||||
|
author.bounds.bottom - author.bounds.height() / 4
|
||||||
|
} else author.bounds.bottom
|
||||||
val body = children.singleOrNull {
|
val body = children.singleOrNull {
|
||||||
it.className == VIEW && !it.clickable && !it.editable && it.text.isEmpty() && it.description.isNotBlank() &&
|
it.className == VIEW && !it.clickable && !it.editable && it.text.isEmpty() && it.description.isNotBlank() &&
|
||||||
it.bounds.top >= author.bounds.bottom && it.bounds.left <= author.bounds.centerX() &&
|
it.bounds.top >= bodyTop && it.bounds.left <= author.bounds.centerX() &&
|
||||||
it.bounds.width() >= row.bounds.width() * .50 && row.bounds.contains(it.bounds)
|
it.bounds.width() >= row.bounds.width() * .50 && row.bounds.contains(it.bounds)
|
||||||
} ?: return null
|
} ?: return null
|
||||||
return Identity(author, body)
|
return Identity(author, body)
|
||||||
@@ -301,13 +341,28 @@ internal object BilibiliComposeComments {
|
|||||||
private const val TEXT_VIEW = "android.widget.TextView"
|
private const val TEXT_VIEW = "android.widget.TextView"
|
||||||
private const val BUTTON = "android.widget.Button"
|
private const val BUTTON = "android.widget.Button"
|
||||||
private const val MAX_PHOTOS = 9
|
private const val MAX_PHOTOS = 9
|
||||||
|
private const val CURATED_COMMENT_PROMPT = "评论被up主精选后,对所有人可见"
|
||||||
|
private const val CURATED_COMMENT_HEADING = "精选评论"
|
||||||
private val CLOSE_LABELS = setOf("关闭", "返回", "关闭评论详情")
|
private val CLOSE_LABELS = setOf("关闭", "返回", "关闭评论详情")
|
||||||
private val MORE_LABELS = setOf("更多", "更多操作", "更多操作,按钮")
|
private val MORE_LABELS = setOf("更多", "更多操作", "更多操作,按钮")
|
||||||
private val REPLY_LABELS = setOf("回复", "回复,按钮")
|
private val REPLY_LABELS = setOf("回复", "回复,按钮")
|
||||||
private val OWN_LABELS = setOf("我", "我发布的评论", "我发布的回复")
|
private val OWN_LABELS = setOf("我", "我发布的评论", "我发布的回复")
|
||||||
private val TOP_LEVEL_PROMPTS = setOf("天青色等烟雨,评论区在等你", "不发没关系,请继续友善哦~", "这里是评论区,不是无人区;-)")
|
private val TOP_LEVEL_PROMPTS = setOf(
|
||||||
|
"天青色等烟雨,评论区在等你",
|
||||||
|
"不发没关系,请继续友善哦~",
|
||||||
|
"这里是评论区,不是无人区;-)",
|
||||||
|
"宫廷玉液酒,评论走一走",
|
||||||
|
"万水千山总是情,评论两句行不行",
|
||||||
|
"轻轻敲醒沉睡的心灵,让我看看你的点评",
|
||||||
|
"你渴望拥有力量吗?评论让力量更强大",
|
||||||
|
"新的风暴已经出现,你的妙评何时再现",
|
||||||
|
"下面我简单喵两句",
|
||||||
|
"勇敢滴少年啊快去创造热评~",
|
||||||
|
"与其赞同别人的话语,不如自己畅所欲言。",
|
||||||
|
)
|
||||||
private val ORDER_HEADINGS = setOf("热门评论", "最新评论")
|
private val ORDER_HEADINGS = setOf("热门评论", "最新评论")
|
||||||
private val ORDER_NAMES = setOf("按热度", "按时间")
|
private val ORDER_NAMES = setOf("按热度", "按时间")
|
||||||
|
private val POLL_PARTICIPANTS = Regex("[0-9]+(?:\\.[0-9]+)?万?人参与")
|
||||||
private val THREAD_TOTAL = Regex("相关回复共\\s*(\\d+)\\s*条")
|
private val THREAD_TOTAL = Regex("相关回复共\\s*(\\d+)\\s*条")
|
||||||
private val FOOTER_TIME = Regex(
|
private val FOOTER_TIME = Regex(
|
||||||
"^(?:刚刚|昨天|前天|\\d+\\s*(?:秒|分钟|小时|天|周|月|年)前|" +
|
"^(?:刚刚|昨天|前天|\\d+\\s*(?:秒|分钟|小时|天|周|月|年)前|" +
|
||||||
|
|||||||
@@ -73,7 +73,10 @@ internal class BilibiliReplies(
|
|||||||
val previous = comments.readTopLevel(video, text) { page, matches ->
|
val previous = comments.readTopLevel(video, text) { page, matches ->
|
||||||
page.windowId.takeIf { page.complete && matches.occurrences == 0 }
|
page.windowId.takeIf { page.complete && matches.occurrences == 0 }
|
||||||
} ?: return false
|
} ?: return false
|
||||||
if (!comments.openTopLevel(video)) return false
|
if (!comments.openTopLevel(video)) {
|
||||||
|
diagnostic("哔哩哔哩未能核对原视频评论框入口")
|
||||||
|
return false
|
||||||
|
}
|
||||||
prepareEditor(target, text, previous, topLevel = true, requiresImages = requiresImages)
|
prepareEditor(target, text, previous, topLevel = true, requiresImages = requiresImages)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -212,7 +215,7 @@ internal class BilibiliReplies(
|
|||||||
|
|
||||||
fun confirmTopLevel(video: VideoContext, text: String, attachments: List<TemplatePhoto>, armedAt: Long): CommentPublishResult {
|
fun confirmTopLevel(video: VideoContext, text: String, attachments: List<TemplatePhoto>, armedAt: Long): CommentPublishResult {
|
||||||
val references = photos.readReceiptPixels(attachments) ?: return CommentPublishResult.UNCERTAIN
|
val references = photos.readReceiptPixels(attachments) ?: return CommentPublishResult.UNCERTAIN
|
||||||
if (ui.await(4_000) { true.takeIf { comments.prepareLatestTopLevel(video) } } != true) {
|
if (ui.await(5_000) { true.takeIf { comments.settleTopLevelAfterSubmit(video) } } != true) {
|
||||||
return CommentPublishResult.UNCERTAIN
|
return CommentPublishResult.UNCERTAIN
|
||||||
}
|
}
|
||||||
fun readMatches(): Pair<Int, ReceiptRow?>? = comments.readTopLevel(video, text) { page, matches ->
|
fun readMatches(): Pair<Int, ReceiptRow?>? = comments.readTopLevel(video, text) { page, matches ->
|
||||||
@@ -226,11 +229,12 @@ internal class BilibiliReplies(
|
|||||||
if (candidate != null || !comments.scrollTopLevel(video)) break
|
if (candidate != null || !comments.scrollTopLevel(video)) break
|
||||||
candidate = ui.await(2_000, ::observed)
|
candidate = ui.await(2_000, ::observed)
|
||||||
}
|
}
|
||||||
val receipt = candidate?.second ?: return CommentPublishResult.UNCERTAIN
|
val located = candidate?.second ?: return CommentPublishResult.UNCERTAIN
|
||||||
diagnostic("哔哩哔哩已在原视频最新评论找到唯一匹配的正文和图片区域")
|
diagnostic("哔哩哔哩已在原视频最新评论找到唯一匹配的正文和图片区域")
|
||||||
if (!verifyImages(receipt.images, references) { readReceipt()?.takeIf { it == receipt }?.images }) {
|
val receipt = ui.await(3_500) {
|
||||||
return CommentPublishResult.UNCERTAIN
|
val current = readReceipt()?.takeIf { it.key == located.key && it.own == located.own } ?: return@await null
|
||||||
}
|
current.takeIf { verifyImages(current.images, references) { readReceipt()?.takeIf { it == current }?.images } }
|
||||||
|
} ?: return CommentPublishResult.UNCERTAIN
|
||||||
if (!receipt.own) {
|
if (!receipt.own) {
|
||||||
val opened = comments.readTopLevel(video, text) { page, matches ->
|
val opened = comments.readTopLevel(video, text) { page, matches ->
|
||||||
val row = matches.rows.singleOrNull()?.takeIf { matches.occurrences == 1 } ?: return@readTopLevel false
|
val row = matches.rows.singleOrNull()?.takeIf { matches.occurrences == 1 } ?: return@readTopLevel false
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ class BilibiliLabelsTest {
|
|||||||
assertNull(BilibiliLabels.replyCount("展开更多评论"))
|
assertNull(BilibiliLabels.replyCount("展开更多评论"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun recognizesRotatingTopLevelPlaceholdersAndRejectsOtherEditors() {
|
||||||
|
assertTrue(BilibiliComposeComments.isTopLevelPrompt("万水千山总是情,评论两句行不行"))
|
||||||
|
assertTrue(BilibiliComposeComments.isTopLevelPrompt("轻轻敲醒沉睡的心灵,让我看看你的点评"))
|
||||||
|
assertFalse(BilibiliComposeComments.isTopLevelPrompt("评论被up主精选后,对所有人可见"))
|
||||||
|
assertFalse(BilibiliComposeComments.isTopLevelPrompt("回复 @小明:"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun relativeAgeMustAgreeWithTheArmedSubmission() {
|
@Test fun relativeAgeMustAgreeWithTheArmedSubmission() {
|
||||||
val armed = 1_000_000L
|
val armed = 1_000_000L
|
||||||
assertTrue(BilibiliLabels.matchesSubmissionTime("刚刚 广东", armed, armed + 4_000))
|
assertTrue(BilibiliLabels.matchesSubmissionTime("刚刚 广东", armed, armed + 4_000))
|
||||||
|
|||||||
+9
-1
@@ -1,6 +1,14 @@
|
|||||||
# 拾见开发进度
|
# 拾见开发进度
|
||||||
|
|
||||||
最近更新于 2026-11-27 11:56(UTC+8)。以下按开发轮次倒序记录。
|
最近更新于 2026-11-27 14:35(UTC+8)。以下按开发轮次倒序记录。
|
||||||
|
|
||||||
|
## 2026-11-27 · 拾见 0.1.40 哔哩哔哩同次任务验收
|
||||||
|
|
||||||
|
- 0.1.40 在发布前识别评论区的「精选评论」标题和输入框提示。识别后跳过该视频的自动评论。修复评论详情关闭时原生列表节点更换后的定位,并在原视频核验通过后恢复回执查找。双图顶层评论可等待最新评论界面稳定,再检查同一条评论的两张图片。
|
||||||
|
- 0.1.39 在开启精选评论的视频上未能读到提交后的回复正文,原提交记录仍待核对。0.1.40 在 vivo Android 12、哔哩哔哩 9.21.0 上验证普通评论区可以搜索、匹配并重开同一条原评论,精选评论区识别后直接跳过。
|
||||||
|
- 14:33:35 从「开始任务」启动 0.1.40 纯文字轮。自动搜索普通视频,14:34:05 在第 8 屏命中此前未提交过的原评论,提交一条纯文字回复。14:34:34 在同一次任务内核对原评论线程中唯一匹配的正文、发送时间、本人身份和零附件,写入一条 `SENT` 并完成任务。验收限制为一个视频、一条回复,全程由程序操作。手机保留本次回执,已恢复临时调整的配置和无障碍设置,旧待核对记录独立归档。
|
||||||
|
- 双图顶层评论已在 0.1.33 完成同次任务验收。12:53:34 从「开始任务」启动,自动搜索、匹配并发布一条顶层评论。12:54:35 在原视频最新评论核对同一条本人评论的正文、两张绑定图片的内容与顺序,并写入一条 `SENT`。
|
||||||
|
- 0.1.40 通过离线构建、74 项 JVM 单测、8 份精选评论真机快照回归和 10 项纯文字回执回放。Lint 为 0 个错误、3 个警告。调试 APK 通过 v2 签名校验,真机安装包与本地构建文件的 SHA-256 一致。
|
||||||
|
|
||||||
## 2026-11-27 · 哔哩哔哩两种发布方式真机验收
|
## 2026-11-27 · 哔哩哔哩两种发布方式真机验收
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user