Release 1.3.3

Bugfix: add additional way to get the actual URL if first method fails
This commit is contained in:
Gergely Hegedus 2025-09-04 14:37:19 +03:00
parent b7619644c3
commit 96947b9fec
4 changed files with 28 additions and 17 deletions

View file

@ -20,8 +20,8 @@ android {
applicationId "org.fnives.tiktokdownloader" applicationId "org.fnives.tiktokdownloader"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 35 targetSdkVersion 35
versionCode 3 versionCode 4
versionName "1.3.2" versionName "1.3.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View file

@ -3,7 +3,6 @@ package org.fnives.tiktokdownloader.data.network
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.fnives.tiktokdownloader.errortracking.ErrorTracer
import org.fnives.tiktokdownloader.Logger import org.fnives.tiktokdownloader.Logger
import org.fnives.tiktokdownloader.data.model.VideoInPending import org.fnives.tiktokdownloader.data.model.VideoInPending
import org.fnives.tiktokdownloader.data.model.VideoInSavingIntoFile import org.fnives.tiktokdownloader.data.model.VideoInSavingIntoFile
@ -16,6 +15,7 @@ import org.fnives.tiktokdownloader.data.network.exceptions.VideoPrivateException
import org.fnives.tiktokdownloader.data.network.parsing.converter.VideoFileUrlConverter import org.fnives.tiktokdownloader.data.network.parsing.converter.VideoFileUrlConverter
import org.fnives.tiktokdownloader.data.network.parsing.response.VideoFileUrl import org.fnives.tiktokdownloader.data.network.parsing.response.VideoFileUrl
import org.fnives.tiktokdownloader.data.network.session.CookieStore import org.fnives.tiktokdownloader.data.network.session.CookieStore
import org.fnives.tiktokdownloader.errortracking.ErrorTracer
class TikTokDownloadRemoteSource( class TikTokDownloadRemoteSource(
private val delayBeforeRequest: Long, private val delayBeforeRequest: Long,
@ -61,8 +61,13 @@ class TikTokDownloadRemoteSource(
byteStream = response.videoInputStream byteStream = response.videoInputStream
) )
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
val exceptionName = (throwable as? HtmlException)?.exceptionName ?: "Unknown Error" val exceptionName =
ErrorTracer.addError("video-stream", "$exceptionName error while service.getVideo", throwable = throwable) (throwable as? HtmlException)?.exceptionName ?: "Unknown Error"
ErrorTracer.addError(
"video-stream",
"$exceptionName error while service.getVideo",
throwable = throwable
)
throw throwable throw throwable
} }
} }
@ -72,18 +77,15 @@ class TikTokDownloadRemoteSource(
private suspend fun <T> wrapIntoProperException(request: suspend () -> T): T = private suspend fun <T> wrapIntoProperException(request: suspend () -> T): T =
try { try {
request() request()
} catch (parsingException: ParsingException) {
throw parsingException
} catch (captchaRequiredException: CaptchaRequiredException) {
throw captchaRequiredException
} catch (videoDeletedException: VideoDeletedException) {
throw videoDeletedException
} catch (videoPrivateException: VideoPrivateException) {
throw videoPrivateException
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
if (throwable is HtmlException) {
ErrorTracer.addError(throwable.html, message = throwable.message ?: "-", throwable = throwable)
throw throwable
}
ErrorTracer.addError(html = "-", message = throwable.message ?: "-", throwable = throwable)
throw NetworkException( throw NetworkException(
cause = throwable, cause = throwable,
html = (throwable as? HtmlException)?.html.orEmpty() html = "wrapIntoProperException"
) )
} finally { } finally {
ErrorTracer.commitErrorTransaction() ErrorTracer.commitErrorTransaction()

View file

@ -4,6 +4,7 @@ import okhttp3.ResponseBody
import org.fnives.tiktokdownloader.errortracking.ErrorTracer import org.fnives.tiktokdownloader.errortracking.ErrorTracer
import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredException import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredException
import org.fnives.tiktokdownloader.data.network.exceptions.HtmlException import org.fnives.tiktokdownloader.data.network.exceptions.HtmlException
import org.fnives.tiktokdownloader.data.network.exceptions.ParsingException
import org.fnives.tiktokdownloader.data.network.exceptions.VideoDeletedException import org.fnives.tiktokdownloader.data.network.exceptions.VideoDeletedException
import org.fnives.tiktokdownloader.data.network.exceptions.VideoPrivateException import org.fnives.tiktokdownloader.data.network.exceptions.VideoPrivateException
import org.fnives.tiktokdownloader.data.network.parsing.response.ActualVideoPageUrl import org.fnives.tiktokdownloader.data.network.parsing.response.ActualVideoPageUrl
@ -22,12 +23,20 @@ class ActualVideoPageUrlConverter(
override fun convertSafely(responseBody: ResponseBody): ActualVideoPageUrl { override fun convertSafely(responseBody: ResponseBody): ActualVideoPageUrl {
val responseBodyAsString = responseBody.string() val responseBodyAsString = responseBody.string()
return try { return try {
val actualVideoPageUrl = responseBodyAsString val validateResponse = responseBodyAsString
.also(throwIfIsCaptchaResponse::invoke) .also(throwIfIsCaptchaResponse::invoke)
.also(throwIfVideoIsDeletedResponse::invoke) .also(throwIfVideoIsDeletedResponse::invoke)
.also(throwIfVideoIsPrivateResponse::invoke) .also(throwIfVideoIsPrivateResponse::invoke)
.split("rel=\"canonical\" href=\"")[1] val actualVideoPageUrl = if (validateResponse.contains("rel=\"canonical\" href=\"")) {
.split("\"")[0] validateResponse.split("rel=\"canonical\" href=\"")[1]
.split("\"")[0]
} else if (validateResponse.contains("\"canonical\":\"")){
validateResponse.split("\"canonical\":\"")[1]
.split("\"")[0]
.replace("\\u002F", "/")
} else {
throw ParsingException(message = "Can't find a way to get the proper URL from the video", html = responseBodyAsString)
}
ActualVideoPageUrl(actualVideoPageUrl, responseBodyAsString) ActualVideoPageUrl(actualVideoPageUrl, responseBodyAsString)
} catch (throwable: Throwable) { } catch (throwable: Throwable) {

Binary file not shown.