Extend Video Deleted parsing
This commit is contained in:
parent
158c322cda
commit
45fb0d4d71
4 changed files with 52 additions and 5 deletions
|
|
@ -38,6 +38,6 @@ Example getting the stack trace for a specific error message:
|
||||||
`jq -r '.[].errors[] | select(.message == "Parsing Error") | .stacktrace' errors.json`
|
`jq -r '.[].errors[] | select(.message == "Parsing Error") | .stacktrace' errors.json`
|
||||||
|
|
||||||
Or getting all htmls if an error happened in the 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.
|
> Use -r when you want to avoid the JSON string quotes around output.
|
||||||
|
|
@ -4,12 +4,18 @@ import org.fnives.tiktokdownloader.data.network.exceptions.VideoDeletedException
|
||||||
|
|
||||||
class ThrowIfVideoIsDeletedResponse {
|
class ThrowIfVideoIsDeletedResponse {
|
||||||
|
|
||||||
|
private val potentialIssues = listOf(
|
||||||
|
"\"statusMsg\":\"status_deleted",
|
||||||
|
"\"statusMsg\":\"item doesn't exist",
|
||||||
|
"statusMsg\":\"[^\"]*status_audit_not_pass"
|
||||||
|
)
|
||||||
|
|
||||||
@Throws(VideoDeletedException::class)
|
@Throws(VideoDeletedException::class)
|
||||||
fun invoke(html: String) {
|
fun invoke(html: String) {
|
||||||
if (html.contains("\"statusMsg\":\"status_deleted")) {
|
potentialIssues.forEach {
|
||||||
throw VideoDeletedException(html = html)
|
if (html.contains(it.toRegex())) {
|
||||||
} else if (html.contains("\"statusMsg\":\"item doesn't exist")) {
|
|
||||||
throw VideoDeletedException(html = html)
|
throw VideoDeletedException(html = html)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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.CaptchaRequiredException
|
||||||
import org.fnives.tiktokdownloader.data.network.exceptions.NetworkException
|
import org.fnives.tiktokdownloader.data.network.exceptions.NetworkException
|
||||||
import org.fnives.tiktokdownloader.data.network.exceptions.ParsingException
|
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.di.module.NetworkModule
|
||||||
import org.fnives.tiktokdownloader.helper.readResourceFile
|
import org.fnives.tiktokdownloader.helper.readResourceFile
|
||||||
import org.junit.jupiter.api.AfterEach
|
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 {
|
companion object {
|
||||||
private const val SHORTENED_URL_RESPONSE = "response/shortened_url_response.html"
|
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_ONE = "response/captcha_required_one.html"
|
||||||
private const val CAPTCHA_REQUIRED_RESPONSE_TWO = "response/captcha_required_two.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"
|
private const val MAIN_PAGE_VARIANT_1_RESPONSE = "response/main_page_v1.html"
|
||||||
|
|
@ -297,6 +311,9 @@ class TikTokDownloadRemoteSourceTest {
|
||||||
readResourceFile(CAPTCHA_REQUIRED_RESPONSE_TWO)
|
readResourceFile(CAPTCHA_REQUIRED_RESPONSE_TWO)
|
||||||
.replace("https://www.tiktok.com/@ieclauuu/video/6887614455967010049", CAPTCHA_TEST_URL)
|
.replace("https://www.tiktok.com/@ieclauuu/video/6887614455967010049", CAPTCHA_TEST_URL)
|
||||||
|
|
||||||
|
private fun Any.readResourceFileDeletedV1UrlResponse() =
|
||||||
|
readResourceFile(DELETED_V1_URL_RESPONSE)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun captchaResponses() = Stream.of(
|
private fun captchaResponses() = Stream.of(
|
||||||
Arguments.of(CAPTCHA_REQUIRED_RESPONSE_ONE, readCaptchaOneResponse()),
|
Arguments.of(CAPTCHA_REQUIRED_RESPONSE_ONE, readCaptchaOneResponse()),
|
||||||
|
|
|
||||||
24
app/src/test/resources/response/video_deleted_v1.html
Normal file
24
app/src/test/resources/response/video_deleted_v1.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue