Skip to content

Commit

Permalink
fix(en/uhdmovies): Fix episode list & video extractor (#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky authored Dec 4, 2023
1 parent bd04dd8 commit aef6ac4
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 432 deletions.
10 changes: 6 additions & 4 deletions src/en/uhdmovies/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
}

ext {
extName = 'UHD Movies'
pkgNameSuffix = 'en.uhdmovies'
extClass = '.UHDMovies'
extVersionCode = 17
extVersionCode = 18
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package eu.kanade.tachiyomi.animeextension.en.uhdmovies

import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import okhttp3.Cookie
import okhttp3.FormBody
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
import org.jsoup.nodes.Document

class RedirectorBypasser(private val client: OkHttpClient, private val headers: Headers) {
fun bypass(url: String): String? {
val lastDoc = client.newCall(GET(url, headers)).execute()
.use { recursiveDoc(it.asJsoup()) }

val script = lastDoc.selectFirst("script:containsData(/?go=):containsData(href)")
?.data()
?: return null

val nextUrl = script.substringAfter("\"href\",\"").substringBefore('"')
val httpUrl = nextUrl.toHttpUrlOrNull() ?: return null
val cookieName = httpUrl.queryParameter("go") ?: return null
val cookieValue = script.substringAfter("'$cookieName', '").substringBefore("'")
val cookie = Cookie.parse(httpUrl, "$cookieName=$cookieValue")!!
val headers = headers.newBuilder().set("referer", lastDoc.location()).build()

val doc = runBlocking(Dispatchers.IO) {
MUTEX.withLock { // Mutex to prevent overwriting cookies from parallel requests
client.cookieJar.saveFromResponse(httpUrl, listOf(cookie))
client.newCall(GET(nextUrl, headers)).execute().use { it.asJsoup() }
}
}

return doc.selectFirst("meta[http-equiv]")?.attr("content")
?.substringAfter("url=")
}

private fun recursiveDoc(doc: Document): Document {
val form = doc.selectFirst("form#landing") ?: return doc
val url = form.attr("action")
val body = FormBody.Builder().apply {
form.select("input").forEach {
add(it.attr("name"), it.attr("value"))
}
}.build()

val headers = headers.newBuilder()
.set("referer", doc.location())
.build()

return client.newCall(POST(url, headers, body)).execute().use {
recursiveDoc(it.asJsoup())
}
}

companion object {
private val MUTEX by lazy { Mutex() }
}
}

This file was deleted.

Loading

0 comments on commit aef6ac4

Please sign in to comment.