cloudstream-extensions-hexated/StremioX/src/main/kotlin/com/hexated/Utils.kt

44 lines
1.1 KiB
Kotlin
Raw Normal View History

2023-04-01 18:27:43 +00:00
package com.hexated
fun String.fixSourceUrl() : String {
return this.replace("/manifest.json", "").replace("stremio://", "https://")
}
2023-04-02 04:33:33 +00:00
fun fixRDSourceName(name: String?, title: String?) : String {
2023-04-03 21:27:03 +00:00
return when {
name?.contains("[RD+]", true) == true -> "[RD+] $title"
name?.contains("[RD download]", true) == true -> "[RD] $title"
!name.isNullOrEmpty() && !title.isNullOrEmpty() -> "$name $title"
else -> title ?: name ?: ""
}
2023-04-02 04:33:33 +00:00
}
2023-04-01 18:27:43 +00:00
fun getEpisodeSlug(
season: Int? = null,
episode: Int? = null,
): Pair<String, String> {
return if (season == null && episode == null) {
"" to ""
} else {
(if (season!! < 10) "0$season" else "$season") to (if (episode!! < 10) "0$episode" else "$episode")
}
}
fun fixUrl(url: String, domain: String): String {
if (url.startsWith("http")) {
return url
}
if (url.isEmpty()) {
return ""
}
val startsWithNoHttp = url.startsWith("//")
if (startsWithNoHttp) {
return "https:$url"
} else {
if (url.startsWith('/')) {
return domain + url
}
return "$domain/$url"
}
}