Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

fix(stalker): stop retrying sibling endpoints after discovery

David Nashash36ca7bf9382b
diff --git a/data/src/main/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiService.kt b/data/src/main/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiService.kt
index a2aa902b..aba27657 100644
--- a/data/src/main/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiService.kt
+++ b/data/src/main/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiService.kt
@@ -86,6 +86,7 @@ class OkHttpStalkerApiService @Inject constructor(
url = loadUrl,
profile = attemptProfile,
referer = referer,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "stb",
"action" to "handshake",
@@ -115,7 +116,8 @@ class OkHttpStalkerApiService @Inject constructor(
url = loadUrl,
profile = attemptProfile,
referer = referer,
- token = token
+ token = token,
+ allowAlternateEndpointRetry = true
)
}.getOrElse { error ->
lastError = error
@@ -137,6 +139,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "stb",
"action" to "get_localization",
@@ -153,6 +156,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = buildProfileQuery(attemptProfile)
)
}.getOrElse { error ->
@@ -179,6 +183,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "account_info",
"action" to "get_main_info",
@@ -198,6 +203,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "stb",
"action" to "get_localization",
@@ -215,6 +221,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "stb",
"action" to "get_modules",
@@ -239,6 +246,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = attemptProfile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = true,
query = mapOf(
"type" to "stb",
"action" to "get_events",
@@ -911,11 +919,11 @@ class OkHttpStalkerApiService @Inject constructor(
referer: String,
query: Map<String, String>,
token: String? = null,
+ allowAlternateEndpointRetry: Boolean = false,
method: String = "GET",
body: String? = null
): JsonElement = withContext(Dispatchers.IO) {
val action = query["action"]
- val canRetryAlternateEndpoint = !token.isNullOrBlank()
val fullUrl = buildUrl(url, query)
val requestBuilder = Request.Builder()
.url(fullUrl)
@@ -935,7 +943,7 @@ class OkHttpStalkerApiService @Inject constructor(
runCatching {
executeJsonRequest(request, action)
}.recoverCatching { error ->
- if (!canRetryAlternateEndpoint) throw error
+ if (!allowAlternateEndpointRetry) throw error
val alternateUrl = siblingLoadUrl(url)
?.takeIf { it != url }
?: throw error
@@ -1047,23 +1055,7 @@ class OkHttpStalkerApiService @Inject constructor(
.get()
.build()
- runCatching {
- executeStreamingRequest(request, action, onItem)
- }.recoverCatching { error ->
- val alternateUrl = siblingLoadUrl(url)
- ?.takeIf { it != url }
- ?: throw error
- Log.w(
- TAG,
- "Retrying streamed Stalker ${action.orEmpty()} via alternate endpoint $alternateUrl after ${error.message}"
- )
- val alternateRequest = request.newBuilder()
- .url(buildUrl(alternateUrl, query))
- .header("Referer", StalkerUrlFactory.portalReferer(alternateUrl))
- .header("Cookie", buildCookieHeader(buildUrl(alternateUrl, query), profile))
- .build()
- executeStreamingRequest(alternateRequest, action, onItem)
- }.getOrElse { throw it }
+ executeStreamingRequest(request, action, onItem)
}
private suspend fun executeStreamingRequest(
@@ -1195,23 +1187,7 @@ class OkHttpStalkerApiService @Inject constructor(
.get()
.build()
- runCatching {
- executeStreamingPrograms(request, action, channelIdOverride, onProgram)
- }.recoverCatching { error ->
- val alternateUrl = siblingLoadUrl(url)
- ?.takeIf { it != url }
- ?: throw error
- Log.w(
- TAG,
- "Retrying streamed Stalker EPG ${action.orEmpty()} via alternate endpoint $alternateUrl after ${error.message}"
- )
- val alternateRequest = request.newBuilder()
- .url(buildUrl(alternateUrl, query))
- .header("Referer", StalkerUrlFactory.portalReferer(alternateUrl))
- .header("Cookie", buildCookieHeader(buildUrl(alternateUrl, query), profile))
- .build()
- executeStreamingPrograms(alternateRequest, action, channelIdOverride, onProgram)
- }.getOrElse { throw it }
+ executeStreamingPrograms(request, action, channelIdOverride, onProgram)
}
private suspend fun executeStreamingPrograms(
@@ -1480,7 +1456,8 @@ class OkHttpStalkerApiService @Inject constructor(
url: String,
profile: StalkerDeviceProfile,
referer: String,
- token: String
+ token: String,
+ allowAlternateEndpointRetry: Boolean = false
): JsonElement {
val formBody = listOf(
"login" to profile.username,
@@ -1497,6 +1474,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = profile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = allowAlternateEndpointRetry,
query = query,
method = "POST",
body = formBody
@@ -1507,6 +1485,7 @@ class OkHttpStalkerApiService @Inject constructor(
profile = profile,
referer = referer,
token = token,
+ allowAlternateEndpointRetry = allowAlternateEndpointRetry,
query = query + mapOf(
"login" to profile.username,
"password" to profile.password
diff --git a/data/src/test/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiServiceTest.kt b/data/src/test/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiServiceTest.kt
index b87e7bf9..a04454c2 100644
--- a/data/src/test/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiServiceTest.kt
+++ b/data/src/test/java/com/streamvault/data/remote/stalker/OkHttpStalkerApiServiceTest.kt
@@ -579,7 +579,7 @@ class OkHttpStalkerApiServiceTest {
}
@Test
- fun getLiveCategories_retries_alternate_endpoint_for_authenticated_requests() = runTest {
+ fun getLiveCategories_stays_on_selected_endpoint_after_authentication() = runTest {
val requestedUrls = mutableListOf<String>()
val service = OkHttpStalkerApiService(
okHttpClient = OkHttpClient.Builder()
@@ -622,12 +622,66 @@ class OkHttpStalkerApiServiceTest {
)
)
- assertThat(result).isInstanceOf(Result.Success::class.java)
- val success = result as Result.Success
- assertThat(success.data.map { it.name }).containsExactly("News")
- assertThat(requestedUrls).containsAtLeast(
- "https://portal.example.com/server/load.php?type=itv&action=get_genres&JsHttpRequest=1-xml",
- "https://portal.example.com/portal.php?type=itv&action=get_genres&JsHttpRequest=1-xml"
+ assertThat(result).isInstanceOf(Result.Error::class.java)
+ val error = result as Result.Error
+ assertThat(error.message).contains("not found")
+ assertThat(requestedUrls).containsExactly(
+ "https://portal.example.com/server/load.php?type=itv&action=get_genres&JsHttpRequest=1-xml"
+ )
+ }
+
+ @Test
+ fun streamLiveStreams_stays_on_selected_endpoint_after_authentication() = runTest {
+ val requestedUrls = mutableListOf<String>()
+ val streamed = mutableListOf<StalkerItemRecord>()
+ val service = OkHttpStalkerApiService(
+ okHttpClient = OkHttpClient.Builder()
+ .addInterceptor(Interceptor { chain ->
+ val request = chain.request()
+ requestedUrls += request.url.toString()
+ val response = when (request.url.encodedPath) {
+ "/server/load.php" -> throw java.io.IOException("stream endpoint failed")
+ "/portal.php" -> Response.Builder()
+ .request(request)
+ .protocol(Protocol.HTTP_1_1)
+ .code(200)
+ .message("OK")
+ .body(
+ """{"js":{"data":[{"id":"100","name":"News","tv_genre_id":"10","cmd":"ffmpeg http://example.com/live.ts"}]}}"""
+ .toResponseBody("application/json".toMediaType())
+ )
+ .build()
+ else -> error("Unexpected path ${request.url.encodedPath}")
+ }
+ response
+ })
+ .build(),
+ json = Json { ignoreUnknownKeys = true }
+ )
+
+ val result = service.streamLiveStreams(
+ session = StalkerSession(
+ loadUrl = "https://portal.example.com/server/load.php",
+ portalReferer = "https://portal.example.com/c/",
+ token = "token-123"
+ ),
+ profile = buildStalkerDeviceProfile(
+ portalUrl = "https://portal.example.com/c",
+ macAddress = "00:1A:79:12:34:56",
+ deviceProfile = "MAG250",
+ timezone = "UTC",
+ locale = "en"
+ )
+ ) { item ->
+ streamed += item
+ }
+
+ assertThat(result).isInstanceOf(Result.Error::class.java)
+ val error = result as Result.Error
+ assertThat(error.message).contains("stream endpoint failed")
+ assertThat(streamed).isEmpty()
+ assertThat(requestedUrls).containsExactly(
+ "https://portal.example.com/server/load.php?type=itv&action=get_all_channels&JsHttpRequest=1-xml"
)
}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 2d10949f..1b22d865 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -2,6 +2,12 @@
All notable product changes are recorded in this document.
+## [1.0.15] - 2026-06-13
+
+### Fixed
+
+- Fixed Stalker endpoint handling so authenticated requests stay on the discovered API endpoint instead of retrying the sibling `portal.php` or `server/load.php` path automatically.
+
## [1.0.14] - 2026-06-06
### Added