-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(en/uhdmovies): Fix episode list & video extractor (#2604)
- Loading branch information
1 parent
bd04dd8
commit aef6ac4
Showing
4 changed files
with
330 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/en/uhdmovies/src/eu/kanade/tachiyomi/animeextension/en/uhdmovies/RedirectorBypasser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |
87 changes: 0 additions & 87 deletions
87
src/en/uhdmovies/src/eu/kanade/tachiyomi/animeextension/en/uhdmovies/TokenInterceptor.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.