From 75472f5847afb8771fbeb64bd46adf2b7cd9bec8 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Sun, 27 Feb 2022 02:03:01 +0100 Subject: [PATCH] fixed #717 and regex stuff --- .../cloudstream3/animeproviders/AnimePaheProvider.kt | 6 +++--- .../cloudstream3/animeproviders/NineAnimeProvider.kt | 4 ++-- .../cloudstream3/animeproviders/TenshiProvider.kt | 2 +- .../cloudstream3/animeproviders/WcoProvider.kt | 2 +- .../lagradost/cloudstream3/extractors/M3u8Manifest.kt | 2 +- .../lagradost/cloudstream3/extractors/WcoStream.kt | 4 ++-- .../cloudstream3/movieproviders/HDMProvider.kt | 4 ++-- .../lagradost/cloudstream3/ui/player/CS3IPlayer.kt | 11 ++++------- .../cloudstream3/ui/player/NonFinalTextRenderer.kt | 2 +- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt index e71d1a9a..2b78ccc6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt @@ -35,7 +35,7 @@ class AnimePaheProvider : MainAPI() { } } - val YTSM = "ysmm = '([^']+)".toRegex() + val YTSM = Regex("ysmm = '([^']+)") val KWIK_PARAMS_RE = Regex("""\("(\w+)",\d+,"(\w+)",(\d+),(\d+),\d+\)""") val KWIK_D_URL = Regex("action=\"([^\"]+)\"") @@ -264,11 +264,11 @@ class AnimePaheProvider : MainAPI() { } val episodes = generateListOfEpisodes(url) - val year = """Aired:[^,]*, (\d+)""".toRegex() + val year = Regex("""Aired:[^,]*, (\d+)""") .find(html)!!.destructured.component1() .toIntOrNull() val status = - when ("""Status:[^a]*a href=["']/anime/(.*?)["']""".toRegex() + when (Regex("""Status:[^a]*a href=["']/anime/(.*?)["']""") .find(html)!!.destructured.component1()) { "airing" -> ShowStatus.Ongoing "completed" -> ShowStatus.Completed diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt index 65730e78..2b34df6f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt @@ -125,9 +125,9 @@ class NineAnimeProvider : MainAPI() { private fun ze(input: String): String { val t = if (input.replace("""[\t\n\f\r]""".toRegex(), "").length % 4 == 0) { - input.replace("""/==?$/""".toRegex(), "") + input.replace(Regex("""/==?$/"""), "") } else input - if (t.length % 4 == 1 || t.contains("""[^+/0-9A-Za-z]""".toRegex())) throw Exception("bad input") + if (t.length % 4 == 1 || t.contains(Regex("""[^+/0-9A-Za-z]"""))) throw Exception("bad input") var i: Int var r = "" var e = 0 diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt index c3b01e1f..424850ea 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt @@ -284,7 +284,7 @@ class TenshiProvider : MainAPI() { document.selectFirst("span.value > span[title=\"Japanese\"]")?.parent()?.text() ?.trim() - val pattern = "(\\d{4})".toRegex() + val pattern = Regex("(\\d{4})") val yearText = document.selectFirst("li.release-date .value").text() year = pattern.find(yearText)?.groupValues?.get(1)?.toIntOrNull() diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt index e9266eab..c461e560 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt @@ -54,7 +54,7 @@ class WcoProvider : MainAPI() { val title = nameHeader.text().replace(" (Dub)", "") val href = nameHeader.attr("href").replace("/watch/", "/anime/") - .replace("-episode-.*".toRegex(), "/") + .replace(Regex("-episode-.*"), "/") val isDub = filmPoster.selectFirst("> div.film-poster-quality")?.text()?.contains("DUB") ?: false diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/M3u8Manifest.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/M3u8Manifest.kt index 2a71e748..545dc309 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/M3u8Manifest.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/M3u8Manifest.kt @@ -5,7 +5,7 @@ object M3u8Manifest { // URL = first, QUALITY = second fun extractLinks(m3u8Data: String): ArrayList> { val data: ArrayList> = ArrayList() - "\"(.*?)\":\"(.*?)\"".toRegex().findAll(m3u8Data).forEach { + Regex("\"(.*?)\":\"(.*?)\"").findAll(m3u8Data).forEach { var quality = it.groupValues[1].replace("auto", "Auto") if (quality != "Auto" && !quality.endsWith('p')) quality += "p" val url = it.groupValues[2] diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/WcoStream.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/WcoStream.kt index 6af4fd3a..607b0898 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/WcoStream.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/WcoStream.kt @@ -20,8 +20,8 @@ open class WcoStream : ExtractorApi() { val baseUrl = url.split("/e/")[0] val html = app.get(url, headers = mapOf("Referer" to "https://wcostream.cc/")).text - val (Id) = ("/e/(.*?)?domain".toRegex().find(url)?.destructured ?: Regex("""/e/(.*)""").find(url)?.destructured) ?: return emptyList() - val (skey) = """skey\s=\s['"](.*?)['"];""".toRegex().find(html)?.destructured ?: return emptyList() + val (Id) = (Regex("/e/(.*?)?domain").find(url)?.destructured ?: Regex("""/e/(.*)""").find(url)?.destructured) ?: return emptyList() + val (skey) = Regex("""skey\s=\s['"](.*?)['"];""").find(html)?.destructured ?: return emptyList() val apiLink = "$baseUrl/info/$Id?domain=wcostream.cc&skey=$skey" val referrer = "$baseUrl/e/$Id?domain=wcostream.cc" diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/HDMProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/HDMProvider.kt index 136df42e..009372d8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/HDMProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/HDMProvider.kt @@ -39,9 +39,9 @@ class HDMProvider : MainAPI() { callback: (ExtractorLink) -> Unit ): Boolean { if (data == "") return false - val slug = ".*/(.*?)\\.mp4".toRegex().find(data)?.groupValues?.get(1) ?: return false + val slug = Regex(".*/(.*?)\\.mp4").find(data)?.groupValues?.get(1) ?: return false val response = app.get(data).text - val key = "playlist\\.m3u8(.*?)\"".toRegex().find(response)?.groupValues?.get(1) ?: return false + val key = Regex("playlist\\.m3u8(.*?)\"").find(response)?.groupValues?.get(1) ?: return false callback.invoke( ExtractorLink( this.name, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index ee2cb8e2..57e1d306 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -102,7 +102,7 @@ class CS3IPlayer : IPlayer { playerPositionChanged: ((Pair) -> Unit)?, nextEpisode: (() -> Unit)?, prevEpisode: (() -> Unit)?, - subtitlesUpdates: (() -> Unit)? + subtitlesUpdates: (() -> Unit)?, ) { this.playerUpdated = playerUpdated this.updateIsPlaying = updateIsPlaying @@ -218,7 +218,7 @@ class CS3IPlayer : IPlayer { } ?: false } - var currentSubtitleOffset : Long = 0 + var currentSubtitleOffset: Long = 0 override fun setSubtitleOffset(offset: Long) { currentSubtitleOffset = offset @@ -419,7 +419,7 @@ class CS3IPlayer : IPlayer { currentWindow: Int, playbackPosition: Long, playBackSpeed: Float, - subtitleOffset : Long, + subtitleOffset: Long, playWhenReady: Boolean = true, cacheFactory: CacheDataSource.Factory? = null, trackSelector: TrackSelector? = null, @@ -617,10 +617,7 @@ class CS3IPlayer : IPlayer { } //override fun onCues(cues: MutableList) { - // cues.firstOrNull()?.text?.let { - // println("CUE: $it") - // } - // super.onCues(cues) + // super.onCues(cues.map { cue -> cue.buildUpon().setText("Hello world").setSize(Cue.DIMEN_UNSET).build() }) //} override fun onRenderedFirstFrame() { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt index 863a60c5..50eb758a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/NonFinalTextRenderer.kt @@ -308,7 +308,7 @@ open class NonFinalTextRenderer @JvmOverloads constructor( } private fun invokeUpdateOutputInternal(cues: List) { - output.onCues(cues) + output.onCues(cues.map { cue -> cue.buildUpon().setSize(Cue.DIMEN_UNSET).build() }) // this fixes https://github.com/LagradOst/CloudStream-3/issues/717 } /**