diff --git a/src/main/kotlin/dev/typetype/server/services/ExtractionErrorSanitizer.kt b/src/main/kotlin/dev/typetype/server/services/ExtractionErrorSanitizer.kt index a4fb60a..aabbb07 100644 --- a/src/main/kotlin/dev/typetype/server/services/ExtractionErrorSanitizer.kt +++ b/src/main/kotlin/dev/typetype/server/services/ExtractionErrorSanitizer.kt @@ -2,22 +2,31 @@ package dev.typetype.server.services object ExtractionErrorSanitizer { private const val MEMBERS_ONLY = "This video is only available for members" + private const val SIGN_IN_REQUIRED = "Sign in is required to verify access to this video" fun sanitize(raw: String?): String? { if (raw.isNullOrBlank()) return null val compact = raw.replace('\n', ' ').replace('\r', ' ').trim() if (compact.isBlank()) return null if (isMembersOnlyPrompt(compact)) return MEMBERS_ONLY + if (isSignInVerificationPrompt(compact)) return SIGN_IN_REQUIRED return compact } private fun isMembersOnlyPrompt(message: String): Boolean { val lowered = message.lowercase() if ("members" in lowered && "only available" in lowered) return true + if ("join this channel" in lowered && "members-only" in lowered) return true + return false + } + + private fun isSignInVerificationPrompt(message: String): Boolean { + val lowered = message.lowercase() if ("sign in to confirm" in lowered) return true if ("not a bot" in lowered) return true if ("qinisekisa ukuthi" in lowered) return true if ("awuyona i-bot" in lowered) return true + if ("ngena ngemvume" in lowered) return true return false } } diff --git a/src/test/kotlin/dev/typetype/server/ExtractionErrorSanitizerTest.kt b/src/test/kotlin/dev/typetype/server/ExtractionErrorSanitizerTest.kt index aaa3d20..8a53f4f 100644 --- a/src/test/kotlin/dev/typetype/server/ExtractionErrorSanitizerTest.kt +++ b/src/test/kotlin/dev/typetype/server/ExtractionErrorSanitizerTest.kt @@ -6,10 +6,10 @@ import org.junit.jupiter.api.Test class ExtractionErrorSanitizerTest { @Test - fun `normalizes bot prompt with mixed locales`() { + fun `normalizes bot prompt with mixed locales to sign-in verification message`() { val raw = "Ngena ngemvume ukuze uqinisekise ukuthi awuyona i-bot" assertEquals( - "This video is only available for members", + "Sign in is required to verify access to this video", ExtractionErrorSanitizer.sanitize(raw), ) } @@ -21,8 +21,14 @@ class ExtractionErrorSanitizerTest { } @Test - fun `normalizes login confirm prompt to members only message`() { + fun `normalizes login confirm prompt to sign-in verification message`() { val raw = "Sign in to confirm you are not a bot" + assertEquals("Sign in is required to verify access to this video", ExtractionErrorSanitizer.sanitize(raw)) + } + + @Test + fun `keeps members-only paywall prompt as members message`() { + val raw = "Join this channel to get access to members-only content like this video" assertEquals("This video is only available for members", ExtractionErrorSanitizer.sanitize(raw)) }