From e072d3cc09a4e6597b71d8391205239a6511aa41 Mon Sep 17 00:00:00 2001 From: WebDitto Date: Wed, 16 Oct 2024 16:14:35 -0300 Subject: [PATCH] fix: Added option to disable File4Go mirror --- src/pt/anitube/build.gradle | 2 +- .../animeextension/pt/anitube/Anitube.kt | 20 +++++++++- .../extractors/AnitubeDownloadExtractor.kt | 37 +++++++++++++------ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/pt/anitube/build.gradle b/src/pt/anitube/build.gradle index a468f92..519039b 100644 --- a/src/pt/anitube/build.gradle +++ b/src/pt/anitube/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Anitube' extClass = '.Anitube' - extVersionCode = 19 + extVersionCode = 20 } apply from: "$rootDir/common.gradle" diff --git a/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/Anitube.kt b/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/Anitube.kt index 9d5e4d0..4f5f8ae 100644 --- a/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/Anitube.kt +++ b/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/Anitube.kt @@ -4,6 +4,7 @@ import android.app.Application import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.animeextension.pt.anitube.extractors.AnitubeDownloadExtractor import eu.kanade.tachiyomi.animeextension.pt.anitube.extractors.AnitubeExtractor import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource @@ -199,8 +200,10 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() { val links = mutableListOf(document.location()) - document.selectFirst("div.abaItemDown > a")?.attr("href")?.let { - links.add(it) + if (preferences.getBoolean(PREF_FILE4GO_KEY, PREF_FILE4GO_DEFAULT)!!) { + document.selectFirst("div.abaItemDown > a")?.attr("href")?.let { + links.add(it) + } } val epName = document.selectFirst("meta[itemprop=name]")!!.attr("content") @@ -235,6 +238,16 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() { } }.also(screen::addPreference) + SwitchPreferenceCompat(screen.context).apply { + key = PREF_FILE4GO_KEY + title = "Usar File4Go como mirror" + setDefaultValue(PREF_FILE4GO_DEFAULT) + summary = PREF_FILE4GO_SUMMARY + setOnPreferenceChangeListener { _, newValue -> + preferences.edit().putBoolean(key, newValue as Boolean).commit() + } + }.also(screen::addPreference) + // Auth Code EditTextPreference(screen.context).apply { key = PREF_AUTHCODE_KEY @@ -308,6 +321,9 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() { private const val PREF_AUTHCODE_KEY = "authcode" private const val PREF_AUTHCODE_SUMMARY = "Código de Autenticação" private const val PREF_AUTHCODE_DEFAULT = "" + private const val PREF_FILE4GO_KEY = "file4go" + private const val PREF_FILE4GO_SUMMARY = "Usar File4Go como mirror" + private const val PREF_FILE4GO_DEFAULT = false private const val PREF_QUALITY_KEY = "preferred_quality" private const val PREF_QUALITY_TITLE = "Qualidade preferida" private const val PREF_QUALITY_DEFAULT = "HD" diff --git a/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/extractors/AnitubeDownloadExtractor.kt b/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/extractors/AnitubeDownloadExtractor.kt index 2d0bb1d..a5e864c 100644 --- a/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/extractors/AnitubeDownloadExtractor.kt +++ b/src/pt/anitube/src/eu/kanade/tachiyomi/animeextension/pt/anitube/extractors/AnitubeDownloadExtractor.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.parallelMapNotNullBlocking import okhttp3.FormBody import okhttp3.Headers +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient class AnitubeDownloadExtractor( @@ -20,23 +21,33 @@ class AnitubeDownloadExtractor( private fun videosFromFile4Go(url: String, quality: String): Video? { Log.d(tag, "Checking download for $url") - val docDownload = client.newCall(GET(url)).execute().asJsoup() - val form = - docDownload.selectFirst("button.download")?.closest("form") + val newHeaders = headers.newBuilder() + .set("Referer", "https://${url.toHttpUrl().host}/") + .add("Accept", "*/*") + .add("Cache-Control", "no-cache") + .add("Pragma", "no-cache") + .add("Connection", "keep-alive") + .add("Sec-Fetch-Dest", "empty") + .add("Sec-Fetch-Mode", "cors") + .add("Sec-Fetch-Site", "same-site") + .build() - if (form == null) { - Log.d(tag, "Download form not found for $url") - return null - } + val id = url.split('/').last() + val idusuario = + client.newCall(GET("$ADS_URL/file4go.php", headers = newHeaders)) + .execute() + .body.string() + .substringAfter("\"publicidade\"") + .substringAfter('"') + .substringBefore('"') val body = FormBody.Builder().apply { - form.select("input[name]").forEach { - add(it.attr("name"), it.attr("value")) - } + add("id", id) + add("idusuario", idusuario) }.build() - val postUrl = form.attr("action") + val postUrl = "https://www.file4go.net/getdownload_new_anitube.php" val postHeaders = headers.newBuilder() .set("Referer", url) @@ -95,4 +106,8 @@ class AnitubeDownloadExtractor( return videosFromDownloadPage(url, epName) } + + companion object { + private const val ADS_URL = "https://ads.anitube.vip" + } }