From 7d1c638d6745415e84104b54b97a9f611ee84b9f Mon Sep 17 00:00:00 2001 From: Arjix <53124886+ArjixWasTaken@users.noreply.github.com> Date: Tue, 24 Aug 2021 21:40:17 +0300 Subject: [PATCH] Create AnimeFlickProvider.kt --- .../animeproviders/AnimeFlickProvider.kt | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt new file mode 100644 index 00000000..bc8e8db8 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt @@ -0,0 +1,119 @@ +package com.lagradost.cloudstream3.animeproviders + +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.getQualityFromName +import org.jsoup.Jsoup +import java.util.* + + +class AnimeFlickProvider : MainAPI() { + companion object { + fun getType(t: String): TvType { + return if (t.contains("OVA") || t.contains("Special")) TvType.ONA + else if (t.contains("Movie")) TvType.AnimeMovie + else TvType.Anime + } + } + + override val mainUrl: String + get() = "https://animeflick.net" + override val name: String + get() = "AnimeFlick" + override val hasQuickSearch: Boolean + get() = false + override val hasMainPage: Boolean + get() = false + + override val supportedTypes: Set + get() = setOf( + TvType.AnimeMovie, + TvType.Anime, + TvType.ONA + ) + + + override fun search(query: String): ArrayList { + val link = "https://animeflick.net/search.php?search=$query" + val html = khttp.get(link).text + val doc = Jsoup.parse(html) + + return ArrayList(doc.select(".row.mt-2").map { + val href = mainUrl + it.selectFirst("a").attr("href") + val title = it.selectFirst("h5 > a").text() + val poster = mainUrl + it.selectFirst("img").attr("src").replace("70x110", "225x320") + AnimeSearchResponse( + title, + href, + this.name, + getType(title), + poster, + null, + null, + EnumSet.of(DubStatus.Subbed), + null, + null + ) + }) + } + + override fun load(url: String): LoadResponse { + val html = khttp.get(url).text + val doc = Jsoup.parse(html) + + val poster = mainUrl + doc.selectFirst("img.rounded").attr("src") + val title = doc.selectFirst("h2.title").text() + + val year = Regex("""(\d{4})""").find(doc.selectFirst(".trending-year").text())!!.destructured.component1().toIntOrNull() + val description = doc.selectFirst("p").text() + + val genres = doc.select("a[href*=\"genre-\"]").map { it.text() } + + val episodes = doc.select("#collapseOne .block-space > .row > div:nth-child(2)").map { + val name = it.selectFirst("a").text() + val link = mainUrl + it.selectFirst("a").attr("href") + AnimeEpisode(link, name) + }.reversed() + + return AnimeLoadResponse( + title, + null, + title, + url, + this.name, + getType(title), + poster, + year, + null, + episodes, + ShowStatus.Ongoing, + description, + genres + ) + } + + override fun loadLinks( + data: String, + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + val html = khttp.get(data).text + + val episodeRegex = Regex("""(https://.*?\.mp4)""") + episodeRegex.findAll(html).map { + it.value + }.toList().forEach { + callback( + ExtractorLink( + "Animeflick", + "Animeflick - Auto", + it, + "", + getQualityFromName("1080") + ) + ) + } + return true + } +}