This commit is contained in:
Olivia 2024-01-25 23:09:52 +07:00
parent 9130622d4c
commit c4de07abb3
2 changed files with 54 additions and 49 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 22 version = 23
cloudstream { cloudstream {

View file

@ -4,7 +4,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils import com.lagradost.cloudstream3.utils.AppUtils
import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper import com.lagradost.cloudstream3.utils.Qualities
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.net.URI import java.net.URI
@ -14,22 +14,22 @@ class TimefourTv : MainAPI() {
override val hasDownloadSupport = false override val hasDownloadSupport = false
override val hasMainPage = true override val hasMainPage = true
override val supportedTypes = setOf( override val supportedTypes = setOf(
TvType.Live TvType.Live
) )
private val homePoster = private val homePoster =
"https://cdn.discordapp.com/attachments/1109266606292488297/1193060449193840681/Screenshot_2024-01-06_at_12-14-16_Logo_Maker_Used_By_2.3_Million_Startups.png" "https://cdn.discordapp.com/attachments/1109266606292488297/1193060449193840681/Screenshot_2024-01-06_at_12-14-16_Logo_Maker_Used_By_2.3_Million_Startups.png"
private val detailPoster = private val detailPoster =
"https://cdn.discordapp.com/attachments/1109266606292488297/1193060448929595454/Screenshot_2024-01-06_at_12-13-02_Logo_Maker_Used_By_2.3_Million_Startups.png" "https://cdn.discordapp.com/attachments/1109266606292488297/1193060448929595454/Screenshot_2024-01-06_at_12-13-02_Logo_Maker_Used_By_2.3_Million_Startups.png"
override val mainPage = mainPageOf( override val mainPage = mainPageOf(
"$mainUrl/24-7-channels.php" to "24/7 Channels", "$mainUrl/24-7-channels.php" to "24/7 Channels",
"$mainUrl/schedule/schedule-generated.json" to "Schedule Channels" "$mainUrl/schedule/schedule-generated.json" to "Schedule Channels"
) )
override suspend fun getMainPage( override suspend fun getMainPage(
page: Int, page: Int,
request: MainPageRequest request: MainPageRequest
): HomePageResponse { ): HomePageResponse {
val items = mutableListOf<HomePageList>() val items = mutableListOf<HomePageList>()
if (request.name == "24/7 Channels") { if (request.name == "24/7 Channels") {
@ -46,11 +46,11 @@ class TimefourTv : MainAPI() {
val header = tag.key val header = tag.key
val channels = tag.value.mapNotNull { val channels = tag.value.mapNotNull {
LiveSearchResponse( LiveSearchResponse(
it.key, it.key,
Item(it.key, items = it.value.toJson()).toJson(), Item(it.key, items = it.value.toJson()).toJson(),
this@TimefourTv.name, this@TimefourTv.name,
TvType.Live, TvType.Live,
posterUrl = homePoster, posterUrl = homePoster,
) )
} }
if (channels.isNotEmpty()) items.add(HomePageList(header, channels, true)) if (channels.isNotEmpty()) items.add(HomePageList(header, channels, true))
@ -64,11 +64,11 @@ class TimefourTv : MainAPI() {
val title = this.select("strong").text() val title = this.select("strong").text()
val href = fixUrl(this.select("a").attr("href")) val href = fixUrl(this.select("a").attr("href"))
return LiveSearchResponse( return LiveSearchResponse(
title, title,
Item(title, href).toJson(), Item(title, href).toJson(),
this@TimefourTv.name, this@TimefourTv.name,
TvType.Live, TvType.Live,
posterUrl = homePoster, posterUrl = homePoster,
) )
} }
@ -88,18 +88,18 @@ class TimefourTv : MainAPI() {
val items = AppUtils.parseJson<ArrayList<Items>>(data.items) val items = AppUtils.parseJson<ArrayList<Items>>(data.items)
items.mapNotNull { eps -> items.mapNotNull { eps ->
Episode( Episode(
data = eps.channels?.toJson() ?: return@mapNotNull null, data = eps.channels?.toJson() ?: return@mapNotNull null,
name = "${eps.event}${eps.time}", name = "${eps.event}${eps.time}",
description = eps.channels.map { it.channel_name }.joinToString(""), description = eps.channels.map { it.channel_name }.joinToString(""),
posterUrl = detailPoster, posterUrl = detailPoster,
) )
} }
} }
return newTvSeriesLoadResponse( return newTvSeriesLoadResponse(
data.title ?: "", data.title ?: "",
url, url,
TvType.TvSeries, TvType.TvSeries,
episodes = episodes episodes = episodes
) { ) {
posterUrl = homePoster posterUrl = homePoster
} }
@ -107,29 +107,34 @@ class TimefourTv : MainAPI() {
} }
override suspend fun loadLinks( override suspend fun loadLinks(
data: String, data: String,
isCasting: Boolean, isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
val json = AppUtils.parseJson<ArrayList<Channels>>(data) val json = AppUtils.parseJson<ArrayList<Channels>>(data)
json.apmap { json.apmap {
val iframe = app.get( val iframe = app.get(
fixChannelUrl( fixChannelUrl(
it.channel_id ?: return@apmap it.channel_id ?: return@apmap
) )
).document.selectFirst("iframe#thatframe")?.attr("src") ).document.selectFirst("iframe#thatframe")?.attr("src")
?: throw ErrorLoadingException("No Iframe Found") ?: throw ErrorLoadingException("No Iframe Found")
val host = getBaseUrl(iframe) val host = getBaseUrl(iframe)
val video = extractVideo(iframe) val video = extractVideo(iframe)
M3u8Helper.generateM3u8( callback.invoke(
ExtractorLink(
this.name,
it.channel_name ?: return@apmap, it.channel_name ?: return@apmap,
video ?: return@apmap, video ?: return@apmap,
"$host/", "$host/",
).forEach(callback) Qualities.Unknown.value,
isM3u8 = true,
)
)
} }
return true return true
@ -138,13 +143,13 @@ class TimefourTv : MainAPI() {
private suspend fun extractVideo(url: String): String? { private suspend fun extractVideo(url: String): String? {
val res = app.get(url, referer = mainUrl) val res = app.get(url, referer = mainUrl)
return Regex("""source:['"](\S+.m3u8)['"],""").find(res.text)?.groupValues?.getOrNull( return Regex("""source:['"](\S+.m3u8)['"],""").find(res.text)?.groupValues?.getOrNull(
1 1
) ?: run { ) ?: run {
val scriptData = val scriptData =
res.document.selectFirst("div#player")?.nextElementSibling()?.data() res.document.selectFirst("div#player")?.nextElementSibling()?.data()
?.substringAfterLast("return(")?.substringBefore(".join") ?.substringAfterLast("return(")?.substringBefore(".join")
scriptData?.removeSurrounding("[", "]")?.replace("\"", "")?.split(",") scriptData?.removeSurrounding("[", "]")?.replace("\"", "")?.split(",")
?.joinToString("") ?.joinToString("")
} }
} }
@ -163,20 +168,20 @@ class TimefourTv : MainAPI() {
} }
data class Item( data class Item(
val title: String? = null, val title: String? = null,
val url: String? = null, val url: String? = null,
val items: String? = null, val items: String? = null,
) )
data class Items( data class Items(
val time: String? = null, val time: String? = null,
val event: String? = null, val event: String? = null,
val channels: ArrayList<Channels>? = arrayListOf(), val channels: ArrayList<Channels>? = arrayListOf(),
) )
data class Channels( data class Channels(
val channel_name: String? = null, val channel_name: String? = null,
val channel_id: String? = null, val channel_id: String? = null,
) )
} }