forked from recloudstream/cloudstream
		
	2embed and Fixes on AllMoviesForYouProvider (#778)
* Provider and Fixes on AllMoviesForYouProvider.kt
This commit is contained in:
		
							parent
							
								
									aadc03c541
								
							
						
					
					
						commit
						6aaf24500e
					
				
					 5 changed files with 139 additions and 96 deletions
				
			
		|  | @ -81,6 +81,7 @@ object APIHolder { | |||
|         PinoyHDXyzProvider(), | ||||
|         PinoyMoviesEsProvider(), | ||||
|         TrailersTwoProvider(), | ||||
|         TwoEmbedProvider(), | ||||
|         DramaSeeProvider(), | ||||
|         WatchAsianProvider(), | ||||
|         KdramaHoodProvider(), | ||||
|  |  | |||
|  | @ -14,6 +14,11 @@ class Upstream: ZplayerV2() { | |||
|     override val mainUrl: String = "https://upstream.to" | ||||
| } | ||||
| 
 | ||||
| class Streamhub2: ZplayerV2() { | ||||
|     override val name: String = "Streamhub" //Here 'cause works | ||||
|     override val mainUrl: String = "https://streamhub.to" | ||||
| } | ||||
| 
 | ||||
| open class ZplayerV2 : ExtractorApi() { | ||||
|     override val name = "Zplayer V2" | ||||
|     override val mainUrl = "https://v2.zplayer.live" | ||||
|  |  | |||
|  | @ -1,17 +1,11 @@ | |||
| package com.lagradost.cloudstream3.movieproviders | ||||
| 
 | ||||
| import com.fasterxml.jackson.module.kotlin.readValue | ||||
| import com.lagradost.cloudstream3.* | ||||
| import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration | ||||
| import com.lagradost.cloudstream3.utils.AppUtils.toJson | ||||
| import com.lagradost.cloudstream3.mvvm.logError | ||||
| import com.lagradost.cloudstream3.utils.ExtractorLink | ||||
| import com.lagradost.cloudstream3.utils.Qualities | ||||
| import com.lagradost.cloudstream3.utils.getPostForm | ||||
| import com.lagradost.cloudstream3.utils.loadExtractor | ||||
| import okio.Buffer | ||||
| import org.jsoup.Jsoup | ||||
| import org.jsoup.nodes.Document | ||||
| import java.net.URLDecoder | ||||
| 
 | ||||
| class AllMoviesForYouProvider : MainAPI() { | ||||
|     companion object { | ||||
|  | @ -27,11 +21,44 @@ class AllMoviesForYouProvider : MainAPI() { | |||
|     // Fetching movies will not work if this link is outdated. | ||||
|     override val mainUrl = "https://allmoviesforyou.net" | ||||
|     override val name = "AllMoviesForYou" | ||||
|     override val hasMainPage = true | ||||
|     override val supportedTypes = setOf( | ||||
|         TvType.Movie, | ||||
|         TvType.TvSeries | ||||
|     ) | ||||
| 
 | ||||
|     override suspend fun getMainPage(): HomePageResponse { | ||||
|         val items = ArrayList<HomePageList>() | ||||
|         val soup = app.get(mainUrl).document | ||||
|         val urls = listOf( | ||||
|             Pair("Movies", "section[data-id=movies] article.TPost.B"), | ||||
|             Pair("TV Series", "section[data-id=series] article.TPost.B"), | ||||
|         ) | ||||
|         for ((name, element) in urls) { | ||||
|             try { | ||||
|                 val home = soup.select(element).map { | ||||
|                     val title = it.selectFirst("h2.title").text() | ||||
|                     val link = it.selectFirst("a").attr("href") | ||||
|                     TvSeriesSearchResponse( | ||||
|                         title, | ||||
|                         link, | ||||
|                         this.name, | ||||
|                         TvType.Movie, | ||||
|                         fixUrl(it.selectFirst("figure img").attr("data-src")), | ||||
|                         null, | ||||
|                         null, | ||||
|                     ) | ||||
|                 } | ||||
| 
 | ||||
|                 items.add(HomePageList(name, home)) | ||||
|             } catch (e: Exception) { | ||||
|                 logError(e) | ||||
|             } | ||||
|         } | ||||
|         if (items.size <= 0) throw ErrorLoadingException() | ||||
|         return HomePageResponse(items) | ||||
|     } | ||||
| 
 | ||||
|     override suspend fun search(query: String): List<SearchResponse> { | ||||
|         val url = "$mainUrl/?s=$query" | ||||
|         val document = app.get(url).document | ||||
|  | @ -58,23 +85,23 @@ class AllMoviesForYouProvider : MainAPI() { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun getLink(document: Document): List<String>? { | ||||
|         val list = ArrayList<String>() | ||||
|         Regex("iframe src=\"(.*?)\"").find(document.html())?.groupValues?.get(1)?.let { | ||||
|             list.add(it) | ||||
|         } | ||||
|         document.select("div.OptionBx")?.forEach { element -> | ||||
|             val baseElement = element.selectFirst("> a.Button") | ||||
|             val elementText = element.selectFirst("> p.AAIco-dns")?.text() | ||||
|             if (elementText == "Streamhub" || elementText == "Dood") { | ||||
|                 baseElement?.attr("href")?.let { href -> | ||||
|                     list.add(href) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return if (list.isEmpty()) null else list | ||||
|     } | ||||
| //    private fun getLink(document: Document): List<String>? { | ||||
| //         val list = ArrayList<String>() | ||||
| //         Regex("iframe src=\"(.*?)\"").find(document.html())?.groupValues?.get(1)?.let { | ||||
| //             list.add(it) | ||||
| //         } | ||||
| //         document.select("div.OptionBx")?.forEach { element -> | ||||
| //             val baseElement = element.selectFirst("> a.Button") | ||||
| //             val elementText = element.selectFirst("> p.AAIco-dns")?.text() | ||||
| //             if (elementText == "Streamhub" || elementText == "Dood") { | ||||
| //                 baseElement?.attr("href")?.let { href -> | ||||
| //                     list.add(href) | ||||
| //                 } | ||||
| //             } | ||||
| //         } | ||||
| // | ||||
| //         return if (list.isEmpty()) null else list | ||||
| //     } | ||||
| 
 | ||||
|     override suspend fun load(url: String): LoadResponse { | ||||
|         val type = getType(url) | ||||
|  | @ -144,14 +171,11 @@ class AllMoviesForYouProvider : MainAPI() { | |||
|                 rating | ||||
|             ) | ||||
|         } else { | ||||
|             val data = getLink(document) | ||||
|                 ?: throw ErrorLoadingException("No Links Found") | ||||
| 
 | ||||
|             return newMovieLoadResponse( | ||||
|                 title, | ||||
|                 url, | ||||
|                 type, | ||||
|                 data.filter { it != "about:blank" }.toJson() | ||||
|                 url | ||||
|             ) { | ||||
|                 posterUrl = backgroundPoster | ||||
|                 this.year = year?.toIntOrNull() | ||||
|  | @ -168,74 +192,17 @@ class AllMoviesForYouProvider : MainAPI() { | |||
|         subtitleCallback: (SubtitleFile) -> Unit, | ||||
|         callback: (ExtractorLink) -> Unit | ||||
|     ): Boolean { | ||||
|         if (data.startsWith("$mainUrl/episode/")) { | ||||
|             val response = app.get(data).text | ||||
|             getLink(Jsoup.parse(response))?.let { links -> | ||||
|                 for (link in links) { | ||||
|                     if (link == data) continue | ||||
|                     loadLinks(link, isCasting, subtitleCallback, callback) | ||||
|         val doc = app.get(data).document | ||||
|         val iframe = doc.select("body iframe").map { it.attr("src") } | ||||
|         iframe.apmap { id -> | ||||
|             if (id.contains("trembed")) { | ||||
|                 val soup = app.get(id).document | ||||
|                 soup.select("body iframe").map { | ||||
|                     val link = it.attr("src").replace("streamhub.to/d/","streamhub.to/e/") | ||||
|                     loadExtractor(link, data, callback) | ||||
|                 } | ||||
|             } else loadExtractor(id, data, callback) | ||||
|         } | ||||
|         return true | ||||
|     } | ||||
|             return false | ||||
|         } else if (data.startsWith(mainUrl) && data != mainUrl) { | ||||
|             val realDataUrl = URLDecoder.decode(data, "UTF-8") | ||||
|             if (data.contains("trdownload")) { | ||||
|                 val request = app.get(data) | ||||
|                 val requestUrl = request.url | ||||
|                 if (requestUrl.startsWith("https://streamhub.to/d/")) { | ||||
|                     val buffer = Buffer() | ||||
|                     val source = request.body?.source() | ||||
|                     var html = "" | ||||
|                     var tries = 0 // 20 tries = 163840 bytes = 0.16mb | ||||
| 
 | ||||
|                     while (source?.exhausted() == false && tries < 20) { | ||||
|                         // 8192 = max size | ||||
|                         source.read(buffer, 8192) | ||||
|                         tries += 1 | ||||
|                         html += buffer.readUtf8() | ||||
|                     } | ||||
|                     getPostForm(request.url, html)?.let { form -> | ||||
|                         val postDocument = Jsoup.parse(form) | ||||
| 
 | ||||
|                         postDocument.selectFirst("a.downloadbtn")?.attr("href")?.let { url -> | ||||
|                             callback( | ||||
|                                 ExtractorLink( | ||||
|                                     this.name, | ||||
|                                     this.name, | ||||
|                                     url, | ||||
|                                     mainUrl, | ||||
|                                     Qualities.Unknown.value | ||||
|                                 ) | ||||
|                             ) | ||||
|                         } | ||||
|                     } | ||||
|                 } else if (requestUrl.startsWith("https://dood")) { | ||||
|                     loadExtractor(requestUrl, null, callback) | ||||
|                 } else { | ||||
|                     callback( | ||||
|                         ExtractorLink( | ||||
|                             this.name, | ||||
|                             this.name, | ||||
|                             realDataUrl, | ||||
|                             mainUrl, | ||||
|                             Qualities.Unknown.value | ||||
|                         ) | ||||
|                     ) | ||||
|                 } | ||||
|                 return true | ||||
|             } | ||||
|             val response = app.get(realDataUrl).text | ||||
|             Regex("<iframe.*?src=\"(.*?)\"").find(response)?.groupValues?.get(1)?.let { url -> | ||||
|                 loadExtractor(url.trimStart(), realDataUrl, callback) | ||||
|             } | ||||
|             return true | ||||
|         } else { | ||||
|             val links = mapper.readValue<List<String>>(data) | ||||
|             for (link in links) { | ||||
|                 loadLinks(link, isCasting, subtitleCallback, callback) | ||||
|             } | ||||
|             return true | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,69 @@ | |||
| package com.lagradost.cloudstream3.movieproviders | ||||
| 
 | ||||
| import com.fasterxml.jackson.annotation.JsonProperty | ||||
| import com.lagradost.cloudstream3.* | ||||
| import com.lagradost.cloudstream3.APIHolder.getCaptchaToken | ||||
| import com.lagradost.cloudstream3.metaproviders.TmdbLink | ||||
| import com.lagradost.cloudstream3.metaproviders.TmdbProvider | ||||
| import com.lagradost.cloudstream3.movieproviders.SflixProvider.Companion.extractRabbitStream | ||||
| import com.lagradost.cloudstream3.utils.AppUtils.parseJson | ||||
| import com.lagradost.cloudstream3.utils.ExtractorLink | ||||
| import com.lagradost.cloudstream3.utils.loadExtractor | ||||
| 
 | ||||
| class TwoEmbedProvider : TmdbProvider() { | ||||
|     override val apiName = "2Embed" | ||||
|     override val name = "2Embed" | ||||
|     override val mainUrl = "https://www.2embed.ru" | ||||
|     override val useMetaLoadResponse = true | ||||
|     override val instantLinkLoading = false | ||||
|     override val supportedTypes = setOf( | ||||
|         TvType.Movie, | ||||
|         TvType.TvSeries, | ||||
|     ) | ||||
| 
 | ||||
|     data class EmbedJson ( | ||||
|         @JsonProperty("type") val type: String?, | ||||
|         @JsonProperty("link") val link: String, | ||||
|         @JsonProperty("sources") val sources: List<String?>, | ||||
|         @JsonProperty("tracks") val tracks: List<String>? | ||||
|     ) | ||||
| 
 | ||||
|     override suspend fun loadLinks( | ||||
|         data: String, | ||||
|         isCasting: Boolean, | ||||
|         subtitleCallback: (SubtitleFile) -> Unit, | ||||
|         callback: (ExtractorLink) -> Unit | ||||
|     ): Boolean { | ||||
|         val mappedData = parseJson<TmdbLink>(data) | ||||
|         val (id, site) = if (mappedData.imdbID != null) listOf( | ||||
|             mappedData.imdbID, | ||||
|             "imdb" | ||||
|         ) else listOf(mappedData.tmdbID.toString(), "tmdb") | ||||
|         val isMovie = mappedData.episode == null && mappedData.season == null | ||||
|         val embedUrl = if (isMovie) { | ||||
|             "$mainUrl/embed/$site/movie?id=$id" | ||||
| 
 | ||||
|         } else { | ||||
|             val suffix = "$id&s=${mappedData.season ?: 1}&e=${mappedData.episode ?: 1}" | ||||
|             "$mainUrl/embed/$site/tv?id=$suffix" | ||||
|         } | ||||
|         val document = app.get(embedUrl).document | ||||
|         val captchaKey = | ||||
|             document.select("script[src*=https://www.google.com/recaptcha/api.js?render=]") | ||||
|                 .attr("src").substringAfter("render=") | ||||
| 
 | ||||
|         val servers =  document.select(".dropdown-menu a[data-id]").map { it.attr("data-id") } | ||||
|         servers.apmap { serverID -> | ||||
|             val token = getCaptchaToken(embedUrl, captchaKey) | ||||
|             val ajax = app.get("$mainUrl/ajax/embed/play?id=$serverID&_token=$token", referer = embedUrl).text | ||||
|             val mappedservers = parseJson<EmbedJson>(ajax) | ||||
|             val iframeLink = mappedservers.link | ||||
|             if (iframeLink.contains("rabbitstream")) { | ||||
|                 extractRabbitStream(iframeLink, subtitleCallback, callback) { it } | ||||
|             } else { | ||||
|                 loadExtractor(iframeLink, embedUrl, callback) | ||||
|             } | ||||
|         } | ||||
|         return true | ||||
|     } | ||||
| } | ||||
|  | @ -112,7 +112,8 @@ val extractorApis: Array<ExtractorApi> = arrayOf( | |||
|     StreamSB7(), | ||||
|     StreamSB8(), | ||||
|     StreamSB9(), | ||||
|     Streamhub(), | ||||
|    // Streamhub(), cause Streamhub2() works | ||||
|     Streamhub2(), | ||||
| 
 | ||||
|     FEmbed(), | ||||
|     FeHD(), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue