Release 1.3.3
Bugfix: add additional way to get the actual URL if first method fails
This commit is contained in:
parent
b7619644c3
commit
96947b9fec
4 changed files with 28 additions and 17 deletions
|
|
@ -20,8 +20,8 @@ android {
|
|||
applicationId "org.fnives.tiktokdownloader"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 35
|
||||
versionCode 3
|
||||
versionName "1.3.2"
|
||||
versionCode 4
|
||||
versionName "1.3.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.fnives.tiktokdownloader.data.network
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.fnives.tiktokdownloader.errortracking.ErrorTracer
|
||||
import org.fnives.tiktokdownloader.Logger
|
||||
import org.fnives.tiktokdownloader.data.model.VideoInPending
|
||||
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.response.VideoFileUrl
|
||||
import org.fnives.tiktokdownloader.data.network.session.CookieStore
|
||||
import org.fnives.tiktokdownloader.errortracking.ErrorTracer
|
||||
|
||||
class TikTokDownloadRemoteSource(
|
||||
private val delayBeforeRequest: Long,
|
||||
|
|
@ -61,8 +61,13 @@ class TikTokDownloadRemoteSource(
|
|||
byteStream = response.videoInputStream
|
||||
)
|
||||
} catch (throwable: Throwable) {
|
||||
val exceptionName = (throwable as? HtmlException)?.exceptionName ?: "Unknown Error"
|
||||
ErrorTracer.addError("video-stream", "$exceptionName error while service.getVideo", throwable = throwable)
|
||||
val exceptionName =
|
||||
(throwable as? HtmlException)?.exceptionName ?: "Unknown Error"
|
||||
ErrorTracer.addError(
|
||||
"video-stream",
|
||||
"$exceptionName error while service.getVideo",
|
||||
throwable = throwable
|
||||
)
|
||||
throw throwable
|
||||
}
|
||||
}
|
||||
|
|
@ -72,18 +77,15 @@ class TikTokDownloadRemoteSource(
|
|||
private suspend fun <T> wrapIntoProperException(request: suspend () -> T): T =
|
||||
try {
|
||||
request()
|
||||
} catch (parsingException: ParsingException) {
|
||||
throw parsingException
|
||||
} catch (captchaRequiredException: CaptchaRequiredException) {
|
||||
throw captchaRequiredException
|
||||
} catch (videoDeletedException: VideoDeletedException) {
|
||||
throw videoDeletedException
|
||||
} catch (videoPrivateException: VideoPrivateException) {
|
||||
throw videoPrivateException
|
||||
} 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(
|
||||
cause = throwable,
|
||||
html = (throwable as? HtmlException)?.html.orEmpty()
|
||||
html = "wrapIntoProperException"
|
||||
)
|
||||
} finally {
|
||||
ErrorTracer.commitErrorTransaction()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import okhttp3.ResponseBody
|
|||
import org.fnives.tiktokdownloader.errortracking.ErrorTracer
|
||||
import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredException
|
||||
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.VideoPrivateException
|
||||
import org.fnives.tiktokdownloader.data.network.parsing.response.ActualVideoPageUrl
|
||||
|
|
@ -22,12 +23,20 @@ class ActualVideoPageUrlConverter(
|
|||
override fun convertSafely(responseBody: ResponseBody): ActualVideoPageUrl {
|
||||
val responseBodyAsString = responseBody.string()
|
||||
return try {
|
||||
val actualVideoPageUrl = responseBodyAsString
|
||||
val validateResponse = responseBodyAsString
|
||||
.also(throwIfIsCaptchaResponse::invoke)
|
||||
.also(throwIfVideoIsDeletedResponse::invoke)
|
||||
.also(throwIfVideoIsPrivateResponse::invoke)
|
||||
.split("rel=\"canonical\" href=\"")[1]
|
||||
.split("\"")[0]
|
||||
val actualVideoPageUrl = if (validateResponse.contains("rel=\"canonical\" href=\"")) {
|
||||
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)
|
||||
} catch (throwable: Throwable) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue