Anitubeinua: Initial series parsing

Only Ashdi players
Fuck the website developers
This commit is contained in:
CakesTwix 2023-02-19 18:51:47 +02:00
parent 2dca366c12
commit 73b0059e68
Signed by: CakesTwix
GPG key ID: 7B11051D5CE19825
2 changed files with 61 additions and 34 deletions

View file

@ -2,15 +2,13 @@ package com.lagradost
import android.util.Log import android.util.Log
import com.lagradost.models.PlayerJson import com.lagradost.models.PlayerJson
import com.lagradost.extractors.AshdiExtractor
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson 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 okio.ByteString.Companion.decodeBase64 import org.jsoup.Jsoup
import okio.ByteString.Companion.decodeHex
import okio.ByteString.Companion.encodeUtf8
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.nio.charset.Charset
class AnitubeinuaProvider : MainAPI() { class AnitubeinuaProvider : MainAPI() {
@ -73,7 +71,7 @@ class AnitubeinuaProvider : MainAPI() {
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
var someInfo = document.select("div.story_c_r")[1] val someInfo = document.select("div.story_c_r")[1]
// Parse info // Parse info
val title = document.selectFirst(".story_c h2")?.text()?.trim().toString() val title = document.selectFirst(".story_c h2")?.text()?.trim().toString()
@ -94,30 +92,40 @@ class AnitubeinuaProvider : MainAPI() {
// 12 - json with episodes // 12 - json with episodes
// Players, Episodes, Number of episodes // Players, Episodes, Number of episodes
// TODO: Parse Episodes // TODO: Parse Episodes
var episodes: List<Episode> = emptyList()
document.select("script").map{ script -> document.select("script").map{ script ->
if (script.data().contains("RalodePlayer.init(")) { if (script.data().contains("RalodePlayer.init(")) {
val playerScriptRawJson = script.data().substringAfterLast(".init(").substringBefore(");") val playerScriptRawJson = script.data().substringAfterLast(".init(").substringBefore(");")
val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",") val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",")
val playerNamesArray = (playerScriptRawJson.substringBefore("],") + "]").dropLast(1).drop(1).split(",") val playerNamesArray = (playerScriptRawJson.substringBefore("],") + "]").dropLast(1).drop(1).split(",")
val numberOfEpisodesInt = playerScriptRawJson.substringAfterLast(",").toIntOrNull() val numberOfEpisodesInt = playerScriptRawJson.substringAfterLast(",").toIntOrNull()
Log.d("load-debug", playerNamesArray[0].dropLast(1).drop(1))
// TODO: Decode string // Decoded string, thanks to Secozzi
Log.d("load-debug", decode(playerNamesArray[0])) // val hexRegex = Regex("\\\\u([0-9a-fA-F]{4})")
// val decodedString = hexRegex.replace(playerNamesArray[0]) { matchResult ->
// Integer.parseInt(matchResult.groupValues[1], 16).toChar().toString()
// }
// Log.d("load-debug", decodedString)
val playerJson = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!! val playerJson = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!!
for(item in playerJson) { for(item in playerJson) {
for (item2 in item) { for (item2 in item) {
//Log.d("load-debug", item2.name) if(!item2.name.contains("ПЛЕЙЛИСТ")) // UFDub player
{
episodes = episodes.plus(
Episode(
"${item2.name}, $url",
item2.name,
episode = item2.name.replace("Серія ","").toIntOrNull(),
)
)
}
} }
} }
} }
} //.substringAfterLast(".init(").substringBefore(");") }
var episodes: List<Episode> = emptyList()
return newTvSeriesLoadResponse(title, url, tvType, episodes) { return newTvSeriesLoadResponse(title, url, tvType, episodes) {
this.posterUrl = poster this.posterUrl = poster
@ -132,34 +140,41 @@ class AnitubeinuaProvider : MainAPI() {
// 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, // (Serisl) [Season, Episode, Player Url] | (Film) [Title, Player Url] data: String, // Серія, 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(", ")
val document = app.get(dataList[1]).document
Log.d("load-debug", dataList.toString())
// Its film, parse one m3u8 document.select("script").map { script ->
if(dataList.size == 2){ Log.d("load-debug", script.data())
val m3u8Url = app.get(dataList[1]).document.select("script").html() if (script.data().contains("RalodePlayer.init(")) {
.substringAfterLast("file:\"") val playerScriptRawJson = script.data().substringAfterLast(".init(").substringBefore(");")
.substringBefore("\",") val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",")
Log.d("load-debug", playerScriptRawJson)
val playerJson = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!!
for(item in playerJson) {
for (item2 in item) {
if(item2.name == dataList[0]){
if(item2.code.contains("https://ashdi.vip")){
M3u8Helper.generateM3u8( M3u8Helper.generateM3u8(
source = dataList[0], source = dataList[0],
streamUrl = m3u8Url, streamUrl = AshdiExtractor().ParseM3U8(Jsoup.parse(item2.code).select("iframe").attr("src")),
referer = "https://tortuga.wtf/" referer = "https://qeruya.cyou"
).forEach(callback) ).forEach(callback)
}
}
}
}
return true
}
}
return true return true
} }
val playerRawJson = app.get(dataList[2]).document.select("script").html() fun decode(input: String): String = java.net.URLDecoder.decode(input, "ISO-8859-1")
.substringAfterLast("file:\'")
.substringBefore("\',")
return true
}
fun decode(input: String): String = java.net.URLDecoder.decode(input, "utf-16")
} }

View file

@ -0,0 +1,12 @@
package com.lagradost.extractors;
import com.lagradost.cloudstream3.app
class AshdiExtractor() {
suspend fun ParseM3U8(url: String): String{
return app.get(url).document.select("script").html()
.substringAfterLast("file:\"")
.substringBefore("\",")
}
}