anitubeinua: refactor ajax parser

This commit is contained in:
CakesTwix 2023-03-11 17:59:23 +02:00
parent 599fda2d0b
commit 96f26e933c
Signed by: CakesTwix
GPG key ID: 7B11051D5CE19825
3 changed files with 190 additions and 107 deletions

View file

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

View file

@ -1,5 +1,6 @@
package com.lagradost package com.lagradost
import android.util.Log
import com.lagradost.models.PlayerJson import com.lagradost.models.PlayerJson
import com.lagradost.extractors.AshdiExtractor import com.lagradost.extractors.AshdiExtractor
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
@ -7,6 +8,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper import com.lagradost.cloudstream3.utils.M3u8Helper
import com.lagradost.extractors.csstExtractor import com.lagradost.extractors.csstExtractor
import com.lagradost.models.Ajax
import com.lagradost.models.Link
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.util.* import java.util.*
@ -76,7 +79,7 @@ class AnitubeinuaProvider : MainAPI() {
} }
// Detailed information // Detailed information
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): AnimeLoadResponse {
val document = app.get(url).document val document = app.get(url).document
val someInfo = document.select("div.story_c_r")[1] val someInfo = document.select("div.story_c_r")[1]
@ -98,28 +101,30 @@ class AnitubeinuaProvider : MainAPI() {
// Return to app // Return to app
// Players, Episodes, Number of episodes // Players, Episodes, Number of episodes
var episodes: List<Episode> = emptyList() var subEpisodes = mutableListOf<Episode>()
var dubEpisodes = mutableListOf<Episode>()
val id = url.split("/").last().split("-").first() val id = url.split("/").last().split("-").first()
val responseGet = app.get("$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}").parsedSafe<Responses>()!!
if (responseGet.success == true) { // First type players val ajax = fromPlaylistAjax("$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}")
episodes =
app.get("$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}") if (!ajax.isNullOrEmpty()) { // Ajax list
.parsedSafe<Responses>()?.response.let { ajax.groupBy{ it.name }.forEach { episodes -> // Group by name
Jsoup.parse(it.toString()).select("div.playlists-videos li") episodes.value.forEach{
.mapIndexedNotNull() { index, eps -> if(it.urls.isDub){
val href = dubEpisodes.add(Episode(
"$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}" "${it.name}, $id, ${it.urls.isDub}",
val name = eps.text().trim() // Серія 1 it.name,
if (href.isNotEmpty()) { episode = it.numberEpisode)
Episode( )
"$href, $index", // link, Серія 1 } else {
name, subEpisodes.add(Episode(
) "${it.name}, $id, ${it.urls.isDub}",
} else { it.name,
null episode = it.numberEpisode)
} )
}
} }
}
}
} else { } else {
document.select("script").map{ script -> document.select("script").map{ script ->
if (script.data().contains("RalodePlayer.init(")) { if (script.data().contains("RalodePlayer.init(")) {
@ -133,7 +138,7 @@ class AnitubeinuaProvider : MainAPI() {
item.forEachIndexed { index, item2 -> item.forEachIndexed { index, item2 ->
if(!item2.name.contains("ПЛЕЙЛИСТ")) // UFDub player if(!item2.name.contains("ПЛЕЙЛИСТ")) // UFDub player
{ {
episodes = episodes.plus( dubEpisodes.add(
Episode( Episode(
"$index, $url", "$index, $url",
item2.name, item2.name,
@ -148,114 +153,82 @@ class AnitubeinuaProvider : MainAPI() {
} }
} }
return newTvSeriesLoadResponse(title, url, tvType, episodes.distinctBy{ it.name }) { return newAnimeLoadResponse(title, url, tvType) {
this.posterUrl = poster this.posterUrl = poster
this.year = year this.year = year
this.plot = description this.plot = description
this.tags = tags this.tags = tags
this.rating = rating this.rating = rating
this.recommendations = recommendations this.recommendations = recommendations
addEpisodes(DubStatus.Dubbed, dubEpisodes)
addEpisodes(DubStatus.Subbed, subEpisodes)
} }
} }
// It works when I click to view the series // It works when I click to view the series
override suspend fun loadLinks( override suspend fun loadLinks(
data: String, // (First) link, index | (Two) index, url title data: String, // (Ajax) Name, id title, isDub | (Two) index, url title
isCasting: Boolean, isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
val dataList = data.split(", ") val dataList = data.split(", ")
if(dataList[0].contains("https://")){ // Its First type player if(dataList[0].toIntOrNull() == null){ // Its ajax list
// Get episodes list (as json) val ajax = fromPlaylistAjax("$mainUrl/engine/ajax/playlists.php?news_id=${dataList[1]}&xfield=playlist&time=${Date().time}")
val responseGet = app.get(dataList[0]).parsedSafe<Responses>() // ajax link
responseGet?.response?.let { it ->
// List Players // Filter by name and isDub
val playersTab = Jsoup.parse(it).select("div.playlists-items") ajax?.filter { it.name == dataList[0] }
?.filter { it.urls.isDub == dataList[2].toBoolean() }
?.forEach {
// Parse all episodes by name // Get m3u8 url
var index = 0 with(it){
var playerTabId = "" when{
Jsoup.parse(it).select("div.playlists-videos li") it.urls.url.contains("https://tortuga.wtf/vod/") -> {
.mapNotNull { eps -> M3u8Helper.generateM3u8(
// 0 - idk, 1 - dub, 2 - player source = "${it.urls.playerName} (${it.urls.name})",
// if with sub streamUrl = AshdiExtractor().ParseM3U8(this.urls.url),
// 0 - idk 1 - dub 2 - sub or dub 3 - player referer = "https://tortuga.wtf/"
// dataList[1] - index ).forEach(callback)
// 0_1_2
// Log.d("load-debug", eps.attr("data-id"))
if(playerTabId != eps.attr("data-id")){
index = 0
playerTabId = eps.attr("data-id")
} }
it.urls.url.contains("https://ashdi.vip/vod") -> {
if(dataList[1].toInt() == index){ M3u8Helper.generateM3u8(
var href = eps.attr("data-file") // m3u url source = "${it.urls.playerName} (${it.urls.name})",
streamUrl = AshdiExtractor().ParseM3U8(this.urls.url),
// Can be without https: referer = "https://qeruya.cyou"
if (!href.contains("https://")) { ).forEach(callback)
href = "https:$href" }
} it.urls.url.contains("https://www.udrop.com") -> {
callback.invoke(
val dubName = playersTab[0].select(" li[data-id=${ playerTabId.take(3) }]").text() // G&M ExtractorLink(
var playerName = playersTab[1].select(" li[data-id=$playerTabId]").text() // ПЛЕЄР ASHDI this.urls.url,
if(playerTabId.count { it == '_' } == 3) { name = "${it.urls.playerName} (${it.urls.name})",
playerName = this.urls.url,
playersTab[2].selectFirst(" li[data-id=$playerTabId]")!! "",
.text() // ПЛЕЄР ASHDI 0,
} isM3u8 = false,
)
with(href){ )
when{ }
contains("https://tortuga.wtf/vod/") -> { it.urls.url.contains("https://csst.online/embed/") -> {
M3u8Helper.generateM3u8( csstExtractor().ParseUrl(it.urls.url).split(",").forEach{ csstUrl ->
source = "$playerName ($dubName)", callback.invoke(
streamUrl = AshdiExtractor().ParseM3U8(href), ExtractorLink(
referer = "https://tortuga.wtf/" this.urls.url,
).forEach(callback) name = "${it.urls.playerName} (${it.urls.name}) ${csstUrl.substringBefore("]").drop(1)}",
} csstUrl.substringAfter("]"),
contains("https://ashdi.vip/vod") -> { "",
M3u8Helper.generateM3u8( 0,
source = "$playerName ($dubName)", isM3u8 = false,
streamUrl = AshdiExtractor().ParseM3U8(href), )
referer = "https://qeruya.cyou" )
).forEach(callback)
}
contains("https://www.udrop.com") -> {
callback.invoke(
ExtractorLink(
"$playerName ($dubName)",
name = "$playerName ($dubName)",
href,
"",
0,
isM3u8 = false,
)
)
}
contains("https://csst.online/embed/") -> {
csstExtractor().ParseUrl(href).split(",").forEach{
callback.invoke(
ExtractorLink(
"$playerName ($dubName)",
name = "$playerName ($dubName) ${it.substringBefore("]").drop(1)}",
it.substringAfter("]"),
"",
0,
isM3u8 = false,
)
)
}
}
else -> {}
}
} }
} }
index += 1 else -> {}
} }
}
} }
} else { } else {
val document = app.get(dataList[1]).document val document = app.get(dataList[1]).document
@ -336,4 +309,99 @@ class AnitubeinuaProvider : MainAPI() {
val response: String?, val response: String?,
val message: String? val message: String?
) )
private suspend fun fromPlaylistAjax(url: String): List<Ajax>? {
val responseGet = app.get(url).parsedSafe<Responses>()
// Not Ajax, return null
if(responseGet?.success == false){
// Log.d("load-debug", "Not Ajax")
return null
}
val returnEpisodes = mutableListOf<Ajax>()
val playlist = Jsoup.parse(responseGet?.response!!)
val audios = mutableListOf<Pair<String,String>>() // (INARI, 0_0, ...)
val listDubStatus = mutableListOf<Pair<String,String>>() // (СУБТИТРИ, 0_0_0, ...)
val listPlayers = mutableListOf<Pair<String,String>>() // (ПЛЕЄР МОНСТР, 0_0_0_0, ...)
playlist.select(".playlists-lists .playlists-items:first-child li").forEach {
audios.add(Pair(it.text(), it.attr("data-id")))
}
// If has subs - So players in 3 index
if(playlist.select(".playlists-lists .playlists-items").count() == 3){
// Players
playlist.select(".playlists-lists .playlists-items:nth-child(3) li").forEach {
listPlayers.add(Pair(it.text(), it.attr("data-id")))
}
// Subs/Dubs index
playlist.select(".playlists-lists .playlists-items:nth-child(2) li").forEach {
listDubStatus.add(Pair(it.text(), it.attr("data-id")))
}
} else {
// Players
playlist.select(".playlists-lists .playlists-items:nth-child(2) li").forEach {
listPlayers.add(Pair(it.text(), it.attr("data-id")))
}
}
playlist.select(".playlists-videos .playlists-items li").forEach { element ->
val audioId = element.attr("data-id") // 0_0_0 or 0_0_0_0 if subs
val episodeId = extractIntFromString(element.text())
val url = element.attr("data-file")
var isDub = true
var audio: String? = null
var playerName = ""
// Set this element Dub name
audios.forEach {
if(audioId.startsWith(it.second)){
audio = it.first
}
}
if(audioId.count { it == '_' } == 3){
listDubStatus.forEach {
if(audioId.startsWith(it.second)){
if(it.first == "СУБТИТРИ"){
isDub = false
}
}
}
listPlayers.forEach {
if(audioId.startsWith(it.second)){
playerName = it.first
}
}
}
returnEpisodes.add(
Ajax(
episodeId,
element.text(),
Link(
isDub, // TODO: Impl
url,
audio.toString(),
playerName,
)
))
}
return returnEpisodes.toList()
}
private fun extractIntFromString(string: String): Int? {
val value = Regex("(\\d+)").find(string)?.value
if(value!![0].toString() == "0"){
return value.drop(1).toIntOrNull()
}
return value.toIntOrNull()
}
} }

View file

@ -0,0 +1,15 @@
package com.lagradost.models
data class Ajax (
val numberEpisode : Int?,
val name : String,
val urls : Link,
)
data class Link (
val isDub : Boolean,
val url : String,
val name : String,
val playerName : String,
)