From c8ef8de606fa8493d0c7cc1da49038b1f50dee56 Mon Sep 17 00:00:00 2001 From: CakesTwix Date: Sun, 21 Jan 2024 14:07:56 +0200 Subject: [PATCH] uakino: Reformat code --- .../kotlin/com/lagradost/UakinoProvider.kt | 277 ++++++++++-------- 1 file changed, 156 insertions(+), 121 deletions(-) diff --git a/UakinoProvider/src/main/kotlin/com/lagradost/UakinoProvider.kt b/UakinoProvider/src/main/kotlin/com/lagradost/UakinoProvider.kt index 3f6074d..3efdc77 100644 --- a/UakinoProvider/src/main/kotlin/com/lagradost/UakinoProvider.kt +++ b/UakinoProvider/src/main/kotlin/com/lagradost/UakinoProvider.kt @@ -1,14 +1,13 @@ package com.lagradost -import android.util.Log import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.LoadResponse.Companion.addActors import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.M3u8Helper +import java.util.* import org.jsoup.Jsoup import org.jsoup.nodes.Element -import java.util.* class UakinoProvider : MainAPI() { @@ -18,50 +17,46 @@ class UakinoProvider : MainAPI() { override val hasMainPage = true override var lang = "uk" override val hasDownloadSupport = true - override val supportedTypes = setOf( - TvType.Movie, - TvType.TvSeries, - TvType.Anime - ) + override val supportedTypes = setOf(TvType.Movie, TvType.TvSeries, TvType.Anime) // Sections - override val mainPage = mainPageOf( - "$mainUrl/filmy/page/" to "Фільми", - "$mainUrl/seriesss/page/" to "Серіали", - "$mainUrl/seriesss/doramy/page/" to "Дорами", - "$mainUrl/animeukr/page/" to "Аніме", - "$mainUrl/cartoon/page/" to "Мультфільми", - "$mainUrl/cartoon/cartoonseries/page/" to "Мультсеріали", - ) + override val mainPage = + mainPageOf( + "$mainUrl/filmy/page/" to "Фільми", + "$mainUrl/seriesss/page/" to "Серіали", + "$mainUrl/seriesss/doramy/page/" to "Дорами", + "$mainUrl/animeukr/page/" to "Аніме", + "$mainUrl/cartoon/page/" to "Мультфільми", + "$mainUrl/cartoon/cartoonseries/page/" to "Мультсеріали", + ) val blackUrls = "(/news/)|(/franchise/)" - override suspend fun getMainPage( - page: Int, - request: MainPageRequest - ): HomePageResponse { + override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { val document = app.get(request.data + page).document - val home = document.select("div.owl-item, div.movie-item") - .filterNot { el -> el.select("a.movie-title, a.full-movie").attr("href").contains(Regex(blackUrls)) } - .map { - Log.d("CakesTwix-Debug", it.select("a.movie-title, a.full-movie").attr("href")) - it.toSearchResponse() - } + val home = + document + .select("div.owl-item, div.movie-item") + .filterNot { el -> + el.select("a.movie-title, a.full-movie").attr("href").contains(Regex(blackUrls)) + } + .map { + // Log.d("CakesTwix-Debug", it.select("a.movie-title, a.full-movie").attr("href")) + it.toSearchResponse() + } return newHomePageResponse(request.name, home) } private fun Element.toSearchResponse(): SearchResponse { - val title = this.selectFirst("a.movie-title, div.full-movie-title")?.text()?.trim().toString() + val title = + this.selectFirst("a.movie-title, div.full-movie-title")?.text()?.trim().toString() val href = this.selectFirst("a.movie-title, a.full-movie")?.attr("href").toString() val posterUrl = fixUrlNull(this.selectFirst("img")?.attr("src")) - return newMovieSearchResponse(title, href, TvType.Movie) { - this.posterUrl = posterUrl - } - + return newMovieSearchResponse(title, href, TvType.Movie) { this.posterUrl = posterUrl } } private suspend fun Element.getSeasonInfo(): SearchResponse { - Log.d("CakesTwix-Debug", "getSeasonInfo: ${this.attr("href")}") + // Log.d("CakesTwix-Debug", "getSeasonInfo: ${this.attr("href")}") val document = app.get(this.attr("href")).document val title = document.selectFirst("h1 span.solototle")?.text()?.trim().toString() val poster = mainUrl + document.selectFirst("div.film-poster img")?.attr("src").toString() @@ -69,24 +64,27 @@ class UakinoProvider : MainAPI() { return newMovieSearchResponse(title, this.attr("href"), TvType.Movie) { this.posterUrl = poster } - } 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(" ", "+") + val document = + app.post( + url = mainUrl, + data = + mapOf( + "do" to "search", + "subaction" to "search", + "story" to query.replace(" ", "+") + ) ) - ).document + .document - return document.select("div.movie-item.short-item") - .filterNot { el -> el.select("a.movie-title, a.full-movie").attr("href").contains(Regex(blackUrls)) } - .map { - it.toSearchResponse() - } + return document + .select("div.movie-item.short-item") + .filterNot { el -> + el.select("a.movie-title, a.full-movie").attr("href").contains(Regex(blackUrls)) + } + .map { it.toSearchResponse() } } // Detailed information @@ -108,7 +106,9 @@ class UakinoProvider : MainAPI() { contains("Рік виходу:") -> year = metadata.select(".fi-desc").text().toInt() contains("Жанр:") -> tags = metadata.select(".fi-desc").text().split(" , ") contains("Актори:") -> actors = metadata.select(".fi-desc").text().split(", ") - contains("") -> rating = metadata.select(".fi-desc").text().substringBefore("/").toRatingInt() + contains("") -> + rating = + metadata.select(".fi-desc").text().substringBefore("/").toRatingInt() } // Log.d("CakesTwix-Debug", this) // Log.d("CakesTwix-Debug", metadata.select(".fi-desc").text()) @@ -118,43 +118,50 @@ class UakinoProvider : MainAPI() { // reversed need for check "Мультсеріали" // tags: Мультфільми , Мультсеріали // It's Cartoon, not Movie - var tvType = with(tags.reversed()){ - when{ - contains("Повнометражне аніме") -> TvType.AnimeMovie - contains("Мультсеріали") -> TvType.Cartoon - contains("Мультфільми") -> TvType.Movie - contains("Багатосерійне аніме") -> TvType.Anime - contains("Дорами") -> TvType.AsianDrama - else -> TvType.Others + var tvType = + with(tags.reversed()) { + when { + contains("Повнометражне аніме") -> TvType.AnimeMovie + contains("Мультсеріали") -> TvType.Cartoon + contains("Мультфільми") -> TvType.Movie + contains("Багатосерійне аніме") -> TvType.Anime + contains("Дорами") -> TvType.AsianDrama + else -> TvType.Others + } } - } // Log.d("CakesTwix-Debug", tvType.toString()) if (tvType == TvType.Others) { - tvType = if (url.contains(Regex("(/anime-series)|(/seriesss)|(/cartoonseries)"))) TvType.TvSeries else TvType.Movie + tvType = + if (url.contains(Regex("(/anime-series)|(/seriesss)|(/cartoonseries)"))) + TvType.TvSeries + else TvType.Movie } val description = document.selectFirst("div[itemprop=description]")?.text()?.trim() val trailer = document.selectFirst("iframe#pre")?.attr("data-src") // Add seasons to recommendations - val recommendations = document.select(".seasons li a").map{ - it.getSeasonInfo() - }.toMutableList() + val recommendations = + document.select(".seasons li a").map { it.getSeasonInfo() }.toMutableList() // Other recommendations - recommendations += document.select(".related-item").map { - it.toSearchResponse() - } + recommendations += document.select(".related-item").map { it.toSearchResponse() } // Return to app // Parse Episodes as Series return if (tvType != TvType.Movie && tvType != TvType.AnimeMovie) { val id = url.split("/").last().split("-").first() val episodes = - app.get("$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}") - .parsedSafe()?.response.let { - Jsoup.parse(it.toString()).select("div.playlists-videos li").mapNotNull { eps -> - val href = "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}" + app.get( + "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}" + ) + .parsedSafe() + ?.response + .let { + Jsoup.parse(it.toString()).select("div.playlists-videos li").mapNotNull { + eps -> + val href = + "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}" val name = eps.text().trim() // Серія 1 if (href.isNotEmpty()) { Episode( @@ -166,7 +173,7 @@ class UakinoProvider : MainAPI() { } } } - newTvSeriesLoadResponse(title, url, tvType, episodes.distinctBy{ it.name }) { + newTvSeriesLoadResponse(title, url, tvType, episodes.distinctBy { it.name }) { this.posterUrl = poster this.year = year this.plot = description @@ -199,36 +206,43 @@ class UakinoProvider : MainAPI() { ): Boolean { val dataList = data.split(",") // TODO: OPTIMIZE code!!! Remove this shitty code as soon as possible!!!!!! - if(dataList.size == 1){ + if (dataList.size == 1) { val id = data.split("/").last().split("-").first() - val responseGet = app.get("$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}").parsedSafe() + val responseGet = + app.get( + "$mainUrl/engine/ajax/playlists.php?news_id=$id&xfield=playlist&time=${Date().time}" + ) + .parsedSafe() if (responseGet?.success == true) { // Its serial responseGet.response?.let { - Jsoup.parse(it).select("div.playlists-videos li") - .mapNotNull { eps -> - var href = eps.attr("data-file") // ashdi - // Can be without https: - if (!href.contains("https://")) { - href = "https:$href" - } - val dub = eps.attr("data-voice") // FanWoxUA - - // Get m3u from player script - app.get(href, referer = "$mainUrl/").document.select("script") - .map { script -> - if (script.data().contains("var player = new Playerjs({")) { - val m3uLink = script.data().substringAfterLast("file:\"") - .substringBefore("\",") - - // Add as source - M3u8Helper.generateM3u8( - source = dub, - streamUrl = m3uLink, - referer = "https://ashdi.vip/" - ).forEach(callback) - } - } + Jsoup.parse(it).select("div.playlists-videos li").mapNotNull { eps -> + var href = eps.attr("data-file") // ashdi + // Can be without https: + if (!href.contains("https://")) { + href = "https:$href" } + val dub = eps.attr("data-voice") // FanWoxUA + + // Get m3u from player script + app.get(href, referer = "$mainUrl/").document.select("script").map { script + -> + if (script.data().contains("var player = new Playerjs({")) { + val m3uLink = + script + .data() + .substringAfterLast("file:\"") + .substringBefore("\",") + + // Add as source + M3u8Helper.generateM3u8( + source = dub, + streamUrl = m3uLink, + referer = "https://ashdi.vip/" + ) + .forEach(callback) + } + } + } } } else { // Its maybe film @@ -236,16 +250,24 @@ class UakinoProvider : MainAPI() { val iframeUrl = document.selectFirst("iframe#pre")?.attr("src") // Get m3u from player script if (iframeUrl != null) { - app.get(iframeUrl, referer = "$mainUrl/").document.select("script").map { script -> + app.get(iframeUrl, referer = "$mainUrl/").document.select("script").map { script + -> if (script.data().contains("var player = new Playerjs({")) { - val m3uLink = script.data().substringAfterLast("file:\"").substringBefore("\",") + val m3uLink = + script.data().substringAfterLast("file:\"").substringBefore("\",") // Add as source M3u8Helper.generateM3u8( - source = document.selectFirst("h1 span.solototle")?.text()?.trim().toString(), + source = + document + .selectFirst("h1 span.solototle") + ?.text() + ?.trim() + .toString(), streamUrl = m3uLink, referer = "https://ashdi.vip/" - ).forEach(callback) + ) + .forEach(callback) } } } @@ -254,30 +276,38 @@ class UakinoProvider : MainAPI() { } val responseGet = app.get(dataList[0]).parsedSafe() // ajax link - if (responseGet?.success == true){ // Its serial + if (responseGet?.success == true) { // Its serial responseGet?.response?.let { - Jsoup.parse(it).select("div.playlists-videos li:contains(${dataList[1]})").mapNotNull { eps -> - var href = eps.attr("data-file") // ashdi - // Can be without https: - if (! href.contains("https://")) { - href = "https:$href" - } - val dub = eps.attr("data-voice") // FanWoxUA + Jsoup.parse(it) + .select("div.playlists-videos li:contains(${dataList[1]})") + .mapNotNull { eps -> + var href = eps.attr("data-file") // ashdi + // Can be without https: + if (!href.contains("https://")) { + href = "https:$href" + } + val dub = eps.attr("data-voice") // FanWoxUA - // Get m3u from player script - app.get(href, referer = "$mainUrl/").document.select("script").map { script -> - if (script.data().contains("var player = new Playerjs({")) { - val m3uLink = script.data().substringAfterLast("file:\"").substringBefore("\",") + // Get m3u from player script + app.get(href, referer = "$mainUrl/").document.select("script").map { script + -> + if (script.data().contains("var player = new Playerjs({")) { + val m3uLink = + script + .data() + .substringAfterLast("file:\"") + .substringBefore("\",") - // Add as source - M3u8Helper.generateM3u8( - source = dub, - streamUrl = m3uLink, - referer = "https://ashdi.vip/" - ).forEach(callback) + // Add as source + M3u8Helper.generateM3u8( + source = dub, + streamUrl = m3uLink, + referer = "https://ashdi.vip/" + ) + .forEach(callback) + } } } - } } } else { // Its maybe film @@ -287,20 +317,26 @@ class UakinoProvider : MainAPI() { if (iframeUrl != null) { app.get(iframeUrl, referer = "$mainUrl/").document.select("script").map { script -> if (script.data().contains("var player = new Playerjs({")) { - val m3uLink = script.data().substringAfterLast("file:\"").substringBefore("\",") + val m3uLink = + script.data().substringAfterLast("file:\"").substringBefore("\",") // Add as source M3u8Helper.generateM3u8( - source = document.selectFirst("h1 span.solototle")?.text()?.trim().toString(), + source = + document + .selectFirst("h1 span.solototle") + ?.text() + ?.trim() + .toString(), streamUrl = m3uLink, referer = "https://ashdi.vip/" - ).forEach(callback) + ) + .forEach(callback) } } } } - return true } @@ -308,5 +344,4 @@ class UakinoProvider : MainAPI() { val success: Boolean?, val response: String, ) - -} \ No newline at end of file +}