diff --git a/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ThrowIfVideoIsDeletedResponse.kt b/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ThrowIfVideoIsDeletedResponse.kt index c575a4a..97661ee 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ThrowIfVideoIsDeletedResponse.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ThrowIfVideoIsDeletedResponse.kt @@ -10,12 +10,17 @@ class ThrowIfVideoIsDeletedResponse { "statusMsg\":\"[^\"]*status_audit_not_pass" ) + private val redirectedToExplorePage = "\"seo.abtest\":{\"canonical\":\"https:\\u002F\\u002Fwww.tiktok.com\\u002Fexplore\"" + @Throws(VideoDeletedException::class) fun invoke(html: String) { potentialIssues.forEach { if (html.contains(it.toRegex())) { throw VideoDeletedException(html = html) } + if (html.contains(redirectedToExplorePage)) { + throw VideoDeletedException(html = html) + } } } } \ No newline at end of file diff --git a/app/src/test/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSourceTest.kt b/app/src/test/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSourceTest.kt index c5807c7..fc2a60e 100644 --- a/app/src/test/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSourceTest.kt +++ b/app/src/test/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSourceTest.kt @@ -273,9 +273,22 @@ class TikTokDownloadRemoteSourceTest { } } + @Test + fun GIVEN_deleted_video_response_v2_THEN_proper_Exception_is_Returned() { + Assertions.assertThrows(VideoDeletedException::class.java) { + runBlocking { + val deletedResponse = readResourceFileDeletedV2UrlResponse() + 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 DELETED_V2_URL_RESPONSE = "response/video_deleted_v2.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" @@ -314,6 +327,9 @@ class TikTokDownloadRemoteSourceTest { private fun Any.readResourceFileDeletedV1UrlResponse() = readResourceFile(DELETED_V1_URL_RESPONSE) + private fun Any.readResourceFileDeletedV2UrlResponse() = + readResourceFile(DELETED_V2_URL_RESPONSE) + @JvmStatic private fun captchaResponses() = Stream.of( Arguments.of(CAPTCHA_REQUIRED_RESPONSE_ONE, readCaptchaOneResponse()), diff --git a/app/src/test/java/org/fnives/uptodate/TikTokDownloadRemoteSourceUpToDateTest.kt b/app/src/test/java/org/fnives/uptodate/TikTokDownloadRemoteSourceUpToDateTest.kt index 30b9fe1..0cbd6ad 100644 --- a/app/src/test/java/org/fnives/uptodate/TikTokDownloadRemoteSourceUpToDateTest.kt +++ b/app/src/test/java/org/fnives/uptodate/TikTokDownloadRemoteSourceUpToDateTest.kt @@ -69,8 +69,11 @@ class TikTokDownloadRemoteSourceUpToDateTest { @Test fun GIVEN_private_WHEN_downloading_THEN_proper_exception_is_thrown() { val parameter = VideoInPending("123", PRIVATE_VIDEO_URL) - Assertions.assertThrows(VideoPrivateException::class.java) { - runBlocking { sut.getVideo(parameter) } + Assertions.assertThrows(VideoDeletedException::class.java) { + // DELETED response is also accepted: sometimes cant differentiate + Assertions.assertThrows(VideoPrivateException::class.java) { + runBlocking { sut.getVideo(parameter) } + } } } diff --git a/app/src/test/resources/response/video_deleted_v2.html b/app/src/test/resources/response/video_deleted_v2.html new file mode 100644 index 0000000..0f59bf2 --- /dev/null +++ b/app/src/test/resources/response/video_deleted_v2.html @@ -0,0 +1,23 @@ + + + + + TikTok - Make Your Day + + + + + + + +
+ +
+ + + + \ No newline at end of file