diff --git a/lib/playlist-utils/src/main/java/eu/kanade/tachiyomi/lib/playlistutils/PlaylistUtils.kt b/lib/playlist-utils/src/main/java/eu/kanade/tachiyomi/lib/playlistutils/PlaylistUtils.kt index 7e9064c9be..1ea06fbd61 100644 --- a/lib/playlist-utils/src/main/java/eu/kanade/tachiyomi/lib/playlistutils/PlaylistUtils.kt +++ b/lib/playlist-utils/src/main/java/eu/kanade/tachiyomi/lib/playlistutils/PlaylistUtils.kt @@ -8,6 +8,7 @@ import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.internal.commonEmptyHeaders +import kotlin.math.abs class PlaylistUtils(private val client: OkHttpClient, private val headers: Headers = commonEmptyHeaders) { @@ -135,7 +136,7 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade val resolution = it.substringAfter("RESOLUTION=") .substringBefore("\n") .substringAfter("x") - .substringBefore(",") + "p" + .substringBefore(",").let(::stnQuality) val videoUrl = it.substringAfter("\n").substringBefore("\n").let { url -> getAbsoluteUrl(url, playlistUrl, masterUrlBasePath)?.trimEnd() @@ -334,6 +335,13 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade // ============================= Utilities ============================== + private fun stnQuality(quality: String): String { + val intQuality = quality.toInt() + val standardQualities = listOf(144, 240, 360, 480, 720, 1080) + val result = standardQualities.minByOrNull { abs(it - intQuality) } ?: quality + return "${result}p" + } + companion object { private const val PLAYLIST_SEPARATOR = "#EXT-X-STREAM-INF:" diff --git a/lib/universal-extractor/build.gradle.kts b/lib/universal-extractor/build.gradle.kts new file mode 100644 index 0000000000..d31dd9ff6d --- /dev/null +++ b/lib/universal-extractor/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("lib-android") +} + +dependencies { + implementation(project(":lib:playlist-utils")) +} diff --git a/lib/universal-extractor/src/main/java/eu/kanade/tachiyomi/lib/universalextractor/UniversalExtractor.kt b/lib/universal-extractor/src/main/java/eu/kanade/tachiyomi/lib/universalextractor/UniversalExtractor.kt new file mode 100644 index 0000000000..81d5f1611a --- /dev/null +++ b/lib/universal-extractor/src/main/java/eu/kanade/tachiyomi/lib/universalextractor/UniversalExtractor.kt @@ -0,0 +1,86 @@ +package eu.kanade.tachiyomi.lib.universalextractor + +import android.annotation.SuppressLint +import android.app.Application +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse +import android.webkit.WebView +import android.webkit.WebViewClient +import eu.kanade.tachiyomi.animesource.model.Video +import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils +import okhttp3.Headers +import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.OkHttpClient +import uy.kohesive.injekt.injectLazy +import java.util.Locale +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +class UniversalExtractor(private val client: OkHttpClient) { + private val context: Application by injectLazy() + private val handler by lazy { Handler(Looper.getMainLooper()) } + @SuppressLint("SetJavaScriptEnabled") + fun videosFromUrl(origRequestUrl: String, origRequestHeader: Headers, customQuality: String? = null, prefix: String = ""): List