package com.lagradost import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.loadExtractor import org.jsoup.Jsoup import org.jsoup.nodes.Element import java.net.URI class Ask4MovieProvider : MainAPI() { override var mainUrl = "https://ask4movie.mx" override var name = "Ask4Movie" override val supportedTypes = setOf(TvType.TvSeries, TvType.Movie, TvType.AnimeMovie) override val hasMainPage = true private fun Element.toSearchResponse(): MovieSearchResponse { // style="background-image: url(https://ask4movie.me/wp-content/uploads/2022/08/Your-Name.-2016-cover.jpg)" val posterRegex = Regex("""url\((.*?)\)""") val poster = posterRegex.find(this.attr("style"))?.groupValues?.get(1) val a = this.select("a") val href = a.attr("href") val title = a.text().trim() // Title (2022) -> 2022 val year = Regex("""\((\d{4})\)$""").find(title)?.groupValues?.getOrNull(1)?.toIntOrNull() return MovieSearchResponse( title, href, this@Ask4MovieProvider.name, TvType.Movie, poster, year, null, null, null ) } // Used in movies/single seasons to get recommendations private fun Element.articleToSearchResponse(): MovieSearchResponse { val poster = this.select("img").attr("src") val a = this.select("a") val href = a.attr("href") val title = a.attr("title") // Title (2022) -> 2022 val year = Regex("""\((\d{4})\)$""").find(title)?.groupValues?.getOrNull(1)?.toIntOrNull() return MovieSearchResponse( title, href, this@Ask4MovieProvider.name, TvType.Movie, poster, year, null, null, null ) } override suspend fun search(query: String): List { val url = "$mainUrl/?s=$query" val doc = app.post( url, // data = mapOf("np_asl_data" to "customset[]=post&customset[]=ct_channel&customset[]=post&customset[]=post&customset[]=post&customset[]=post&asl_gen[]=title&asl_gen[]=exact&qtranslate_lang=0&filters_initial=1&filters_changed=0") ).document return doc.select("div.item").map { it.toSearchResponse() } } private fun getIframe(html: String): String? { val data = Regex("""