diff --git a/KlonTVProvider/build.gradle.kts b/KlonTVProvider/build.gradle.kts new file mode 100644 index 0000000..1c6bc61 --- /dev/null +++ b/KlonTVProvider/build.gradle.kts @@ -0,0 +1,28 @@ +// use an integer for version numbers +version = 1 + + +cloudstream { + language = "uk" + // All of these properties are optional, you can safely remove them + + description = "Команда Klon.TV створила безкоштовний онлайн-сервіс, щоб кожен наш глядач з легкістю та без зайвих суперечок вибрав цікавий фільм, або одразу продовжив дивитися улюблений серіал. Минула та пора, коли треба стежити за афішами твого міста, і вгадувати якість майбутньої стрічки. Також вже можна забути про трату часу на довгу дорогу в кінотеатр, півгодинного перегляду трейлерів перед показом, сусідами, що чавкають, яким не зрозуміти, що фільм треба іноді й слухати, а не тільки дивитися. Вибравши наш сервіс для перегляду фільмів онлайн безкоштовно, ви будете приємно здивовані: українське озвучення, перегляд без реєстрації, ніякої реклами на весь екран, і багато інших цікавих можливостей. Klon.TV - цінує кожного глядача, і зробить все можливе, щоб Ви до нас повернулися:)." + authors = listOf("CakesTwix") + + /** + * Status int as the following: + * 0: Down + * 1: Ok + * 2: Slow + * 3: Beta only + * */ + status = 1 // will be 3 if unspecified + tvTypes = listOf( + "Anime", + "TvSeries", + "Cartoon", + "Movie", + ) + + iconUrl = "https://www.google.com/s2/favicons?domain=klon.tv&sz=%size%" +} \ No newline at end of file diff --git a/KlonTVProvider/src/main/AndroidManifest.xml b/KlonTVProvider/src/main/AndroidManifest.xml new file mode 100644 index 0000000..29aec9d --- /dev/null +++ b/KlonTVProvider/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProvider.kt b/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProvider.kt new file mode 100644 index 0000000..a1ac6ad --- /dev/null +++ b/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProvider.kt @@ -0,0 +1,208 @@ +package com.lagradost + +import android.util.Log +import com.lagradost.models.PlayerJson +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId +import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId +import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.M3u8Helper +import org.jsoup.nodes.Element + +class KlonTVProvider : MainAPI() { + + // Basic Info + override var mainUrl = "https://klon.tv" + override var name = "KlonTV" + override val hasMainPage = true + override var lang = "uk" + override val hasDownloadSupport = true + override val supportedTypes = setOf( + TvType.Anime, + TvType.TvSeries, + TvType.Cartoon, + TvType.Movie, + ) + + // Sections + override val mainPage = mainPageOf( + "$mainUrl/serialy/page/" to "Серіали", + "$mainUrl/anime/page/" to "Аніме", + "$mainUrl/filmy/page/" to "Зарубіжні фільми", + "$mainUrl/multfilmy/page/" to "Мультфільми", + "$mainUrl/multserialy/page/" to "Мультсеріали", + ) + + // Main Page + private val animeSelector = ".short-news__slide-item" + private val titleSelector = ".card-link__style, .text-module__main" + private val hrefSelector = titleSelector + private val posterSelector = ".card-poster__img, .cover-image, .owl-carousel .owl-item img" + + // Load info + private val titleLoadSelector = ".seo-h1__position" + private val genresSelector = ".table-info__link" + private val yearSelector = ".table-info__link a" + private val playerSelector = "div.film-player iframe" + private val descriptionSelector = ".info-clamp__hid" + private val recommendationsSelector = ".related-news__small-card" + // private val ratingSelector = ".pmovie__subrating img" + + override suspend fun getMainPage( + page: Int, + request: MainPageRequest + ): HomePageResponse { + val document = app.get(request.data + page).document + + val home = document.select(animeSelector).map { + it.toSearchResponse() + } + return newHomePageResponse(request.name, home) + } + + private fun Element.toSearchResponse(): AnimeSearchResponse { + val title = this.selectFirst(titleSelector)?.text()?.trim().toString() + val href = this.selectFirst(hrefSelector)?.attr("href").toString() + val posterUrl = mainUrl + this.selectFirst(posterSelector)?.attr("data-src") + val status = this.select(".poster__label").text() + return newAnimeSearchResponse(title, href, TvType.Anime) { + this.posterUrl = posterUrl + addDubStatus(isDub = true) + } + + } + + 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 + + return document.select(animeSelector).map { + it.toSearchResponse() + } + } + + // Detailed information + override suspend fun load(url: String): LoadResponse { + val document = app.get(url).document + // Parse info + + val title = document.selectFirst(titleLoadSelector)?.text()?.trim().toString() + val poster = mainUrl + document.selectFirst(posterSelector)?.attr("data-src") + val tags = document.select(genresSelector).map { it.text() } + val year = document.selectFirst(yearSelector)?.text()?.toIntOrNull() + val playerUrl = document.select(playerSelector).attr("data-src") + + val tvType = with(tags){ + when{ + contains("Серіали") -> TvType.TvSeries + contains("Фільми") -> TvType.Movie + contains("Аніме") -> TvType.Anime + contains("Мультфільми") -> TvType.Movie + contains("Мультсеріали") -> TvType.TvSeries + else -> TvType.TvSeries + } + } + val description = document.selectFirst(descriptionSelector)?.text()?.trim() + + val recommendations = document.select(recommendationsSelector).map { + it.toSearchResponse() + } + + // Return to app + // Parse Episodes as Series + return if (tvType != TvType.Movie) { + var episodes: List = emptyList() + val playerRawJson = app.get(playerUrl).document.select("script").html() + .substringAfterLast("file:\'") + .substringBefore("\',") + + tryParseJson>(playerRawJson)?.map { dubs -> // Dubs + for(season in dubs.folder){ // Seasons + for(episode in season.folder){ // Episodes + episodes = episodes.plus( + Episode( + "${season.title}, ${episode.title}, $playerUrl", + episode.title, + season.title.replace(" Сезон ","").toIntOrNull(), + episode.title.replace("Серія ","").toIntOrNull(), + episode.poster + ) + ) + } + } + } + newAnimeLoadResponse(title, url, tvType) { + this.posterUrl = poster + this.year = year + this.plot = description + this.tags = tags + this.rating = rating + this.recommendations = recommendations + addEpisodes(DubStatus.Dubbed, episodes) + } + } else { // Parse as Movie. + newMovieLoadResponse(title, url, tvType, "$title, $playerUrl") { + this.posterUrl = poster + this.year = year + this.plot = description + this.tags = tags + this.rating = rating + this.recommendations = recommendations + } + } + } + + // It works when I click to view the series + override suspend fun loadLinks( + data: String, // (Serisl) [Season, Episode, Player Url] | (Film) [Title, Player Url] + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + val dataList = data.split(", ") + + // Its film, parse one m3u8 + if(dataList.size == 2){ + val m3u8Url = app.get(dataList[1]).document.select("script").html() + .substringAfterLast("file:\"") + .substringBefore("\",") + M3u8Helper.generateM3u8( + source = dataList[0], + streamUrl = m3u8Url, + referer = "https://tortuga.wtf/" + ).forEach(callback) + + return true + } + + val playerRawJson = app.get(dataList[2]).document.select("script").html() + .substringAfterLast("file:\'") + .substringBefore("\',") + + tryParseJson>(playerRawJson)?.map { dubs -> // Dubs + for(season in dubs.folder){ // Seasons + if(season.title == dataList[0]){ + for(episode in season.folder){ // Episodes + if(episode.title == dataList[1]){ + // Add as source + M3u8Helper.generateM3u8( + source = dubs.title, + streamUrl = episode.file, + referer = "https://tortuga.wtf/" + ).forEach(callback) + } + } + } + } + } + return true + } + +} \ No newline at end of file diff --git a/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProviderPlugin.kt b/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProviderPlugin.kt new file mode 100644 index 0000000..1eadebe --- /dev/null +++ b/KlonTVProvider/src/main/kotlin/com/lagradost/KlonTVProviderPlugin.kt @@ -0,0 +1,13 @@ +package com.lagradost + +import com.lagradost.cloudstream3.plugins.CloudstreamPlugin +import com.lagradost.cloudstream3.plugins.Plugin +import android.content.Context + +@CloudstreamPlugin +class KlonTVProviderPlugin: Plugin() { + override fun load(context: Context) { + // All providers should be added in this manner. Please don't edit the providers list directly. + registerMainAPI(KlonTVProvider()) + } +} \ No newline at end of file diff --git a/KlonTVProvider/src/main/kotlin/com/lagradost/Tracker.kt b/KlonTVProvider/src/main/kotlin/com/lagradost/Tracker.kt new file mode 100644 index 0000000..5c33563 --- /dev/null +++ b/KlonTVProvider/src/main/kotlin/com/lagradost/Tracker.kt @@ -0,0 +1,58 @@ +package com.lagradost + +import android.util.Log +import com.lagradost.cloudstream3.app + +class Tracker { + suspend fun getTracker(title: String?, type: String?, year: Int?): Tracker { + val res = app.get("https://api.consumet.org/meta/anilist/$title") + .parsedSafe()?.results?.find { media -> + Log.d("load-debug", media.toString()) + (media.title?.english.equals(title, true) || media.title?.romaji.equals( + title, + true + )) + } + return Tracker(res?.malId, res?.aniId, res?.image, res?.cover) + } + + data class Tracker( + val malId: Int? = null, + val aniId: String? = null, + val image: String? = null, + val cover: String? = null, + ) + + data class Title( + val romaji: String? = null, + val english: String? = null, + ) + + data class Results( + val aniId: String? = null, + val malId: Int? = null, + val title: Title? = null, + val releaseDate: Int? = null, + val type: String? = null, + val image: String? = null, + val cover: String? = null, + ) + + data class AniSearch( + val results: ArrayList? = arrayListOf(), + ) + + private data class Episodes( + val file: String? = null, + val title: String? = null, + val poster: String? = null, + ) + + private data class Home( + val table: String? = null, + ) + + private data class Search( + val mes: String? = null, + ) +} \ No newline at end of file diff --git a/KlonTVProvider/src/main/kotlin/com/lagradost/models/PlayerJson.kt b/KlonTVProvider/src/main/kotlin/com/lagradost/models/PlayerJson.kt new file mode 100644 index 0000000..163dd77 --- /dev/null +++ b/KlonTVProvider/src/main/kotlin/com/lagradost/models/PlayerJson.kt @@ -0,0 +1,22 @@ +package com.lagradost.models + +data class PlayerJson ( + + val title : String, + val folder : List +) + +data class Season ( + + val title : String, + val folder : List +) + +data class Episode ( + + val title : String, + val file : String, + val id : String, + val poster : String, + val subtitle : String, +)