FembedExtractor: Prevent cloudflare problems (#969)

Vizer: Remove unnecessary runCatching block
This commit is contained in:
Claudemirovsky
2022-10-23 03:42:11 -03:00
committed by GitHub
parent 2d3190e174
commit df3d1a0e5b
2 changed files with 5 additions and 6 deletions

View File

@ -9,8 +9,9 @@ import okhttp3.OkHttpClient
class FembedExtractor(private val client: OkHttpClient) {
fun videosFromUrl(url: String, prefix: String = ""): List<Video> {
val videoApi = url.replace("/v/", "/api/source/")
val body = client.newCall(POST(videoApi)).execute()
.body?.string().orEmpty()
val body = runCatching {
client.newCall(POST(videoApi)).execute().body?.string().orEmpty()
}.getOrNull() ?: return emptyList<Video>()
val jsonResponse = Json { ignoreUnknownKeys = true }
.decodeFromString<FembedResponse>(body)