2022-09-26 17:07:39 +00:00
|
|
|
package com.hexated
|
|
|
|
|
|
|
|
import com.lagradost.cloudstream3.*
|
2024-01-06 06:00:38 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
2022-09-26 17:07:39 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
2022-12-30 12:55:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.M3u8Helper
|
2022-09-26 17:07:39 +00:00
|
|
|
import org.jsoup.nodes.Element
|
2024-01-06 06:00:38 +00:00
|
|
|
import java.net.URI
|
2022-09-26 17:07:39 +00:00
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
class TimefourTv : MainAPI() {
|
|
|
|
override var mainUrl = "https://dlhd.sx"
|
2022-09-26 17:07:39 +00:00
|
|
|
override var name = "Time4tv"
|
|
|
|
override val hasDownloadSupport = false
|
|
|
|
override val hasMainPage = true
|
|
|
|
override val supportedTypes = setOf(
|
2024-01-06 06:00:38 +00:00
|
|
|
TvType.Live
|
2022-09-26 17:07:39 +00:00
|
|
|
)
|
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
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"
|
|
|
|
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"
|
|
|
|
|
2022-09-26 17:07:39 +00:00
|
|
|
override val mainPage = mainPageOf(
|
2024-01-06 06:00:38 +00:00
|
|
|
"$mainUrl/24-7-channels.php" to "24/7 Channels",
|
|
|
|
"$mainUrl/schedule/schedule-generated.json" to "Schedule Channels"
|
2022-09-26 17:07:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
override suspend fun getMainPage(
|
2024-01-06 06:00:38 +00:00
|
|
|
page: Int,
|
|
|
|
request: MainPageRequest
|
2022-09-26 17:07:39 +00:00
|
|
|
): HomePageResponse {
|
2022-10-04 12:51:29 +00:00
|
|
|
val items = mutableListOf<HomePageList>()
|
2024-01-06 06:00:38 +00:00
|
|
|
if (request.name == "24/7 Channels") {
|
|
|
|
val req = app.get(request.data)
|
|
|
|
mainUrl = getBaseUrl(req.url)
|
|
|
|
val res = req.document
|
|
|
|
val channels = res.select("div.grid-container div.grid-item").mapNotNull {
|
|
|
|
it.toSearchResponse()
|
2022-10-04 12:51:29 +00:00
|
|
|
}
|
2024-01-06 06:00:38 +00:00
|
|
|
if (channels.isNotEmpty()) items.add(HomePageList(request.name, channels, true))
|
|
|
|
} else {
|
|
|
|
val res = app.get(request.data).parsedSafe<Map<String, Map<String, ArrayList<Items>>>>()
|
|
|
|
res?.forEach { tag ->
|
|
|
|
val header = tag.key
|
|
|
|
val channels = tag.value.mapNotNull {
|
|
|
|
LiveSearchResponse(
|
|
|
|
it.key,
|
|
|
|
Item(it.key, items = it.value.toJson()).toJson(),
|
|
|
|
this@TimefourTv.name,
|
|
|
|
TvType.Live,
|
|
|
|
posterUrl = homePoster,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if (channels.isNotEmpty()) items.add(HomePageList(header, channels, true))
|
2022-11-06 05:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
return newHomePageResponse(items, false)
|
2022-09-26 17:07:39 +00:00
|
|
|
}
|
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
private fun Element.toSearchResponse(): LiveSearchResponse {
|
|
|
|
val title = this.select("strong").text()
|
|
|
|
val href = fixUrl(this.select("a").attr("href"))
|
2023-01-01 14:03:35 +00:00
|
|
|
return LiveSearchResponse(
|
2024-01-06 06:00:38 +00:00
|
|
|
title,
|
|
|
|
Item(title, href).toJson(),
|
|
|
|
this@TimefourTv.name,
|
|
|
|
TvType.Live,
|
|
|
|
posterUrl = homePoster,
|
2023-01-01 14:03:35 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-09-10 12:56:48 +00:00
|
|
|
override suspend fun search(query: String): List<SearchResponse> {
|
2024-01-06 06:00:38 +00:00
|
|
|
val document = app.get("$mainUrl/24-7-channels.php").document
|
2023-09-10 12:56:48 +00:00
|
|
|
return document.select("div.grid-container div.grid-item:contains($query)").mapNotNull {
|
2024-01-06 06:00:38 +00:00
|
|
|
it.toSearchResponse()
|
2023-09-10 12:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-26 17:07:39 +00:00
|
|
|
|
2022-11-06 05:45:43 +00:00
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
override suspend fun load(url: String): LoadResponse {
|
|
|
|
val data = AppUtils.parseJson<Item>(url)
|
|
|
|
val episodes = if (data.items.isNullOrEmpty()) {
|
|
|
|
listOf(Episode(arrayListOf(Channels(data.title, data.url)).toJson()))
|
|
|
|
} else {
|
|
|
|
val items = AppUtils.parseJson<ArrayList<Items>>(data.items)
|
2024-01-07 11:09:14 +00:00
|
|
|
items.mapNotNull { eps ->
|
2024-01-06 06:00:38 +00:00
|
|
|
Episode(
|
2024-01-07 11:09:14 +00:00
|
|
|
data = eps.channels?.toJson() ?: return@mapNotNull null,
|
|
|
|
name = "${eps.event} • ${eps.time}",
|
|
|
|
description = eps.channels.map { it.channel_name }.joinToString(" • "),
|
2024-01-06 06:00:38 +00:00
|
|
|
posterUrl = detailPoster,
|
|
|
|
)
|
2023-07-29 19:37:51 +00:00
|
|
|
}
|
2022-09-26 17:07:39 +00:00
|
|
|
}
|
2024-01-06 06:00:38 +00:00
|
|
|
return newTvSeriesLoadResponse(
|
|
|
|
data.title ?: "",
|
|
|
|
url,
|
|
|
|
TvType.TvSeries,
|
|
|
|
episodes = episodes
|
|
|
|
) {
|
|
|
|
posterUrl = homePoster
|
|
|
|
}
|
|
|
|
|
2022-09-26 17:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun loadLinks(
|
2024-01-06 06:00:38 +00:00
|
|
|
data: String,
|
|
|
|
isCasting: Boolean,
|
|
|
|
subtitleCallback: (SubtitleFile) -> Unit,
|
|
|
|
callback: (ExtractorLink) -> Unit
|
2022-09-26 17:07:39 +00:00
|
|
|
): Boolean {
|
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
val json = AppUtils.parseJson<ArrayList<Channels>>(data)
|
|
|
|
|
|
|
|
json.apmap {
|
|
|
|
val iframe = app.get(
|
|
|
|
fixChannelUrl(
|
|
|
|
it.channel_id ?: return@apmap
|
|
|
|
)
|
|
|
|
).document.selectFirst("iframe#thatframe")?.attr("src")
|
|
|
|
?: throw ErrorLoadingException("No Iframe Found")
|
|
|
|
val host = getBaseUrl(iframe)
|
|
|
|
val video = extractVideo(iframe)
|
|
|
|
|
2022-12-30 12:55:25 +00:00
|
|
|
M3u8Helper.generateM3u8(
|
2024-01-06 06:00:38 +00:00
|
|
|
it.channel_name ?: return@apmap,
|
|
|
|
video ?: return@apmap,
|
|
|
|
"$host/",
|
2022-12-30 12:55:25 +00:00
|
|
|
).forEach(callback)
|
2022-09-26 17:07:39 +00:00
|
|
|
}
|
2024-01-06 06:00:38 +00:00
|
|
|
|
2022-09-26 17:07:39 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-06 06:00:38 +00:00
|
|
|
private suspend fun extractVideo(url: String): String? {
|
|
|
|
val res = app.get(url, referer = mainUrl)
|
|
|
|
return Regex("""source:['"](\S+.m3u8)['"],""").find(res.text)?.groupValues?.getOrNull(
|
|
|
|
1
|
|
|
|
) ?: run {
|
|
|
|
val scriptData =
|
|
|
|
res.document.selectFirst("div#player")?.nextElementSibling()?.data()
|
|
|
|
?.substringAfterLast("return(")?.substringBefore(".join")
|
|
|
|
scriptData?.removeSurrounding("[", "]")?.replace("\"", "")?.split(",")
|
|
|
|
?.joinToString("")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun fixChannelUrl(url: String): String {
|
|
|
|
return if (url.startsWith(mainUrl)) {
|
|
|
|
url
|
|
|
|
} else {
|
|
|
|
"$mainUrl/stream/stream-$url.php"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getBaseUrl(url: String): String {
|
|
|
|
return URI(url).let {
|
|
|
|
"${it.scheme}://${it.host}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data class Item(
|
|
|
|
val title: String? = null,
|
|
|
|
val url: String? = null,
|
|
|
|
val items: String? = null,
|
|
|
|
)
|
|
|
|
|
|
|
|
data class Items(
|
|
|
|
val time: String? = null,
|
|
|
|
val event: String? = null,
|
|
|
|
val channels: ArrayList<Channels>? = arrayListOf(),
|
|
|
|
)
|
|
|
|
|
|
|
|
data class Channels(
|
|
|
|
val channel_name: String? = null,
|
|
|
|
val channel_id: String? = null,
|
|
|
|
)
|
|
|
|
|
2022-09-26 17:07:39 +00:00
|
|
|
}
|