diff --git a/app/build.gradle b/app/build.gradle index a48b3f5..c259b1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" } diff --git a/app/src/main/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSource.kt b/app/src/main/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSource.kt index 2d9f385..7e406bc 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSource.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/data/network/TikTokDownloadRemoteSource.kt @@ -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 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() diff --git a/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ActualVideoPageUrlConverter.kt b/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ActualVideoPageUrlConverter.kt index 6761158..741db0d 100644 --- a/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ActualVideoPageUrlConverter.kt +++ b/app/src/main/java/org/fnives/tiktokdownloader/data/network/parsing/converter/ActualVideoPageUrlConverter.kt @@ -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) { diff --git a/tiktok-downloader.apk b/tiktok-downloader.apk index 6008fc6..9bbfed1 100644 Binary files a/tiktok-downloader.apk and b/tiktok-downloader.apk differ