forked from aniyomiorg/aniyomi-extensions
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ext { | ||
extName = 'Megaflix' | ||
extClass = '.Megaflix' | ||
extVersionCode = 21 | ||
extVersionCode = 22 | ||
isNsfw = true | ||
} | ||
|
||
|
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
69 changes: 69 additions & 0 deletions
69
src/pt/megaflix/src/eu/kanade/tachiyomi/animeextension/pt/megaflix/WebViewResolver.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,69 @@ | ||
package eu.kanade.tachiyomi.animeextension.pt.megaflix | ||
|
||
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.WebView | ||
import android.webkit.WebViewClient | ||
import okhttp3.Headers | ||
import uy.kohesive.injekt.injectLazy | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class WebViewResolver() { | ||
private val context: Application by injectLazy() | ||
private val handler by lazy { Handler(Looper.getMainLooper()) } | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
fun getUrl(origRequestUrl: String, origRequestheader: Headers): String { | ||
val latch = CountDownLatch(1) | ||
var webView: WebView? = null | ||
var resultUrl = "" | ||
val headers = origRequestheader.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() | ||
|
||
handler.post { | ||
val webview = WebView(context) | ||
webView = webview | ||
with(webview.settings) { | ||
javaScriptEnabled = true | ||
domStorageEnabled = true | ||
databaseEnabled = true | ||
useWideViewPort = false | ||
loadWithOverviewMode = false | ||
userAgentString = origRequestheader["User-Agent"] | ||
} | ||
webview.webViewClient = object : WebViewClient() { | ||
override fun shouldInterceptRequest( | ||
view: WebView, | ||
request: WebResourceRequest, | ||
): WebResourceResponse? { | ||
val url = request.url.toString() | ||
if (VIDEO_REGEX.containsMatchIn(url)) { | ||
resultUrl = url | ||
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 resultUrl | ||
} | ||
|
||
companion object { | ||
const val TIMEOUT_SEC: Long = 20 | ||
private val VIDEO_REGEX by lazy { Regex("\\.(mp4|m3u8)") } | ||
} | ||
} |
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