From 687daeecee559d5b82b6a83cbda8899561b8c31d Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Wed, 15 Jul 2026 10:06:06 -0700 Subject: [PATCH 1/2] Add actual declarations for webMain/webTest --- .../com/lagradost/api/ContextHelper.web.kt | 4 +++ .../webMain/kotlin/com/lagradost/api/Log.kt | 19 +++++++++++ .../extractors/YoutubeExtractor.web.kt | 32 +++++++++++++++++++ .../cloudstream3/mvvm/ArchComponentExt.web.kt | 32 +++++++++++++++++++ .../cloudstream3/utils/Coroutines.web.kt | 14 ++++++++ .../cloudstream3/utils/Ignore.web.kt | 5 +++ 6 files changed, 106 insertions(+) create mode 100644 library/src/webMain/kotlin/com/lagradost/api/ContextHelper.web.kt create mode 100644 library/src/webMain/kotlin/com/lagradost/api/Log.kt create mode 100644 library/src/webMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.web.kt create mode 100644 library/src/webMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.web.kt create mode 100644 library/src/webMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.web.kt create mode 100644 library/src/webTest/kotlin/com/lagradost/cloudstream3/utils/Ignore.web.kt diff --git a/library/src/webMain/kotlin/com/lagradost/api/ContextHelper.web.kt b/library/src/webMain/kotlin/com/lagradost/api/ContextHelper.web.kt new file mode 100644 index 00000000000..83cae11a5c6 --- /dev/null +++ b/library/src/webMain/kotlin/com/lagradost/api/ContextHelper.web.kt @@ -0,0 +1,4 @@ +package com.lagradost.api + +actual fun getContext(): Any? = null +actual fun setContext(context: Any?) = Unit diff --git a/library/src/webMain/kotlin/com/lagradost/api/Log.kt b/library/src/webMain/kotlin/com/lagradost/api/Log.kt new file mode 100644 index 00000000000..8062526d417 --- /dev/null +++ b/library/src/webMain/kotlin/com/lagradost/api/Log.kt @@ -0,0 +1,19 @@ +package com.lagradost.api + +actual object Log { + actual fun d(tag: String, message: String) { + console.log("[$tag] $message") + } + + actual fun i(tag: String, message: String) { + console.info("[$tag] $message") + } + + actual fun w(tag: String, message: String) { + console.warn("[$tag] $message") + } + + actual fun e(tag: String, message: String) { + console.error("[$tag] $message") + } +} diff --git a/library/src/webMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.web.kt b/library/src/webMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.web.kt new file mode 100644 index 00000000000..07463bd56e5 --- /dev/null +++ b/library/src/webMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.web.kt @@ -0,0 +1,32 @@ +package com.lagradost.cloudstream3.extractors + +import com.lagradost.cloudstream3.SubtitleFile +import com.lagradost.cloudstream3.utils.ExtractorApi +import com.lagradost.cloudstream3.utils.ExtractorLink + +/** + * Web/JS target shim. + * + * NewPipeExtractor is JVM-only, so the full extraction logic used on + * Android/desktop can't run here. This stub keeps the multiplatform + * source set compiling; it performs no extraction and simply reports + * that no links were found on this target. + * + * If/when a JS-compatible YouTube extraction path exists, replace the + * body of getUrl() with that implementation. + */ +actual open class YoutubeExtractor actual constructor() : ExtractorApi() { + + actual override val mainUrl = "https://www.youtube.com" + actual override val name = "YouTube" + actual override val requiresReferer = false + + actual override suspend fun getUrl( + url: String, + referer: String?, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit, + ) { + // No-op on web target: NewPipeExtractor is unavailable here. + } +} diff --git a/library/src/webMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.web.kt b/library/src/webMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.web.kt new file mode 100644 index 00000000000..f108bf7fbe5 --- /dev/null +++ b/library/src/webMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.web.kt @@ -0,0 +1,32 @@ +package com.lagradost.cloudstream3.mvvm + +actual fun platformThrowAbleToResource(throwable: Throwable): Resource { + val message = throwable.message.orEmpty() + return when { + message.contains("timeout", ignoreCase = true) -> { + Resource.Failure( + true, + "Connection Timeout\nPlease try again later." + ) + } + + message.contains("NetworkError", ignoreCase = true) || + message.contains("Failed to fetch", ignoreCase = true) || + message.contains("ERR_NAME_NOT_RESOLVED", ignoreCase = true) -> { + Resource.Failure( + true, + "Cannot connect to server, try again later.\n${throwable.message}" + ) + } + + message.contains("SSL", ignoreCase = true) || + message.contains("certificate", ignoreCase = true) -> { + Resource.Failure( + true, + (throwable.message ?: "SSL error") + "\nTry a VPN or DNS." + ) + } + + else -> safeFail(throwable) + } +} diff --git a/library/src/webMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.web.kt b/library/src/webMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.web.kt new file mode 100644 index 00000000000..3ea59f6cc02 --- /dev/null +++ b/library/src/webMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.web.kt @@ -0,0 +1,14 @@ +package com.lagradost.cloudstream3.utils + +import androidx.annotation.AnyThread +import androidx.annotation.MainThread +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +actual val workerDispatcher: CoroutineDispatcher = Dispatchers.Default +internal actual annotation class WorkerThread() + +@AnyThread +actual fun runOnMainThreadNative(@MainThread work: () -> Unit) { + work.invoke() +} diff --git a/library/src/webTest/kotlin/com/lagradost/cloudstream3/utils/Ignore.web.kt b/library/src/webTest/kotlin/com/lagradost/cloudstream3/utils/Ignore.web.kt new file mode 100644 index 00000000000..0381a19448a --- /dev/null +++ b/library/src/webTest/kotlin/com/lagradost/cloudstream3/utils/Ignore.web.kt @@ -0,0 +1,5 @@ +package com.lagradost.cloudstream3.utils + +import kotlin.test.Ignore + +actual typealias IgnoreOnWeb = Ignore From 12442bfafa003f4c49237af981a53b12fb8742c6 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Wed, 15 Jul 2026 15:24:17 -0700 Subject: [PATCH 2/2] Add comment --- library/src/webMain/kotlin/com/lagradost/api/Log.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/src/webMain/kotlin/com/lagradost/api/Log.kt b/library/src/webMain/kotlin/com/lagradost/api/Log.kt index 8062526d417..be185f0ca65 100644 --- a/library/src/webMain/kotlin/com/lagradost/api/Log.kt +++ b/library/src/webMain/kotlin/com/lagradost/api/Log.kt @@ -2,6 +2,8 @@ package com.lagradost.api actual object Log { actual fun d(tag: String, message: String) { + // There is no console.debug in Kotlin/JS (Yet) + // We will switch this when it is added. console.log("[$tag] $message") }