From 56fb9fcb7c96ccd54e42a90505154ca4dd2c25e2 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Sat, 12 Feb 2022 18:36:48 +0800 Subject: [PATCH] kdramahood: add default source and subtitle (#629) * kdramahood: add default source and subtitle * applied PR changes --- .../movieproviders/KdramaHoodProvider.kt | 96 +++++++++++++++---- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/KdramaHoodProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/KdramaHoodProvider.kt index 44825a88..1b9b803b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/KdramaHoodProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/KdramaHoodProvider.kt @@ -1,11 +1,15 @@ package com.lagradost.cloudstream3.movieproviders -import com.fasterxml.jackson.module.kotlin.readValue +import android.util.Log +import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.extractors.* import com.lagradost.cloudstream3.extractors.helper.AsianEmbedHelper +import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.getQualityFromName import com.lagradost.cloudstream3.utils.loadExtractor import org.jsoup.Jsoup @@ -18,6 +22,11 @@ class KdramaHoodProvider : MainAPI() { override val hasDownloadSupport = true override val supportedTypes = setOf(TvType.TvSeries, TvType.Movie) + private data class ResponseDatas( + @JsonProperty("label") val label: String, + @JsonProperty("file") val file: String + ) + override suspend fun getMainPage(): HomePageResponse { val doc = app.get("$mainUrl/home2").document val home = ArrayList() @@ -154,6 +163,16 @@ class KdramaHoodProvider : MainAPI() { } } } + //Fetch default source and subtitles + epVidLinkEl.select("div.embed2")?.forEach { defsrc -> + if (defsrc == null) { return@forEach } + val scriptstring = defsrc.toString() + if (scriptstring.contains("sources: [{")) { + "(?<=playerInstance2.setup\\()([\\s\\S]*?)(?=\\);)".toRegex().find(scriptstring)?.value?.let { itemjs -> + listOfLinks.add("$mainUrl$itemjs") + } + } + } } TvSeriesEpisode( name = null, @@ -199,27 +218,68 @@ class KdramaHoodProvider : MainAPI() { callback: (ExtractorLink) -> Unit ): Boolean { var count = 0 - mapper.readValue>(data).apmap { item -> + parseJson>(data).apmap { item -> if (item.isNotBlank()) { count++ - var url = item.trim() - if (url.startsWith("//")) { - url = "https:$url" - } - //Log.i(this.name, "Result => (url) ${url}") - when { - url.startsWith("https://asianembed.io") -> { - AsianEmbedHelper.getUrls(url, callback) - } - url.startsWith("https://embedsito.com") -> { - val extractor = XStreamCdn() - extractor.domainUrl = "embedsito.com" - extractor.getUrl(url).forEach { link -> - callback.invoke(link) + if (item.startsWith(mainUrl)) { + val text = item.substring(mainUrl.length) + //Log.i(this.name, "Result => (text) $text") + //Find video files + try { + "(?<=sources: )([\\s\\S]*?)(?<=])".toRegex().find(text)?.value?.let { vid -> + parseJson>(vid).forEach { src -> + //Log.i(this.name, "Result => (src) ${src.toJson()}") + callback( + ExtractorLink( + name = "$name ${src.label}", + url = src.file, + quality = getQualityFromName(src.label), + referer = mainUrl, + source = name + ) + ) + } } + } catch (e: Exception) { + logError(e) } - else -> { - loadExtractor(url, mainUrl, callback) + //Find subtitles + try { + "(?<=tracks: )([\\s\\S]*?)(?<=])".toRegex().find(text)?.value?.let { sub -> + val subtext = sub.replace("file:", "\"file\":") + .replace("label:", "\"label\":") + .replace("kind:", "\"kind\":") + parseJson>(subtext).forEach { src -> + //Log.i(this.name, "Result => (sub) ${src.toJson()}") + subtitleCallback( + SubtitleFile( + lang = src.label, + url = src.file + ) + ) + } + } + } catch (e: Exception) { + logError(e) + } + + } else { + val url = fixUrl(item.trim()) + //Log.i(this.name, "Result => (url) $url") + when { + url.startsWith("https://asianembed.io") -> { + AsianEmbedHelper.getUrls(url, callback) + } + url.startsWith("https://embedsito.com") -> { + val extractor = XStreamCdn() + extractor.domainUrl = "embedsito.com" + extractor.getUrl(url).forEach { link -> + callback.invoke(link) + } + } + else -> { + loadExtractor(url, mainUrl, callback) + } } } }