Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(en/uhdmovies): Fix episode list & video extractor #2604

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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