From b942e066ee5138d028a6eab4d20f4c2bc6de0abc Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:49:17 +0200 Subject: [PATCH] quality stuff --- app/build.gradle | 2 +- .../cloudstream3/ui/result/ResultFragment.kt | 2 +- .../cloudstream3/utils/ExtractorApi.kt | 88 +++++++++---------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e0e26466..305f6b18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,7 +36,7 @@ android { targetSdkVersion 30 versionCode 45 - versionName "2.9.19" + versionName "2.9.20" resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index bcc51262..b10e7b91 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -799,7 +799,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom) builder.setTitle(title) - builder.setItems(links.map { it.name }.toTypedArray()) { dia, which -> + builder.setItems(links.map { "${it.name} ${Qualities.getStringByInt(it.quality)}" }.toTypedArray()) { dia, which -> callback.invoke(links[which]) dia?.dismiss() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt index c775cbda..138dcbc3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt @@ -22,18 +22,18 @@ data class ExtractorLink( ) : VideoDownloadManager.IDownloadableMinimum data class ExtractorUri( - val uri : Uri, - val name : String, + val uri: Uri, + val name: String, val basePath: String? = null, val relativePath: String? = null, val displayName: String? = null, - val id : Int? = null, - val parentId : Int? = null, - val episode : Int? = null, - val season : Int? = null, - val headerName : String? = null, + val id: Int? = null, + val parentId: Int? = null, + val episode: Int? = null, + val season: Int? = null, + val headerName: String? = null, val tvType: TvType? = null, ) @@ -45,44 +45,36 @@ data class ExtractorSubtitleLink( ) : VideoDownloadManager.IDownloadableMinimum enum class Qualities(var value: Int) { - Unknown(0), - P360(-2), // 360p - P480(-1), // 480p - P720(1), // 720p - P1080(2), // 1080p - P1440(3), // 1440p - P2160(4); // 4k or 2160p + Unknown(400), + P144(144), // 144p + P240(240), // 240p + P360(360), // 360p + P480(480), // 480p + P720(720), // 720p + P1080(1080), // 1080p + P1440(1440), // 1440p + P2160(2160); // 4k or 2160p companion object { - fun getStringByInt(qual: Int?) : String { + fun getStringByInt(qual: Int?): String { return when (qual) { - P360.value -> "360p" - P480.value -> "480p" - P720.value -> "720p" - P1080.value -> "1080p" - P1440.value -> "1440p" - P2160.value -> "2160p/4k" - else -> "" + Unknown.value -> "" + P2160.value -> "4K" + else -> "${qual}p" } } } } fun getQualityFromName(qualityName: String?): Int { - if (qualityName == null) { + if (qualityName == null) return Qualities.Unknown.value - } - return when (qualityName.replace("p", "").replace("P", "").trim()) { - "360" -> Qualities.P360 - "480" -> Qualities.P480 - "720" -> Qualities.P720 - "1080" -> Qualities.P1080 - "1440" -> Qualities.P1440 - "2160" -> Qualities.P2160 + + val match = qualityName.lowercase().replace("p", "").trim() + return when (match) { "4k" -> Qualities.P2160 - "4K" -> Qualities.P2160 - else -> Qualities.Unknown - }.value + else -> null + }?.value ?: match.toIntOrNull() ?: Qualities.Unknown.value } private val packedRegex = Regex("""eval\(function\(p,a,c,k,e,.*\)\)""") @@ -98,7 +90,11 @@ fun getAndUnpack(string: String): String { /** * Tries to load the appropriate extractor based on link, returns true if any extractor is loaded. * */ -suspend fun loadExtractor(url: String, referer: String? = null, callback: (ExtractorLink) -> Unit) : Boolean { +suspend fun loadExtractor( + url: String, + referer: String? = null, + callback: (ExtractorLink) -> Unit +): Boolean { for (extractor in extractorApis) { if (url.startsWith(extractor.mainUrl)) { extractor.getSafeUrl(url, referer)?.forEach(callback) @@ -136,19 +132,19 @@ val extractorApis: Array = arrayOf( StreamSB8(), StreamSB9(), StreamSB10(), - // Streamhub(), cause Streamhub2() works + // Streamhub(), cause Streamhub2() works Streamhub2(), FEmbed(), FeHD(), Fplayer(), - // WatchSB(), 'cause StreamSB.kt works + // WatchSB(), 'cause StreamSB.kt works Uqload(), Uqload1(), Evoload(), Evoload1(), VoeExtractor(), - // UpstreamExtractor(), GenericM3U8.kt works + // UpstreamExtractor(), GenericM3U8.kt works Tomatomatela(), Cinestart(), @@ -162,17 +158,17 @@ val extractorApis: Array = arrayOf( AsianLoad(), - // GenericM3U8(), + // GenericM3U8(), Jawcloud(), Zplayer(), ZplayerV2(), Upstream(), - // StreamSB.kt works - // SBPlay(), - // SBPlay1(), - // SBPlay2(), + // StreamSB.kt works + // SBPlay(), + // SBPlay1(), + // SBPlay2(), PlayerVoxzer(), ) @@ -192,7 +188,7 @@ fun httpsify(url: String): String { return if (url.startsWith("//")) "https:$url" else url } -suspend fun getPostForm(requestUrl : String, html : String) : String? { +suspend fun getPostForm(requestUrl: String, html: String): String? { val document = Jsoup.parse(html) val inputs = document.select("Form > input") if (inputs.size < 4) return null @@ -216,7 +212,7 @@ suspend fun getPostForm(requestUrl : String, html : String) : String? { } delay(5000) // ye this is needed, wont work with 0 delay - val postResponse = app.post( + return app.post( requestUrl, headers = mapOf( "content-type" to "application/x-www-form-urlencoded", @@ -226,8 +222,6 @@ suspend fun getPostForm(requestUrl : String, html : String) : String? { ), data = mapOf("op" to op, "id" to id, "mode" to mode, "hash" to hash) ).text - - return postResponse } abstract class ExtractorApi {