fix networking on some extensions

This commit is contained in:
rebelonion 2024-02-08 00:38:09 -06:00
parent d86481a0f7
commit b093b5f979
5 changed files with 38 additions and 29 deletions

View file

@ -138,10 +138,11 @@ dependencies {
implementation 'ca.gosyer:voyager-navigator:1.0.0-rc07' implementation 'ca.gosyer:voyager-navigator:1.0.0-rc07'
implementation 'com.squareup.logcat:logcat:0.1' implementation 'com.squareup.logcat:logcat:0.1'
implementation 'com.github.inorichi.injekt:injekt-core:65b0440' implementation 'com.github.inorichi.injekt:injekt-core:65b0440'
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.11' implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.12'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.12'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps'
implementation 'com.squareup.okio:okio:3.7.0' implementation 'com.squareup.okio:okio:3.7.0'
implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.12'
implementation 'ch.acra:acra-http:5.11.3' implementation 'ch.acra:acra-http:5.11.3'
implementation 'org.jsoup:jsoup:1.15.4' implementation 'org.jsoup:jsoup:1.15.4'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.2' implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.2'

View file

@ -257,8 +257,15 @@ class AnimeWatchAdapter(
val url = sourceHttp?.baseUrl val url = sourceHttp?.baseUrl
url?.let { url?.let {
refresh = true refresh = true
val headersMap = try {
sourceHttp.headers.toMultimap()
.mapValues { it.value.getOrNull(0) ?: "" }
} catch (e: Exception) {
emptyMap()
}
val intent = Intent(fragment.requireContext(), CookieCatcher::class.java) val intent = Intent(fragment.requireContext(), CookieCatcher::class.java)
.putExtra("url", url) .putExtra("url", url)
.putExtra("headers", headersMap as HashMap<String, String>)
startActivity(fragment.requireContext(), intent, null) startActivity(fragment.requireContext(), intent, null)
} }
} }

View file

@ -97,7 +97,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import okhttp3.internal.immutableListOf
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.* import java.util.*
@ -1375,16 +1374,16 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
logger("mimeType: $mimeType") logger("mimeType: $mimeType")
if (sub != null) { if (sub != null) {
val listofnotnullsubs = immutableListOf(sub).filterNotNull() val listofnotnullsubs = listOfNotNull(sub)
builder.setSubtitleConfigurations(listofnotnullsubs) builder.setSubtitleConfigurations(listofnotnullsubs)
} }
builder.build() builder.build()
} else { } else {
val addedSubsDownloadedMediaItem = downloadedMediaItem.buildUpon() val addedSubsDownloadedMediaItem = downloadedMediaItem.buildUpon()
if (sub != null) { if (sub != null) {
val listofnotnullsubs = immutableListOf(sub).filterNotNull() val listofnotnullsubs = listOfNotNull(sub)
val addLanguage = listofnotnullsubs[0].buildUpon().setLanguage("en").build() val addLanguage = listofnotnullsubs[0].buildUpon().setLanguage("en").build()
addedSubsDownloadedMediaItem.setSubtitleConfigurations(immutableListOf(addLanguage)) addedSubsDownloadedMediaItem.setSubtitleConfigurations(listOf(addLanguage))
episode.selectedSubtitle = 0 episode.selectedSubtitle = 0
} }
addedSubsDownloadedMediaItem.build() addedSubsDownloadedMediaItem.build()

View file

@ -17,12 +17,14 @@ import uy.kohesive.injekt.api.get
class CookieCatcher : AppCompatActivity() { class CookieCatcher : AppCompatActivity() {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
@Suppress("UNCHECKED_CAST")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
//get url from intent //get url from intent
val url = intent.getStringExtra("url") ?: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" val url = intent.getStringExtra("url") ?: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
val headers: Map<String, String> = intent.getSerializableExtra("headers") as? Map<String, String> ?: emptyMap()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val process = Application.getProcessName() val process = Application.getProcessName()
@ -54,7 +56,7 @@ class CookieCatcher : AppCompatActivity() {
} }
} }
webView.loadUrl(url) webView.loadUrl(url, headers)
} }
} }

View file

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
import okhttp3.Cache import okhttp3.Cache
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.brotli.BrotliInterceptor
import java.io.File import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -19,26 +20,23 @@ class NetworkHelper(
context: Context context: Context
) { ) {
private val cacheDir = File(context.cacheDir, "network_cache")
private val cacheSize = 5L * 1024 * 1024 // 5 MiB
val cookieJar = AndroidCookieJar() val cookieJar = AndroidCookieJar()
private val userAgentInterceptor by lazy { val client: OkHttpClient = run {
UserAgentInterceptor(::defaultUserAgentProvider)
}
private val cloudflareInterceptor by lazy {
CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider)
}
private fun baseClientBuilder(callTimeout: Int = 2): OkHttpClient.Builder {
val builder = OkHttpClient.Builder() val builder = OkHttpClient.Builder()
.cookieJar(cookieJar) .cookieJar(cookieJar)
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS)
.callTimeout(callTimeout.toLong(), TimeUnit.MINUTES) .callTimeout(2, TimeUnit.MINUTES)
.cache(
Cache(
directory = File(context.cacheDir, "network_cache"),
maxSize = 5L * 1024 * 1024, // 5 MiB
),
)
.addInterceptor(BrotliInterceptor)
.addInterceptor(UncaughtExceptionInterceptor()) .addInterceptor(UncaughtExceptionInterceptor())
.addInterceptor(userAgentInterceptor) .addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))
if (PrefManager.getVal(PrefName.VerboseLogging)) { if (PrefManager.getVal(PrefName.VerboseLogging)) {
val httpLoggingInterceptor = HttpLoggingInterceptor().apply { val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
@ -47,6 +45,10 @@ class NetworkHelper(
builder.addNetworkInterceptor(httpLoggingInterceptor) builder.addNetworkInterceptor(httpLoggingInterceptor)
} }
builder.addInterceptor(
CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider),
)
when (PrefManager.getVal<Int>(PrefName.DohProvider)) { when (PrefManager.getVal<Int>(PrefName.DohProvider)) {
PREF_DOH_CLOUDFLARE -> builder.dohCloudflare() PREF_DOH_CLOUDFLARE -> builder.dohCloudflare()
PREF_DOH_GOOGLE -> builder.dohGoogle() PREF_DOH_GOOGLE -> builder.dohGoogle()
@ -63,19 +65,17 @@ class NetworkHelper(
PREF_DOH_LIBREDNS -> builder.dohLibreDNS() PREF_DOH_LIBREDNS -> builder.dohLibreDNS()
} }
return builder builder.build()
} }
val downloadClient = client.newBuilder().callTimeout(20, TimeUnit.MINUTES).build()
val client by lazy { baseClientBuilder().cache(Cache(cacheDir, cacheSize)).build() } /**
val downloadClient by lazy { baseClientBuilder(20).build() } * @deprecated Since extension-lib 1.5
*/
@Deprecated("The regular client handles Cloudflare by default")
@Suppress("UNUSED") @Suppress("UNUSED")
val cloudflareClient by lazy { val cloudflareClient: OkHttpClient = client
client.newBuilder()
.addInterceptor(cloudflareInterceptor)
.build()
}
val requestClient = Requests( val requestClient = Requests(
client, client,