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(pt/Anitube): Added option to disable File4Go mirror #309

Merged
merged 1 commit into from
Oct 17, 2024
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
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"
}
}