From 4ff296dea592ee5356c0dbe6c8e81d742c7fb711 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:44:52 +0200 Subject: [PATCH] Add Ask4movie --- Ask4Movie/build.gradle.kts | 27 ++ Ask4Movie/src/main/AndroidManifest.xml | 2 + .../kotlin/com/lagradost/Ask4MoviePlugin.kt | 14 ++ .../kotlin/com/lagradost/Ask4MovieProvider.kt | 237 ++++++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 Ask4Movie/build.gradle.kts create mode 100644 Ask4Movie/src/main/AndroidManifest.xml create mode 100644 Ask4Movie/src/main/kotlin/com/lagradost/Ask4MoviePlugin.kt create mode 100644 Ask4Movie/src/main/kotlin/com/lagradost/Ask4MovieProvider.kt diff --git a/Ask4Movie/build.gradle.kts b/Ask4Movie/build.gradle.kts new file mode 100644 index 0000000..0315eba --- /dev/null +++ b/Ask4Movie/build.gradle.kts @@ -0,0 +1,27 @@ +// use an integer for version numbers +version = 3 + + +cloudstream { + language = "en" + // All of these properties are optional, you can safely remove them + +// description = "Uses TMDB" + authors = listOf("Blatzar") + + /** + * Status int as the following: + * 0: Down + * 1: Ok + * 2: Slow + * 3: Beta only + * */ + status = 1 // will be 3 if unspecified + tvTypes = listOf( + "TvSeries", + "Movie", + "AnimeMovie" + ) + + iconUrl = "https://www.google.com/s2/favicons?domain=ask4movie.mx&sz=%size%" +} \ No newline at end of file diff --git a/Ask4Movie/src/main/AndroidManifest.xml b/Ask4Movie/src/main/AndroidManifest.xml new file mode 100644 index 0000000..29aec9d --- /dev/null +++ b/Ask4Movie/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MoviePlugin.kt b/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MoviePlugin.kt new file mode 100644 index 0000000..58d5351 --- /dev/null +++ b/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MoviePlugin.kt @@ -0,0 +1,14 @@ + +package com.lagradost + +import com.lagradost.cloudstream3.plugins.CloudstreamPlugin +import com.lagradost.cloudstream3.plugins.Plugin +import android.content.Context + +@CloudstreamPlugin +class Ask4MoviePlugin: Plugin() { + override fun load(context: Context) { + // All providers should be added in this manner. Please don't edit the providers list directly. + registerMainAPI(Ask4MovieProvider()) + } +} \ No newline at end of file diff --git a/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MovieProvider.kt b/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MovieProvider.kt new file mode 100644 index 0000000..05d7870 --- /dev/null +++ b/Ask4Movie/src/main/kotlin/com/lagradost/Ask4MovieProvider.kt @@ -0,0 +1,237 @@ +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("""