Change GDBoT proxy url and make it automatically change (#1606)
This commit is contained in:
parent
72f6e2568e
commit
b442bca887
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'HolaMovies'
|
||||
pkgNameSuffix = 'en.holamovies'
|
||||
extClass = '.HolaMovies'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
libVersion = '13'
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
@ -24,9 +23,6 @@ import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
class HolaMovies : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
@ -40,18 +36,10 @@ class HolaMovies : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DateFormatter by lazy {
|
||||
SimpleDateFormat("d MMMM yyyy", Locale.ENGLISH)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Popular ===============================
|
||||
|
||||
override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/page/$page/")
|
||||
@ -74,7 +62,7 @@ class HolaMovies : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
override fun latestUpdatesSelector(): String = "div#latest-tab-pane > div.row > div.col-md-6"
|
||||
|
||||
override fun latestUpdatesNextPageSelector(): String? = popularAnimeNextPageSelector()
|
||||
override fun latestUpdatesNextPageSelector(): String = popularAnimeNextPageSelector()
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||
val thumbnailUrl = element.selectFirst("img")!!.attr("data-src")
|
||||
@ -331,7 +319,7 @@ class HolaMovies : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
episode.url.toHttpUrl().host.contains("gdtot") ||
|
||||
episode.url.toHttpUrl().host.contains("gdbot") -> {
|
||||
GDBotExtractor(client, headers).videosFromUrl(episode.url)
|
||||
GDBotExtractor(client, headers, preferences).videosFromUrl(episode.url)
|
||||
}
|
||||
else -> { throw Exception("Unsupported url: ${episode.url}") }
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.animeextension.en.holamovies.extractors
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
@ -11,22 +12,41 @@ import okhttp3.Headers
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
class GDBotExtractor(private val client: OkHttpClient, private val headers: Headers) {
|
||||
class GDBotExtractor(private val client: OkHttpClient, private val headers: Headers, private val preferences: SharedPreferences) {
|
||||
|
||||
private val botUrl = "https://gdbot.xyz"
|
||||
private val PREF_BOT_URL_KEY = "bot_url"
|
||||
|
||||
fun videosFromUrl(serverUrl: String): List<Video> {
|
||||
private val defaultUrl = "https://gdtot.pro"
|
||||
|
||||
fun videosFromUrl(serverUrl: String, maxTries: Int = 1): List<Video> {
|
||||
val botUrl = preferences.getString(PREF_BOT_URL_KEY, defaultUrl)!!
|
||||
val videoList = mutableListOf<Video>()
|
||||
|
||||
if (maxTries == 3) throw Exception("Video extraction catastrophically failed")
|
||||
|
||||
val docHeaders = headers.newBuilder()
|
||||
.add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
|
||||
.add("Host", botUrl.toHttpUrl().host)
|
||||
.build()
|
||||
|
||||
val fileId = serverUrl.substringAfter("/file/")
|
||||
val document = client.newCall(
|
||||
val resp = try {
|
||||
client.newCall(
|
||||
GET("$botUrl/file/$fileId", headers = docHeaders),
|
||||
).execute().asJsoup()
|
||||
).execute()
|
||||
} catch (a: Exception) {
|
||||
val newHost = OkHttpClient().newCall(GET(botUrl)).execute().request.url.host
|
||||
preferences.edit().putString(PREF_BOT_URL_KEY, "https://$newHost").apply()
|
||||
return videosFromUrl(serverUrl, maxTries + 1)
|
||||
}
|
||||
|
||||
if (resp.code == 421) {
|
||||
val newHost = OkHttpClient().newCall(GET(botUrl)).execute().request.url.host
|
||||
preferences.edit().putString(PREF_BOT_URL_KEY, "https://$newHost").apply()
|
||||
return videosFromUrl(serverUrl, maxTries + 1)
|
||||
}
|
||||
|
||||
val document = resp.asJsoup()
|
||||
|
||||
videoList.addAll(
|
||||
document.select("li.py-6 > a[href]").parallelMap { server ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user