anitubeinua: refactor VideoContructor parser
This commit is contained in:
parent
96f26e933c
commit
518abe596f
2 changed files with 66 additions and 40 deletions
|
@ -10,6 +10,7 @@ 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.Ajax
|
||||||
import com.lagradost.models.Link
|
import com.lagradost.models.Link
|
||||||
|
import com.lagradost.models.videoConstructor
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -128,24 +129,18 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
} else {
|
} else {
|
||||||
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 episodesList = fromVideoContructor(script)
|
||||||
val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",")
|
|
||||||
// val playerNamesArray = (playerScriptRawJson.substringBefore("],") + "]").dropLast(1).drop(1).replace("\",\"", ",,,").split(",,,")
|
|
||||||
// val numberOfEpisodesInt = playerScriptRawJson.substringAfterLast(",").toIntOrNull()
|
|
||||||
|
|
||||||
val playerJson = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!!
|
episodesList.forEachIndexed { index, episode ->
|
||||||
for(item in playerJson) {
|
if(!episode.playerName.contains("ПЛЕЙЛИСТ")) // UFDub player
|
||||||
item.forEachIndexed { index, item2 ->
|
{
|
||||||
if(!item2.name.contains("ПЛЕЙЛИСТ")) // UFDub player
|
dubEpisodes.add(
|
||||||
{
|
Episode(
|
||||||
dubEpisodes.add(
|
"$index, $url",
|
||||||
Episode(
|
episode.episodeName,
|
||||||
"$index, $url",
|
episode = episode.episodeNumber,
|
||||||
item2.name,
|
|
||||||
episode = item2.name.replace("Серія ","").toIntOrNull(),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,37 +229,29 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
val document = app.get(dataList[1]).document
|
val document = app.get(dataList[1]).document
|
||||||
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(");")
|
fromVideoContructor(script).forEach { dub ->
|
||||||
val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",")
|
with(dub.episodeUrl) {
|
||||||
val playerNamesArray = (playerScriptRawJson.substringBefore("],") + "]").dropLast(1).drop(1).replace("\",\"", ",,,").split(",,,")
|
|
||||||
|
|
||||||
val playerJson = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!!
|
|
||||||
playerJson.forEachIndexed { index, dub ->
|
|
||||||
with(dub[dataList[0].toInt()].code) {
|
|
||||||
when {
|
when {
|
||||||
contains("https://tortuga.wtf/vod/") -> {
|
contains("https://tortuga.wtf/vod/") -> {
|
||||||
M3u8Helper.generateM3u8(
|
M3u8Helper.generateM3u8(
|
||||||
source = decode(playerNamesArray[index]),
|
source = dub.playerName,
|
||||||
streamUrl = AshdiExtractor().ParseM3U8(Jsoup.parse(dub[dataList[0].toInt()].code).select("iframe")
|
streamUrl = AshdiExtractor().ParseM3U8(this),
|
||||||
.attr("src")),
|
|
||||||
referer = "https://tortuga.wtf/"
|
referer = "https://tortuga.wtf/"
|
||||||
).forEach(callback)
|
).forEach(callback)
|
||||||
}
|
}
|
||||||
contains("https://ashdi.vip/vod") -> {
|
contains("https://ashdi.vip/vod") -> {
|
||||||
M3u8Helper.generateM3u8(
|
M3u8Helper.generateM3u8(
|
||||||
source = decode(playerNamesArray[index]),
|
source = dub.playerName,
|
||||||
streamUrl = AshdiExtractor().ParseM3U8(Jsoup.parse(dub[dataList[0].toInt()].code).select("iframe")
|
streamUrl = AshdiExtractor().ParseM3U8(this),
|
||||||
.attr("src")),
|
|
||||||
referer = "https://qeruya.cyou"
|
referer = "https://qeruya.cyou"
|
||||||
).forEach(callback)
|
).forEach(callback)
|
||||||
}
|
}
|
||||||
contains("https://www.udrop.com") -> {
|
contains("https://www.udrop.com") -> {
|
||||||
callback.invoke(
|
callback.invoke(
|
||||||
ExtractorLink(
|
ExtractorLink(
|
||||||
decode(playerNamesArray[index]),
|
dub.playerName,
|
||||||
name = decode(playerNamesArray[index]),
|
name = dub.playerName,
|
||||||
Jsoup.parse(dub[dataList[0].toInt()].code).select("iframe")
|
this,
|
||||||
.attr("src"),
|
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
isM3u8 = false,
|
isM3u8 = false,
|
||||||
|
@ -272,12 +259,11 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
contains("https://csst.online/embed/") -> {
|
contains("https://csst.online/embed/") -> {
|
||||||
csstExtractor().ParseUrl(Jsoup.parse(dub[dataList[0].toInt()].code).select("iframe")
|
csstExtractor().ParseUrl(this).split(",").forEach{
|
||||||
.attr("src")).split(",").forEach{
|
|
||||||
callback.invoke(
|
callback.invoke(
|
||||||
ExtractorLink(
|
ExtractorLink(
|
||||||
decode(playerNamesArray[index]),
|
dub.playerName,
|
||||||
name = "${decode(playerNamesArray[index])} ${it.substringBefore("]").drop(1)}",
|
name = "${dub.playerName} ${it.substringBefore("]").drop(1)}",
|
||||||
it.substringAfter("]"),
|
it.substringAfter("]"),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
|
@ -310,6 +296,8 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
val message: String?
|
val message: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Thanks to Andro999b
|
||||||
|
// https://github.com/Andro999b/movies-telegram-bot/blob/a296c7d4122a25fa70b612e75d741dd55c154640/functions/src/providers/AnitubeUAProvider.ts#L86-L137
|
||||||
private suspend fun fromPlaylistAjax(url: String): List<Ajax>? {
|
private suspend fun fromPlaylistAjax(url: String): List<Ajax>? {
|
||||||
val responseGet = app.get(url).parsedSafe<Responses>()
|
val responseGet = app.get(url).parsedSafe<Responses>()
|
||||||
|
|
||||||
|
@ -329,6 +317,7 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
audios.add(Pair(it.text(), it.attr("data-id")))
|
audios.add(Pair(it.text(), it.attr("data-id")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set listPlayers and listDubStatus
|
||||||
// If has subs - So players in 3 index
|
// If has subs - So players in 3 index
|
||||||
if(playlist.select(".playlists-lists .playlists-items").count() == 3){
|
if(playlist.select(".playlists-lists .playlists-items").count() == 3){
|
||||||
// Players
|
// Players
|
||||||
|
@ -340,12 +329,14 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
listDubStatus.add(Pair(it.text(), it.attr("data-id")))
|
listDubStatus.add(Pair(it.text(), it.attr("data-id")))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// No subs
|
||||||
// Players
|
// Players
|
||||||
playlist.select(".playlists-lists .playlists-items:nth-child(2) li").forEach {
|
playlist.select(".playlists-lists .playlists-items:nth-child(2) li").forEach {
|
||||||
listPlayers.add(Pair(it.text(), it.attr("data-id")))
|
listPlayers.add(Pair(it.text(), it.attr("data-id")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse episodes
|
||||||
playlist.select(".playlists-videos .playlists-items li").forEach { element ->
|
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 audioId = element.attr("data-id") // 0_0_0 or 0_0_0_0 if subs
|
||||||
val episodeId = extractIntFromString(element.text())
|
val episodeId = extractIntFromString(element.text())
|
||||||
|
@ -382,17 +373,44 @@ class AnitubeinuaProvider : MainAPI() {
|
||||||
episodeId,
|
episodeId,
|
||||||
element.text(),
|
element.text(),
|
||||||
Link(
|
Link(
|
||||||
isDub, // TODO: Impl
|
isDub,
|
||||||
url,
|
url,
|
||||||
audio.toString(),
|
audio.toString(),
|
||||||
playerName,
|
playerName,
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnEpisodes.toList()
|
return returnEpisodes.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fromVideoContructor(script: Element): List<videoConstructor> {
|
||||||
|
val playerScriptRawJson = script.data().substringAfterLast(".init(").substringBefore(");")
|
||||||
|
val playerEpisodesRawJson = playerScriptRawJson.substringAfter("],").substringBeforeLast(",")
|
||||||
|
val playerNamesArray = (playerScriptRawJson.substringBefore("],") + "]").dropLast(1).drop(1).replace("\",\"", ",,,").split(",,,")
|
||||||
|
// val numberOfEpisodesInt = playerScriptRawJson.substringAfterLast(",").toIntOrNull()
|
||||||
|
|
||||||
|
val jsonEpisodes = tryParseJson<List<List<PlayerJson>>>(playerEpisodesRawJson)!!
|
||||||
|
val episodes = mutableListOf<videoConstructor>()
|
||||||
|
|
||||||
|
jsonEpisodes.forEachIndexed { index, episode ->
|
||||||
|
val playerName = decode(playerNamesArray[index])
|
||||||
|
episode.forEach{
|
||||||
|
episodes.add(
|
||||||
|
videoConstructor(
|
||||||
|
playerName,
|
||||||
|
it.name,
|
||||||
|
extractIntFromString(it.name),
|
||||||
|
Jsoup.parse(it.code).select("iframe").attr("src")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
// Log.d("load-debug", "$playerName ${it.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.d("load-debug", episodes.toString())
|
||||||
|
return episodes.toList()
|
||||||
|
}
|
||||||
private fun extractIntFromString(string: String): Int? {
|
private fun extractIntFromString(string: String): Int? {
|
||||||
val value = Regex("(\\d+)").find(string)?.value
|
val value = Regex("(\\d+)").find(string)?.value
|
||||||
if(value!![0].toString() == "0"){
|
if(value!![0].toString() == "0"){
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.lagradost.models
|
||||||
|
|
||||||
|
data class videoConstructor (
|
||||||
|
val playerName: String,
|
||||||
|
val episodeName: String,
|
||||||
|
val episodeNumber: Int?,
|
||||||
|
val episodeUrl: String
|
||||||
|
)
|
Loading…
Reference in a new issue