package com.lagradost.cloudstream3.movieproviders import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.Qualities import org.jsoup.Jsoup class HDMProvider : MainAPI() { override val name: String get() = "HD Movies" override val mainUrl: String get() = "https://hdm.to" override fun search(query: String): ArrayList { val url = "$mainUrl/search/$query" val response = khttp.get(url) val document = Jsoup.parse(response.text) val items = document.select("div.col-md-2 > article > a") if (items.isEmpty()) return ArrayList() val returnValue = ArrayList() for (i in items) { val href = i.attr("href") val data = i.selectFirst("> div.item") val img = data.selectFirst("> img").attr("src") val name = data.selectFirst("> div.movie-details").text() returnValue.add(MovieSearchResponse(name, href, href, this.name, TvType.Movie, img, null)) } return returnValue } override fun loadLinks(data: String, isCasting: Boolean, callback: (ExtractorLink) -> Unit): Boolean { if (data == "") return false val slug = ".*/(.*?)\\.mp4".toRegex().find(data)?.groupValues?.get(1) ?: return false val response = khttp.get(data) val key = "playlist\\.m3u8(.*?)\"".toRegex().find(response.text)?.groupValues?.get(1) ?: return false callback.invoke(ExtractorLink(this.name, this.name, "https://hls.1o.to/vod/$slug/playlist.m3u8$key", "", Qualities.HD.value, true)) return true } override fun load(slug: String): LoadResponse? { val response = khttp.get(slug) val document = Jsoup.parse(response.text) val title = document.selectFirst("h2.movieTitle").text() val poster = document.selectFirst("div.post-thumbnail > img").attr("src") val descript = document.selectFirst("div.synopsis > p").text() val year = document.select("div.movieInfoAll > div.row > div.col-md-6")?.get(1)?.selectFirst("> p > a")?.text() ?.toIntOrNull() val data = "src/player/\\?v=(.*?)\"".toRegex().find(response.text)?.groupValues?.get(1) ?: return null return MovieLoadResponse(title, slug, this.name, TvType.Movie, "$mainUrl/src/player/?v=$data", poster, year, descript, null) } }