From 2ed1dd5d4fbadac7f6945307a031f19aed1e6bf5 Mon Sep 17 00:00:00 2001 From: antonydp <38143733+antonydp@users.noreply.github.com> Date: Thu, 6 Oct 2022 19:29:17 +0200 Subject: [PATCH] StarLiveProvider --- StarLiveProvider/build.gradle.kts | 25 ++++ StarLiveProvider/src/main/AndroidManifest.xml | 2 + .../kotlin/com/lagradost/StarLiveProvider.kt | 136 ++++++++++++++++++ .../com/lagradost/StarLiveProviderPlugin.kt | 14 ++ 4 files changed, 177 insertions(+) create mode 100644 StarLiveProvider/build.gradle.kts create mode 100644 StarLiveProvider/src/main/AndroidManifest.xml create mode 100644 StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProvider.kt create mode 100644 StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProviderPlugin.kt diff --git a/StarLiveProvider/build.gradle.kts b/StarLiveProvider/build.gradle.kts new file mode 100644 index 0000000..e02ba85 --- /dev/null +++ b/StarLiveProvider/build.gradle.kts @@ -0,0 +1,25 @@ +// use an integer for version numbers +version = 1 + + +cloudstream { + language = "it" + // All of these properties are optional, you can safely remove them + + // description = "Lorem Ipsum" + authors = listOf("Adippe") + + /** + * Status int as the following: + * 0: Down + * 1: Ok + * 2: Slow + * 3: Beta only + * */ + status = 1 // will be 3 if unspecified + tvTypes = listOf( + "Live", + ) + + iconUrl = "https://www.google.com/s2/favicons?domain=starlive.xyz&sz=%size%" +} \ No newline at end of file diff --git a/StarLiveProvider/src/main/AndroidManifest.xml b/StarLiveProvider/src/main/AndroidManifest.xml new file mode 100644 index 0000000..29aec9d --- /dev/null +++ b/StarLiveProvider/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProvider.kt b/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProvider.kt new file mode 100644 index 0000000..3bb2d35 --- /dev/null +++ b/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProvider.kt @@ -0,0 +1,136 @@ +package com.lagradost + +import com.fasterxml.jackson.annotation.JsonProperty +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.utils.* +import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import org.jsoup.nodes.Element + + +class StarLiveProvider : MainAPI() { + override var lang = "it" + override var mainUrl = "https://starlive.xyz" + override var name = "StarLive" + override val hasMainPage = true + override val hasChromecastSupport = true + override val supportedTypes = setOf( + TvType.Live, + ) + + override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { + val document = app.get(mainUrl).document + val sections = document.select("div.panel") + if (sections.isEmpty()) throw ErrorLoadingException() + + return HomePageResponse(sections.map { sport -> + val dayMatch = sport.previousElementSiblings().toList().first { it.`is`("h3") }.text() + val categoryName = sport.selectFirst("h4")?.text()?:"Other" + val showsList = sport.select("tr").takeWhile { it.text().contains("Player").not() }.filter { it.hasAttr("class")}.drop(1) + val shows = showsList.groupBy { it.text().substringBeforeLast(" ")}.map { matchs -> + val posterUrl = fixUrl(sport.selectFirst("h4")?.attr("style")?.substringAfter("(")?.substringBefore(")")?:"") + val href = mutableListOf() + val hasDate = matchs.key.contains(":") + val matchName = if (hasDate){matchs.key.substringAfter(" ")} else{matchs.key} + + matchs.value.map { match -> + val linkUrl = fixUrl(match.selectFirst("a")?.attr("href") ?: "") + val lang = match.attr("class") + href.add( "{\"link\": \"$linkUrl\", \"lang\":\"$lang\", \"name\": \"$matchName\"}") + } + + val date = if (hasDate){dayMatch + " - " + matchs.key.substringBefore(" ")} else{dayMatch} + + LiveSearchResponse( + matchName, + "{\"linkData\": $href , \"matchData\":{\"time\": \"$date\", \"poster\":\"$posterUrl\"}}", + this@StarliveProvider.name, + TvType.Live, + posterUrl, + ) + } + HomePageList( + categoryName, + shows + ) + + }) + + } + + private data class LinkParser( + @JsonProperty("link") val link: String, + @JsonProperty("lang") val language: String, + @JsonProperty("name") val name: String + ) + private data class MatchDataParser( + @JsonProperty("time") val time: String, + @JsonProperty("poster") val poster: String + ) + private data class MatchParser( + @JsonProperty("linkData") val linkData: List, + @JsonProperty("matchData") val MatchData: MatchDataParser + ) + + override suspend fun load(url: String): LoadResponse { + val matchdata = tryParseJson(url) + val poster = matchdata?.MatchData?.poster + val Matchstart = matchdata?.MatchData?.time + return LiveStreamLoadResponse( + dataUrl = url, + url = matchdata?.linkData?.firstOrNull()?.link?:mainUrl, + name = matchdata?.linkData?.firstOrNull()?.name?:mainUrl, + posterUrl = poster, + plot = Matchstart, + apiName = this@StarliveProvider.name + ) + + + } + + + + + private suspend fun extractVideoLinks( + data: LinkParser, + callback: (ExtractorLink) -> Unit + ) { + val linktoStream = "https:"+app.get(data.link).document.selectFirst("iframe")!!.attr("src") + + val referrerLink = if(linktoStream.contains("starlive")){ + app.get(linktoStream, referer = data.link).document.selectFirst("iframe")?.attr("src")?:"" + } + else{ + linktoStream + } + val packed = when(linktoStream.contains("starlive")){ + true -> app.get(referrerLink, referer = linktoStream).document.select("script")[6].childNodes()[0].toString() + false -> app.get(linktoStream, referer = data.link).document.select("script").select("script")[6].childNodes()[0].toString() + } + val streamurl = getAndUnpack(packed).substringAfter("var src=\"").substringBefore("\"") + callback( + ExtractorLink( + source = this.name, + name = data.name + " - " + data.language, + url = streamurl, + quality = 0, + referer = referrerLink, + isM3u8 = true + ) + ) + + } + + + override suspend fun loadLinks( + data: String, + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + tryParseJson(data)?.linkData?.map {link-> + extractVideoLinks(link, callback) + } + + return true + } +} \ No newline at end of file diff --git a/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProviderPlugin.kt b/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProviderPlugin.kt new file mode 100644 index 0000000..60d6bee --- /dev/null +++ b/StarLiveProvider/src/main/kotlin/com/lagradost/StarLiveProviderPlugin.kt @@ -0,0 +1,14 @@ + +package com.lagradost + +import com.lagradost.cloudstream3.plugins.CloudstreamPlugin +import com.lagradost.cloudstream3.plugins.Plugin +import android.content.Context + +@CloudstreamPlugin +class StarLiveProviderPlugin: Plugin() { + override fun load(context: Context) { + // All providers should be added in this manner. Please don't edit the providers list directly. + registerMainAPI(StarLiveProvider()) + } +} \ No newline at end of file