Skip to content

Commit

Permalink
Fixed carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
doGior committed Nov 6, 2024
1 parent 2e6b150 commit 9fc5151
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions CanaliTV/src/main/kotlin/com/lagradost/CanaliTV.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.lagradost

import com.lagradost.api.Log
import android.content.Context
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.CommonActivity.activity
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink
Expand All @@ -18,6 +19,8 @@ class CanaliTV : MainAPI() {
override var sequentialMainPage = true
override val supportedTypes = setOf(TvType.Live)
private var playlist: Playlist? = null
private val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE)


private suspend fun getTVChannels(): List<TVChannel> {
if (playlist == null) {
Expand All @@ -33,7 +36,16 @@ class CanaliTV : MainAPI() {
): HomePageResponse {
val data = getTVChannels()
val title = "Canali TV"
val show = data.map { it.toSearchResponse(apiName = this@CanaliTV.name) }
val show = data.map {
sharedPref?.edit()?.apply {
putString(it.url, it.toJson())
apply()
}
it.toSearchResponse(apiName = this@CanaliTV.name)
}



return newHomePageResponse(
HomePageList(
title,
Expand All @@ -57,14 +69,19 @@ class CanaliTV : MainAPI() {
}

override suspend fun load(url: String): LoadResponse {
val data = parseJson<Data>(url)
Log.d("LOAD", "Data: $data")
val tvChannel = sharedPref?.getString(url, null)?.let { parseJson<TVChannel>(it) }
?: throw ErrorLoadingException("Error loading channel from cache")

val streamUrl = tvChannel.url.toString()
val channelName = tvChannel.title ?: tvChannel.attributes["tvg-id"].toString()
val posterUrl = tvChannel.attributes["tvg-logo"].toString()

return LiveStreamLoadResponse(
data.title,
data.url,
channelName,
streamUrl,
this.name,
url,
data.poster,
posterUrl
)
}

Expand All @@ -75,12 +92,11 @@ class CanaliTV : MainAPI() {
callback: (ExtractorLink) -> Unit
): Boolean {

val loadData = parseJson<Data>(data)
callback.invoke(
ExtractorLink(
this.name,
loadData.title,
loadData.url,
"Free-TV",
"Free-TV",
data,
"",
Qualities.Unknown.value,
isM3u8 = true
Expand All @@ -90,13 +106,6 @@ class CanaliTV : MainAPI() {
}
}

data class Data(
val url: String,
val title: String,
val poster: String,
val nation: String
)

data class Playlist(
val items: List<TVChannel> = emptyList(),
)
Expand All @@ -114,7 +123,7 @@ data class TVChannel(
val posterUrl = attributes["tvg-logo"].toString()
return LiveSearchResponse(
channelName,
Data(streamUrl, channelName, posterUrl, "").toJson(),
streamUrl,
apiName,
TvType.Live,
posterUrl,
Expand Down

0 comments on commit 9fc5151

Please sign in to comment.