higotv: Fix episodes

This commit is contained in:
CakesTwix 2024-02-17 12:08:51 +02:00
parent 533133df10
commit 14f7218c5b
Signed by: CakesTwix
GPG key ID: 7B11051D5CE19825
2 changed files with 49 additions and 58 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 2 version = 3
dependencies{ dependencies{
implementation("com.google.code.gson:gson:2.9.0") implementation("com.google.code.gson:gson:2.9.0")

View file

@ -1,6 +1,6 @@
package com.lagradost package com.lagradost
import com.google.gson.Gson import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.lagradost.cloudstream3.AnimeSearchResponse import com.lagradost.cloudstream3.AnimeSearchResponse
import com.lagradost.cloudstream3.DubStatus import com.lagradost.cloudstream3.DubStatus
@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.models.PlayerJson import com.lagradost.models.PlayerJson
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
class HigoTVProvider : MainAPI() { class HigoTVProvider : MainAPI() {
// Basic Info // Basic Info
@ -63,6 +64,10 @@ class HigoTVProvider : MainAPI() {
private val TAG = "$name-Debug" private val TAG = "$name-Debug"
private val gson = GsonBuilder()
.setLenient()
.create()
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val document = app.get("$mainUrl/${request.data}").document val document = app.get("$mainUrl/${request.data}").document
@ -92,6 +97,7 @@ class HigoTVProvider : MainAPI() {
// Detailed information // Detailed information
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
val document = app.get(url).document val document = app.get(url).document
// Parse info // Parse info
val title = document.select(".anime-op__txt").text() val title = document.select(".anime-op__txt").text()
val engTitle = document.select(".anime-eng__txt").text() val engTitle = document.select(".anime-eng__txt").text()
@ -128,35 +134,31 @@ class HigoTVProvider : MainAPI() {
// Parse episodes // Parse episodes
val episodes = mutableListOf<Episode>() val episodes = mutableListOf<Episode>()
val playerRawJson = document.select("div.player")
document .select("script").forEach {
.select("div.player") if(!it.html().substringAfter("file:").substringBeforeLast("})").contains("folder:")) return@forEach
.select("script")
.html()
.substringAfterLast("file:")
.substringBeforeLast("},")
val parsedJSON = Gson().fromJson<List<PlayerJson>>(playerRawJson, listPlayer) val parsedJSON = gson.fromJson<List<PlayerJson>>(
it.html().substringAfter("file:").substringBeforeLast("})"), listPlayer
)
if (parsedJSON[0].title.isNullOrEmpty()) return@forEach
parsedJSON[1].folder?.forEach { voices -> parsedJSON[0].folder?.forEach { voices ->
if (voices != null) { if (voices != null) {
if (!voices.title.isNullOrEmpty()) { if (voices.file.isNullOrBlank()) return@forEach
voices.folder?.forEach {
if (it != null) {
if (!it.file.isNullOrBlank()) {
episodes.add( episodes.add(
Episode( Episode(
"${url}, ${it.title}", "${url}, ${voices.title}",
it.title, voices.title,
episode = it.title!!.replace(" Серія", "").toIntOrNull(), episode = voices.title!!.replace(" Серія", "").toIntOrNull(),
) )
) )
} }
} }
} }
}
} // Log.d("CakesTwix-Debug", playerRawJson)
}
// Parse Episodes as Series // Parse Episodes as Series
return if (tvType != TvType.Movie) { return if (tvType != TvType.Movie) {
@ -196,31 +198,24 @@ class HigoTVProvider : MainAPI() {
val document = app.get(dataList[0]).document val document = app.get(dataList[0]).document
val playerRawJson = document.select("div.player")
document .select("script").forEach {
.select("div.player") if(!it.html().substringAfter("file:").substringBeforeLast("})").contains("folder:")) return@forEach
.select("script")
.html()
.substringAfterLast("file:")
.substringBeforeLast("},")
val parsedJSON = Gson().fromJson<List<PlayerJson>>(playerRawJson, listPlayer) val parsedJSON = gson.fromJson<List<PlayerJson>>(
it.html().substringAfter("file:").substringBeforeLast("})"), listPlayer
)
if (parsedJSON[0].title.isNullOrEmpty()) return@forEach
// Sorry for this... parsedJSON[0].folder?.forEach { voices ->
// Here we check for the presence of letters in JSON voices and the presence of folder
// in them and the scheme is repeated, but further instead of folder, we check file
parsedJSON[1].folder?.forEach { voices ->
if (voices != null) { if (voices != null) {
if (!voices.title.isNullOrEmpty()) { if (voices.file.isNullOrBlank() || voices.title != dataList[1]) return@forEach
voices.folder?.forEach {
if (it != null) {
if (!it.file.isNullOrBlank()) {
if (it.title == dataList[1]) {
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
it.file, voices.file,
name = "${voices.title}", name = "${parsedJSON[0].title}",
it.file, voices.file,
"", "",
0, 0,
isM3u8 = false, isM3u8 = false,
@ -229,10 +224,6 @@ class HigoTVProvider : MainAPI() {
} }
} }
} }
}
}
}
}
return true return true
} }