Skip to content

Commit

Permalink
higotv: Fix episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
CakesTwix committed Feb 17, 2024
1 parent 533133d commit 14f7218
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 62 deletions.
2 changes: 1 addition & 1 deletion HigoTVProvider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// use an integer for version numbers
version = 2
version = 3

dependencies{
implementation("com.google.code.gson:gson:2.9.0")
Expand Down
113 changes: 52 additions & 61 deletions HigoTVProvider/src/main/kotlin/com/lagradost/HigoTVProvider.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lagradost

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.lagradost.cloudstream3.AnimeSearchResponse
import com.lagradost.cloudstream3.DubStatus
Expand All @@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.models.PlayerJson
import org.jsoup.nodes.Element


class HigoTVProvider : MainAPI() {

// Basic Info
Expand Down Expand Up @@ -63,6 +64,10 @@ class HigoTVProvider : MainAPI() {

private val TAG = "$name-Debug"

private val gson = GsonBuilder()
.setLenient()
.create()

override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val document = app.get("$mainUrl/${request.data}").document

Expand Down Expand Up @@ -92,6 +97,7 @@ class HigoTVProvider : MainAPI() {
// Detailed information
override suspend fun load(url: String): LoadResponse {
val document = app.get(url).document

// Parse info
val title = document.select(".anime-op__txt").text()
val engTitle = document.select(".anime-eng__txt").text()
Expand Down Expand Up @@ -128,35 +134,31 @@ class HigoTVProvider : MainAPI() {
// Parse episodes
val episodes = mutableListOf<Episode>()

val playerRawJson =
document
.select("div.player")
.select("script")
.html()
.substringAfterLast("file:")
.substringBeforeLast("},")

val parsedJSON = Gson().fromJson<List<PlayerJson>>(playerRawJson, listPlayer)

parsedJSON[1].folder?.forEach { voices ->
if (voices != null) {
if (!voices.title.isNullOrEmpty()) {
voices.folder?.forEach {
if (it != null) {
if (!it.file.isNullOrBlank()) {
episodes.add(
Episode(
"${url}, ${it.title}",
it.title,
episode = it.title!!.replace(" Серія", "").toIntOrNull(),
)
)
}
}
document.select("div.player")
.select("script").forEach {
if(!it.html().substringAfter("file:").substringBeforeLast("})").contains("folder:")) return@forEach

val parsedJSON = gson.fromJson<List<PlayerJson>>(
it.html().substringAfter("file:").substringBeforeLast("})"), listPlayer
)
if (parsedJSON[0].title.isNullOrEmpty()) return@forEach

parsedJSON[0].folder?.forEach { voices ->
if (voices != null) {
if (voices.file.isNullOrBlank()) return@forEach
episodes.add(
Episode(
"${url}, ${voices.title}",
voices.title,
episode = voices.title!!.replace(" Серія", "").toIntOrNull(),
)
)
}
}
}
}

// Log.d("CakesTwix-Debug", playerRawJson)

// Parse Episodes as Series
return if (tvType != TvType.Movie) {

Expand Down Expand Up @@ -196,43 +198,32 @@ class HigoTVProvider : MainAPI() {

val document = app.get(dataList[0]).document

val playerRawJson =
document
.select("div.player")
.select("script")
.html()
.substringAfterLast("file:")
.substringBeforeLast("},")

val parsedJSON = Gson().fromJson<List<PlayerJson>>(playerRawJson, listPlayer)

// Sorry for this...
// 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.title.isNullOrEmpty()) {
voices.folder?.forEach {
if (it != null) {
if (!it.file.isNullOrBlank()) {
if (it.title == dataList[1]) {
callback.invoke(
ExtractorLink(
it.file,
name = "${voices.title}",
it.file,
"",
0,
isM3u8 = false,
)
)
}
}
}
document.select("div.player")
.select("script").forEach {
if(!it.html().substringAfter("file:").substringBeforeLast("})").contains("folder:")) return@forEach

val parsedJSON = gson.fromJson<List<PlayerJson>>(
it.html().substringAfter("file:").substringBeforeLast("})"), listPlayer
)
if (parsedJSON[0].title.isNullOrEmpty()) return@forEach

parsedJSON[0].folder?.forEach { voices ->
if (voices != null) {
if (voices.file.isNullOrBlank() || voices.title != dataList[1]) return@forEach

callback.invoke(
ExtractorLink(
voices.file,
name = "${parsedJSON[0].title}",
voices.file,
"",
0,
isM3u8 = false,
)
)
}
}
}
}

return true
}
Expand Down

0 comments on commit 14f7218

Please sign in to comment.