forked from aniyomiorg/aniyomi-extensions
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finally fix faselhd source (aniyomiorg#862)
* Update build.gradle * fix faselhd
- Loading branch information
1 parent
be441f9
commit 34b7756
Showing
6 changed files
with
219 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/ar/faselhd/src/eu/kanade/tachiyomi/animeextension/ar/faselhd/GetSourcesInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package eu.kanade.tachiyomi.animeextension.ar.faselhd | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebResourceResponse | ||
import android.webkit.WebSettings | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import eu.kanade.tachiyomi.network.GET | ||
import okhttp3.Headers.Companion.toHeaders | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
import java.io.IOException | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class GetSourcesInterceptor(private val getSources: String, private val client: OkHttpClient) : Interceptor { | ||
private val context = Injekt.get<Application>() | ||
private val handler by lazy { Handler(Looper.getMainLooper()) } | ||
|
||
private val initWebView by lazy { | ||
WebSettings.getDefaultUserAgent(context) | ||
} | ||
|
||
@Synchronized | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
initWebView | ||
|
||
val request = chain.request() | ||
|
||
try { | ||
val newRequest = resolveWithWebView(request) | ||
|
||
return chain.proceed(newRequest ?: request) | ||
} catch (e: Exception) { | ||
throw IOException(e) | ||
} | ||
} | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
private fun resolveWithWebView(request: Request): Request? { | ||
val latch = CountDownLatch(1) | ||
|
||
var webView: WebView? = null | ||
|
||
val origRequestUrl = request.url.toString() | ||
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() | ||
var newRequest: Request? = null | ||
|
||
handler.post { | ||
val webview = WebView(context) | ||
webView = webview | ||
with(webview.settings) { | ||
javaScriptEnabled = true | ||
domStorageEnabled = true | ||
databaseEnabled = true | ||
useWideViewPort = false | ||
loadWithOverviewMode = false | ||
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0" | ||
} | ||
webview.webViewClient = object : WebViewClient() { | ||
override fun shouldInterceptRequest( | ||
view: WebView, | ||
request: WebResourceRequest | ||
): WebResourceResponse? { | ||
val url = request.url.toString() | ||
if (url.contains(getSources)) { | ||
val newHeaders = request.requestHeaders.toHeaders() | ||
newRequest = GET(url, newHeaders) | ||
latch.countDown() | ||
} | ||
return super.shouldInterceptRequest(view, request) | ||
} | ||
} | ||
|
||
webView?.loadUrl(origRequestUrl, headers) | ||
} | ||
|
||
latch.await(TIMEOUT_SEC, TimeUnit.SECONDS) | ||
|
||
handler.post { | ||
webView?.stopLoading() | ||
webView?.destroy() | ||
webView = null | ||
} | ||
return newRequest | ||
} | ||
|
||
companion object { | ||
const val TIMEOUT_SEC: Long = 20 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...hdmovies/src/eu/kanade/tachiyomi/animeextension/ar/faselhdmovies/GetSourcesInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package eu.kanade.tachiyomi.animeextension.ar.faselhdmovies | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebResourceResponse | ||
import android.webkit.WebSettings | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import eu.kanade.tachiyomi.network.GET | ||
import okhttp3.Headers.Companion.toHeaders | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
import java.io.IOException | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class GetSourcesInterceptor(private val getSources: String, private val client: OkHttpClient) : Interceptor { | ||
private val context = Injekt.get<Application>() | ||
private val handler by lazy { Handler(Looper.getMainLooper()) } | ||
|
||
private val initWebView by lazy { | ||
WebSettings.getDefaultUserAgent(context) | ||
} | ||
|
||
@Synchronized | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
initWebView | ||
|
||
val request = chain.request() | ||
|
||
try { | ||
val newRequest = resolveWithWebView(request) | ||
|
||
return chain.proceed(newRequest ?: request) | ||
} catch (e: Exception) { | ||
throw IOException(e) | ||
} | ||
} | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
private fun resolveWithWebView(request: Request): Request? { | ||
val latch = CountDownLatch(1) | ||
|
||
var webView: WebView? = null | ||
|
||
val origRequestUrl = request.url.toString() | ||
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() | ||
var newRequest: Request? = null | ||
|
||
handler.post { | ||
val webview = WebView(context) | ||
webView = webview | ||
with(webview.settings) { | ||
javaScriptEnabled = true | ||
domStorageEnabled = true | ||
databaseEnabled = true | ||
useWideViewPort = false | ||
loadWithOverviewMode = false | ||
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0" | ||
} | ||
webview.webViewClient = object : WebViewClient() { | ||
override fun shouldInterceptRequest( | ||
view: WebView, | ||
request: WebResourceRequest | ||
): WebResourceResponse? { | ||
val url = request.url.toString() | ||
if (url.contains(getSources)) { | ||
val newHeaders = request.requestHeaders.toHeaders() | ||
newRequest = GET(url, newHeaders) | ||
latch.countDown() | ||
} | ||
return super.shouldInterceptRequest(view, request) | ||
} | ||
} | ||
|
||
webView?.loadUrl(origRequestUrl, headers) | ||
} | ||
|
||
latch.await(TIMEOUT_SEC, TimeUnit.SECONDS) | ||
|
||
handler.post { | ||
webView?.stopLoading() | ||
webView?.destroy() | ||
webView = null | ||
} | ||
return newRequest | ||
} | ||
|
||
companion object { | ||
const val TIMEOUT_SEC: Long = 20 | ||
} | ||
} |