Fix failing unit test
Attempt to get the video URL from the first response if the 'actual' url cannot be found within.
This commit is contained in:
parent
78606df4dd
commit
0849fdc318
4 changed files with 20 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ class ActualVideoPageUrlConverter(
|
|||
) : ParsingExceptionThrowingConverter<ActualVideoPageUrl>() {
|
||||
|
||||
@Throws(IndexOutOfBoundsException::class, CaptchaRequiredException::class)
|
||||
override fun convertSafely(responseBody: ResponseBody): ActualVideoPageUrl? {
|
||||
override fun convertSafely(responseBody: ResponseBody): ActualVideoPageUrl {
|
||||
val responseBodyAsString =responseBody.string()
|
||||
return try {
|
||||
val actualVideoPageUrl = responseBodyAsString
|
||||
|
|
|
|||
|
|
@ -9,13 +9,20 @@ abstract class ParsingExceptionThrowingConverter<T> : Converter<ResponseBody, T>
|
|||
|
||||
@Throws(ParsingException::class, CaptchaRequiredException::class)
|
||||
final override fun convert(value: ResponseBody): T? =
|
||||
try {
|
||||
doActionSafely {
|
||||
convertSafely(value)
|
||||
}
|
||||
|
||||
@Throws(ParsingException::class, CaptchaRequiredException::class)
|
||||
fun doActionSafely(action: () -> T): T {
|
||||
try {
|
||||
return action()
|
||||
} catch (captchaRequiredException: CaptchaRequiredException) {
|
||||
throw captchaRequiredException
|
||||
} catch (throwable: Throwable) {
|
||||
throw ParsingException(cause = throwable)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun convertSafely(responseBody: ResponseBody): T?
|
||||
abstract fun convertSafely(responseBody: ResponseBody): T
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package org.fnives.tiktokdownloader.data.network.parsing.converter
|
|||
import okhttp3.ResponseBody
|
||||
import org.fnives.tiktokdownloader.Logger
|
||||
import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredException
|
||||
import org.fnives.tiktokdownloader.data.network.exceptions.ParsingException
|
||||
import org.fnives.tiktokdownloader.data.network.parsing.response.VideoFileUrl
|
||||
|
||||
class VideoFileUrlConverter(
|
||||
|
|
@ -10,12 +11,17 @@ class VideoFileUrlConverter(
|
|||
) : ParsingExceptionThrowingConverter<VideoFileUrl>() {
|
||||
|
||||
@Throws(IllegalArgumentException::class, IndexOutOfBoundsException::class, CaptchaRequiredException::class)
|
||||
override fun convertSafely(responseBody: ResponseBody): VideoFileUrl? {
|
||||
return convertSafely(responseBody.string())
|
||||
override fun convertSafely(responseBody: ResponseBody): VideoFileUrl {
|
||||
return convert(responseBody.string())
|
||||
}
|
||||
|
||||
@Throws(ParsingException::class, CaptchaRequiredException::class)
|
||||
fun convertSafely(responseBody: String): VideoFileUrl {
|
||||
return doActionSafely { convert(responseBody) }
|
||||
}
|
||||
|
||||
@Throws(IllegalArgumentException::class, IndexOutOfBoundsException::class, CaptchaRequiredException::class)
|
||||
fun convertSafely(responseBody: String): VideoFileUrl {
|
||||
private fun convert(responseBody: String): VideoFileUrl {
|
||||
val html = responseBody.also(throwIfIsCaptchaResponse::invoke)
|
||||
val url = tryToParseDownloadLink(html).also { Logger.logMessage("parsed download link = $it") }
|
||||
?: tryToParseVideoSrc(html).also { Logger.logMessage("parsed video src = $it") }
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import org.fnives.tiktokdownloader.data.network.parsing.response.VideoResponse
|
|||
|
||||
class VideoResponseConverter : ParsingExceptionThrowingConverter<VideoResponse>() {
|
||||
|
||||
override fun convertSafely(responseBody: ResponseBody): VideoResponse? =
|
||||
override fun convertSafely(responseBody: ResponseBody): VideoResponse =
|
||||
VideoResponse(responseBody.contentType(), responseBody.byteStream())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue