Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
Expand All @@ -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))
}

Expand Down