Skip to content

Commit

Permalink
fix(pt/Anitube): Added option to disable File4Go mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
WebDitto committed Oct 16, 2024
1 parent 4bece4b commit 8b2f982
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pt/anitube/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Anitube'
extClass = '.Anitube'
extVersionCode = 19
extVersionCode = 20
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -95,4 +106,8 @@ class AnitubeDownloadExtractor(

return videosFromDownloadPage(url, epName)
}

companion object {
private const val ADS_URL = "https://ads.anitube.vip"
}
}

0 comments on commit 8b2f982

Please sign in to comment.