Skip to content
Merged

Fixes #500

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.lagradost.cloudstream3.utils.Coroutines.mainWork
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
import com.lagradost.nicehttp.requestCreator
import io.ktor.http.Url
import io.ktor.http.decodeURLPart
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import okhttp3.Interceptor
Expand Down Expand Up @@ -211,7 +212,7 @@ actual class WebViewResolver actual constructor(
* */
return@runBlocking try {
when {
blacklistedFiles.any { Url(webViewUrl).encodedPath.contains(it) } || webViewUrl.endsWith(
blacklistedFiles.any { Url(webViewUrl).encodedPath.decodeURLPart().contains(it) } || webViewUrl.endsWith(
"/favicon.ico"
) -> WebResourceResponse(
"image/png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ fun MainAPI.updateUrl(url: String): String {
URLBuilder().apply {
takeFrom(updated)
user = original.user
password = original.password
encodedPath = original.encodedPath
fragment = original.fragment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper
import io.ktor.http.Url
import io.ktor.http.decodeURLPart
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
Expand Down Expand Up @@ -49,7 +50,7 @@ open class ByseSX : ExtractorApi() {
}

private fun getCodeFromUrl(url: String): String {
val path = Url(url).encodedPath
val path = Url(url).encodedPath.decodeURLPart()
return path.trimEnd('/').substringAfterLast('/')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper.Companion.generateM3u8
import io.ktor.http.Url
import io.ktor.http.decodeURLPart

class Geodailymotion : Dailymotion() {
override val name = "GeoDailymotion"
Expand Down Expand Up @@ -65,7 +66,7 @@ open class Dailymotion : ExtractorApi() {
}

private fun getVideoId(url: String): String? {
val path = Url(url).encodedPath
val path = Url(url).encodedPath.decodeURLPart()
val id = path.substringAfter("/video/")
return if (id.matches(videoIdRegex)) id else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ object NineAnimeHelper {
}
}

fun encode(input: String): String =
input.encodeUrl().replace("+", "%20")

fun encode(input: String): String = input.encodeUrl()
private fun decode(input: String): String = input.decodeUrl()
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ import com.lagradost.cloudstream3.extractors.Ztreamhub
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.Coroutines.atomicListOf
import io.ktor.http.Url
import io.ktor.http.decodeURLPart
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
Expand Down Expand Up @@ -414,7 +415,7 @@ enum class ExtractorLinkType {

private fun inferTypeFromUrl(url: String): ExtractorLinkType {
val path = try {
Url(url).encodedPath
Url(url).encodedPath.decodeURLPart()
} catch (_: Throwable) {
// don't log magnet links as errors
null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
package com.lagradost.cloudstream3.utils

import io.ktor.http.Url
import io.ktor.http.URLBuilder
import io.ktor.http.path
import io.ktor.http.decodeURLQueryComponent
import io.ktor.http.encodeURLParameter

object StringUtils {
fun String.decodeUrl(): String {
return try {
val parsed = Url(this)
URLBuilder().apply {
protocol = parsed.protocol
host = parsed.host
port = parsed.port
path(*parsed.segments.toTypedArray())
parameters.appendAll(parsed.parameters)
fragment = parsed.fragment
}.buildString()
} catch (_: Exception) {
this
}
return this.decodeURLQueryComponent()
}

fun String.encodeUrl(): String {
return try {
URLBuilder(Url(this)).buildString()
} catch (_: Exception) {
// Fallback for malformed URLs
this
}
return this.encodeURLParameter()
}

// Deprecate after next stable
Expand Down