From d2baf99a12c279d320f67866a35b7677637dd1e1 Mon Sep 17 00:00:00 2001 From: CakesTwix Date: Tue, 9 Apr 2024 11:54:59 +0300 Subject: [PATCH] anitubeinua: Fix posters for recommendations and reformat code --- .../com/lagradost/AnitubeinuaProvider.kt | 366 ++++++++---------- 1 file changed, 171 insertions(+), 195 deletions(-) diff --git a/AnitubeinuaProvider/src/main/kotlin/com/lagradost/AnitubeinuaProvider.kt b/AnitubeinuaProvider/src/main/kotlin/com/lagradost/AnitubeinuaProvider.kt index 14fbc52..89f56d2 100644 --- a/AnitubeinuaProvider/src/main/kotlin/com/lagradost/AnitubeinuaProvider.kt +++ b/AnitubeinuaProvider/src/main/kotlin/com/lagradost/AnitubeinuaProvider.kt @@ -12,7 +12,6 @@ import com.lagradost.models.Ajax import com.lagradost.models.Link import com.lagradost.models.PlayerJson import com.lagradost.models.videoConstructor -import java.util.* import org.jsoup.Jsoup import org.jsoup.nodes.Element @@ -25,17 +24,17 @@ class AnitubeinuaProvider : MainAPI() { override var lang = "uk" override val hasDownloadSupport = true override val supportedTypes = - setOf( - TvType.AnimeMovie, - TvType.Anime, - ) + setOf( + TvType.AnimeMovie, + TvType.Anime, + ) // Sections override val mainPage = - mainPageOf( - "$mainUrl/anime/page/" to "Нові", - "$mainUrl/f/sort=rating/order=desc/page/" to "Популярні", - ) + mainPageOf( + "$mainUrl/anime/page/" to "Нові", + "$mainUrl/f/sort=rating/order=desc/page/" to "Популярні", + ) private var dle_login_hash = "" @@ -49,8 +48,9 @@ class AnitubeinuaProvider : MainAPI() { private fun Element.toSearchResponse(): AnimeSearchResponse { val title = this.selectFirst(".story_c h2 a, div.text_content a")?.text()?.trim().toString() val href = this.selectFirst(".story_c h2 a, div.text_content a")?.attr("href").toString() - val posterUrl = - mainUrl + this.selectFirst(".story_c_l span.story_post img, a img")?.attr("src") + var posterUrl = this.selectFirst(".story_c_l span.story_post img")?.attr("src") + // For recommendations + if (posterUrl.isNullOrEmpty()) posterUrl = this.selectFirst("a img")?.attr("data-src") var isSub = this.select(".box .sub").isNotEmpty() var isDub = this.select(".box .ukr").isNotEmpty() @@ -59,23 +59,21 @@ class AnitubeinuaProvider : MainAPI() { isDub = true } return newAnimeSearchResponse(title, href, TvType.Anime) { - this.posterUrl = posterUrl + this.posterUrl = mainUrl + posterUrl addDubStatus(isDub, isSub) } } override suspend fun search(query: String): List { val document = - app.post( - url = mainUrl, - data = - mapOf( - "do" to "search", - "subaction" to "search", - "story" to query.replace(" ", "+") - ) - ) - .document + app.post( + url = mainUrl, + data = + mapOf( + "do" to "search", + "subaction" to "search", + "story" to query.replace(" ", "+"))) + .document return document.select("article.story").map { it.toSearchResponse() } } @@ -88,8 +86,7 @@ class AnitubeinuaProvider : MainAPI() { // Parse info val title = document.selectFirst(".story_c h2")?.text()?.trim().toString() - val poster = - mainUrl + document.selectFirst(".story_c_left span.story_post img")?.attr("src") + val poster = mainUrl + document.selectFirst(".story_c_left span.story_post img")?.attr("src") val tags = someInfo.select("a[href*=/anime/]").map { it.text() } val year = someInfo.select("a[href*=/xfsearch/year/]").text().toIntOrNull() @@ -97,8 +94,7 @@ class AnitubeinuaProvider : MainAPI() { val description = document.selectFirst("div.my-text")?.text()?.trim() // val author = someInfo.select("strong:contains(Студія:)").next().html() val trailer = document.selectFirst(".rcol a.rollover")?.attr("href").toString() - val rating = - document.selectFirst(".lexington-box > div:last-child span")?.text().toRatingInt() + val rating = document.selectFirst(".lexington-box > div:last-child span")?.text().toRatingInt() val recommendations = document.select(".horizontal ul li").map { it.toSearchResponse() } @@ -107,42 +103,37 @@ class AnitubeinuaProvider : MainAPI() { val subEpisodes = mutableListOf() val dubEpisodes = mutableListOf() val id = url.split("/").last().split("-").first() - dle_login_hash = document.body().selectFirst("script")!!.html() - .substringAfterLast("dle_login_hash = '") - .substringBefore("';") + dle_login_hash = + document + .body() + .selectFirst("script")!! + .html() + .substringAfterLast("dle_login_hash = '") + .substringBefore("';") val ajax = - fromPlaylistAjax( - "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&user_hash=$dle_login_hash" - ) + fromPlaylistAjax( + "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&user_hash=$dle_login_hash") if (!ajax.isNullOrEmpty()) { // Ajax list ajax - .groupBy { it.name } - .forEach { episodes -> // Group by name - episodes.value.forEach lit@{ - // UFDub player, drop - if (it.urls.url.contains("video.ufdub")) return@lit + .groupBy { it.name } + .forEach { episodes -> // Group by name + episodes.value.forEach lit@{ + // UFDub player, drop + if (it.urls.url.contains("video.ufdub")) return@lit - if (it.urls.isDub) { - dubEpisodes.add( - Episode( - "${it.name}, $id, ${it.urls.isDub}", - it.name, - episode = it.numberEpisode - ) - ) - } else { - subEpisodes.add( - Episode( - "${it.name}, $id, ${it.urls.isDub}", - it.name, - episode = it.numberEpisode - ) - ) + if (it.urls.isDub) { + dubEpisodes.add( + Episode( + "${it.name}, $id, ${it.urls.isDub}", it.name, episode = it.numberEpisode)) + } else { + subEpisodes.add( + Episode( + "${it.name}, $id, ${it.urls.isDub}", it.name, episode = it.numberEpisode)) + } } } - } } else { document.select("script").map { script -> if (script.data().contains("RalodePlayer.init(")) { @@ -156,12 +147,11 @@ class AnitubeinuaProvider : MainAPI() { varEpisodeNumber = episodesList.last().episodeNumber?.plus(1) } dubEpisodes.add( - Episode( - "$varEpisodeNumber, $url", - episode.episodeName, - episode = varEpisodeNumber, - ) - ) + Episode( + "$varEpisodeNumber, $url", + episode.episodeName, + episode = varEpisodeNumber, + )) } } } @@ -182,89 +172,84 @@ class AnitubeinuaProvider : MainAPI() { // It works when I click to view the series override suspend fun loadLinks( - data: String, // (Ajax) Name, id title, isDub | (Two) Episode name, url title - isCasting: Boolean, - subtitleCallback: (SubtitleFile) -> Unit, - callback: (ExtractorLink) -> Unit + data: String, // (Ajax) Name, id title, isDub | (Two) Episode name, url title + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit ): Boolean { val dataList = data.split(", ") // Log.d("CakesTwix-Debug", data) if (dataList[1].toIntOrNull() != null) { // Its ajax list val ajax = - fromPlaylistAjax( - "$mainUrl/engine/ajax/playlists.php?news_id=${dataList[1]}&xfield=playlist&user_hash=$dle_login_hash" - ) + fromPlaylistAjax( + "$mainUrl/engine/ajax/playlists.php?news_id=${dataList[1]}&xfield=playlist&user_hash=$dle_login_hash") // Filter by name and isDub ajax - ?.filter { it.name == dataList[0] } - ?.filter { it.urls.isDub == dataList[2].toBoolean() } - ?.forEach { - // Get m3u8 url - with(it) { - when { - it.urls.url.contains("https://tortuga.wtf/vod/") -> { - M3u8Helper.generateM3u8( - source = "${it.urls.playerName} (${it.urls.name})", - streamUrl = AshdiExtractor().ParseM3U8(this.urls.url), - referer = "https://tortuga.wtf/" - ) - .forEach(callback) - } - it.urls.url.contains("https://ashdi.vip/vod") -> { - M3u8Helper.generateM3u8( - source = "${it.urls.playerName} (${it.urls.name})", - streamUrl = AshdiExtractor().ParseM3U8(this.urls.url), - referer = "https://qeruya.cyou" - ) - .forEach(callback) - } - it.urls.url.contains("https://www.udrop.com") -> { - callback.invoke( - ExtractorLink( - this.urls.url, - name = "${it.urls.playerName} (${it.urls.name})", - this.urls.url, - "", - 0, - isM3u8 = false, - ) - ) - } - it.urls.url.contains("https://csst.online/embed/") || it.urls.url.contains("https://monstro.site/embed/") -> { - csstExtractor().ParseUrl(it.urls.url).split(",").forEach { csstUrl - -> - callback.invoke( - ExtractorLink( - this.urls.url, - name = "${it.urls.playerName} (${it.urls.name}) ${csstUrl.substringBefore("]").drop(1)}", - csstUrl.substringAfter("]"), - "", - 0, - isM3u8 = false, - ) - ) + ?.filter { it.name == dataList[0] } + ?.filter { it.urls.isDub == dataList[2].toBoolean() } + ?.forEach { + // Get m3u8 url + with(it) { + when { + it.urls.url.contains("https://tortuga.wtf/vod/") -> { + M3u8Helper.generateM3u8( + source = "${it.urls.playerName} (${it.urls.name})", + streamUrl = AshdiExtractor().ParseM3U8(this.urls.url), + referer = "https://tortuga.wtf/") + .forEach(callback) } - } - it.urls.url.contains("https://www.mp4upload.com/") -> { - Mp4Upload().getUrl(it.urls.url)?.forEach { extlink -> - callback.invoke( - ExtractorLink( - extlink.source, - "${it.urls.playerName} (${it.urls.name})", - extlink.url, - extlink.referer, - extlink.quality, - extlink.type, - extlink.headers, - ) - ) + it.urls.url.contains("https://ashdi.vip/vod") -> { + M3u8Helper.generateM3u8( + source = "${it.urls.playerName} (${it.urls.name})", + streamUrl = AshdiExtractor().ParseM3U8(this.urls.url), + referer = "https://qeruya.cyou") + .forEach(callback) } + it.urls.url.contains("https://www.udrop.com") -> { + callback.invoke( + ExtractorLink( + this.urls.url, + name = "${it.urls.playerName} (${it.urls.name})", + this.urls.url, + "", + 0, + isM3u8 = false, + )) + } + it.urls.url.contains("https://csst.online/embed/") || + it.urls.url.contains("https://monstro.site/embed/") -> { + csstExtractor().ParseUrl(it.urls.url).split(",").forEach { csstUrl -> + callback.invoke( + ExtractorLink( + this.urls.url, + name = + "${it.urls.playerName} (${it.urls.name}) ${csstUrl.substringBefore("]").drop(1)}", + csstUrl.substringAfter("]"), + "", + 0, + isM3u8 = false, + )) + } + } + it.urls.url.contains("https://www.mp4upload.com/") -> { + Mp4Upload().getUrl(it.urls.url)?.forEach { extlink -> + callback.invoke( + ExtractorLink( + extlink.source, + "${it.urls.playerName} (${it.urls.name})", + extlink.url, + extlink.referer, + extlink.quality, + extlink.type, + extlink.headers, + )) + } + } + else -> {} } - else -> {} } } - } } else { val document = app.get(dataList[1]).document document.select("script").map { script -> @@ -286,59 +271,55 @@ class AnitubeinuaProvider : MainAPI() { when { contains("https://tortuga.wtf/vod/") -> { M3u8Helper.generateM3u8( - source = dub.playerName, - streamUrl = AshdiExtractor().ParseM3U8(this), - referer = "https://tortuga.wtf/" - ) - .forEach(callback) + source = dub.playerName, + streamUrl = AshdiExtractor().ParseM3U8(this), + referer = "https://tortuga.wtf/") + .forEach(callback) } contains("https://ashdi.vip/vod") -> { M3u8Helper.generateM3u8( - source = dub.playerName, - streamUrl = AshdiExtractor().ParseM3U8(this), - referer = "https://qeruya.cyou" - ) - .forEach(callback) + source = dub.playerName, + streamUrl = AshdiExtractor().ParseM3U8(this), + referer = "https://qeruya.cyou") + .forEach(callback) } contains("https://www.udrop.com") -> { callback.invoke( - ExtractorLink( - dub.playerName, - name = dub.playerName, - this, - "", - 0, - isM3u8 = false, - ) - ) + ExtractorLink( + dub.playerName, + name = dub.playerName, + this, + "", + 0, + isM3u8 = false, + )) } - contains("https://monstro.site/embed/") || contains("https://csst.online/embed/") -> { + contains("https://monstro.site/embed/") || + contains("https://csst.online/embed/") -> { csstExtractor().ParseUrl(this).split(",").forEach { callback.invoke( - ExtractorLink( - dub.playerName, - name = "${dub.playerName.replace("\"", "")} ${it.substringBefore("]").drop(1)}", - it.substringAfter("]"), - "", - 0, - isM3u8 = false - ) - ) + ExtractorLink( + dub.playerName, + name = + "${dub.playerName.replace("\"", "")} ${it.substringBefore("]").drop(1)}", + it.substringAfter("]"), + "", + 0, + isM3u8 = false)) } } contains("https://www.mp4upload.com/") -> { Mp4Upload().getUrl(this)?.forEach { extlink -> callback.invoke( - ExtractorLink( - extlink.source, - dub.playerName, - extlink.url, - extlink.referer, - extlink.quality, - extlink.type, - extlink.headers, - ) - ) + ExtractorLink( + extlink.source, + dub.playerName, + extlink.url, + extlink.referer, + extlink.quality, + extlink.type, + extlink.headers, + )) } } else -> {} @@ -433,17 +414,15 @@ class AnitubeinuaProvider : MainAPI() { } returnEpisodes.add( - Ajax( - episodeId, - element.text(), - Link( - isDub, - url, - audio.toString(), - playerName, - ) - ) - ) + Ajax( + episodeId, + element.text(), + Link( + isDub, + url, + audio.toString(), + playerName, + ))) } return returnEpisodes.toList() @@ -451,14 +430,13 @@ class AnitubeinuaProvider : MainAPI() { private fun fromVideoContructor(script: Element): List { 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) - .replace("\",\"", ",,,") - .split(",,,") + (playerScriptRawJson.substringBefore("],") + "]") + .dropLast(1) + .drop(1) + .replace("\",\"", ",,,") + .split(",,,") // val numberOfEpisodesInt = playerScriptRawJson.substringAfterLast(",").toIntOrNull() val jsonEpisodes = tryParseJson>>(playerEpisodesRawJson)!! @@ -468,13 +446,11 @@ class AnitubeinuaProvider : MainAPI() { val playerName = decode(playerNamesArray[index]) episode.forEach { episodes.add( - videoConstructor( - playerName, - it.name, - extractIntFromString(it.name), - Jsoup.parse(it.code).select("iframe").attr("src") - ) - ) + videoConstructor( + playerName, + it.name, + extractIntFromString(it.name), + Jsoup.parse(it.code).select("iframe").attr("src"))) // Log.d("load-debug", "$playerName ${it.name}") } } @@ -489,4 +465,4 @@ class AnitubeinuaProvider : MainAPI() { return value.value.toIntOrNull() } -} +} \ No newline at end of file