Extend Video Deleted parsing

This commit is contained in:
Gergely Hegedus 2025-09-04 13:46:18 +03:00
parent 158c322cda
commit 45fb0d4d71
4 changed files with 52 additions and 5 deletions

View file

@ -38,6 +38,6 @@ Example getting the stack trace for a specific error message:
`jq -r '.[].errors[] | select(.message == "Parsing Error") | .stacktrace' errors.json`
Or getting all htmls if an error happened in the json:
`jq '.[] | select(.errors[]?.message == "Parsing Error") | .errors[].html'`
`jq '.[] | select(.errors[]?.message == "Parsing Error") | .errors[].html' errors.json`
> Use -r when you want to avoid the JSON string quotes around output.

View file

@ -4,12 +4,18 @@ import org.fnives.tiktokdownloader.data.network.exceptions.VideoDeletedException
class ThrowIfVideoIsDeletedResponse {
private val potentialIssues = listOf(
"\"statusMsg\":\"status_deleted",
"\"statusMsg\":\"item doesn't exist",
"statusMsg\":\"[^\"]*status_audit_not_pass"
)
@Throws(VideoDeletedException::class)
fun invoke(html: String) {
if (html.contains("\"statusMsg\":\"status_deleted")) {
throw VideoDeletedException(html = html)
} else if (html.contains("\"statusMsg\":\"item doesn't exist")) {
potentialIssues.forEach {
if (html.contains(it.toRegex())) {
throw VideoDeletedException(html = html)
}
}
}
}

View file

@ -8,6 +8,7 @@ import org.fnives.tiktokdownloader.data.model.VideoInSavingIntoFile
import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredException
import org.fnives.tiktokdownloader.data.network.exceptions.NetworkException
import org.fnives.tiktokdownloader.data.network.exceptions.ParsingException
import org.fnives.tiktokdownloader.data.network.exceptions.VideoDeletedException
import org.fnives.tiktokdownloader.di.module.NetworkModule
import org.fnives.tiktokdownloader.helper.readResourceFile
import org.junit.jupiter.api.AfterEach
@ -260,8 +261,21 @@ class TikTokDownloadRemoteSourceTest {
}
}
@Test
fun GIVEN_deleted_video_response_v1_THEN_proper_Exception_is_Returned() {
Assertions.assertThrows(VideoDeletedException::class.java) {
runBlocking<Unit> {
val deletedResponse = readResourceFileDeletedV1UrlResponse()
mockWebServer.enqueue(MockResponse().setResponseCode(200).setBody(deletedResponse))
sut.getVideo(VideoInPending("", TEST_URL))
}
}
}
companion object {
private const val SHORTENED_URL_RESPONSE = "response/shortened_url_response.html"
private const val DELETED_V1_URL_RESPONSE = "response/video_deleted_v1.html"
private const val CAPTCHA_REQUIRED_RESPONSE_ONE = "response/captcha_required_one.html"
private const val CAPTCHA_REQUIRED_RESPONSE_TWO = "response/captcha_required_two.html"
private const val MAIN_PAGE_VARIANT_1_RESPONSE = "response/main_page_v1.html"
@ -297,6 +311,9 @@ class TikTokDownloadRemoteSourceTest {
readResourceFile(CAPTCHA_REQUIRED_RESPONSE_TWO)
.replace("https://www.tiktok.com/@ieclauuu/video/6887614455967010049", CAPTCHA_TEST_URL)
private fun Any.readResourceFileDeletedV1UrlResponse() =
readResourceFile(DELETED_V1_URL_RESPONSE)
@JvmStatic
private fun captchaResponses() = Stream.of(
Arguments.of(CAPTCHA_REQUIRED_RESPONSE_ONE, readCaptchaOneResponse()),

File diff suppressed because one or more lines are too long