kdramahood: add default source and subtitle (#629)

* kdramahood: add default source and subtitle

* applied PR changes
This commit is contained in:
Jace 2022-02-12 18:36:48 +08:00 committed by GitHub
parent d1278f97e7
commit 56fb9fcb7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,15 @@
package com.lagradost.cloudstream3.movieproviders 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.*
import com.lagradost.cloudstream3.extractors.* import com.lagradost.cloudstream3.extractors.*
import com.lagradost.cloudstream3.extractors.helper.AsianEmbedHelper 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.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName
import com.lagradost.cloudstream3.utils.loadExtractor import com.lagradost.cloudstream3.utils.loadExtractor
import org.jsoup.Jsoup import org.jsoup.Jsoup
@ -18,6 +22,11 @@ class KdramaHoodProvider : MainAPI() {
override val hasDownloadSupport = true override val hasDownloadSupport = true
override val supportedTypes = setOf(TvType.TvSeries, TvType.Movie) 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 { override suspend fun getMainPage(): HomePageResponse {
val doc = app.get("$mainUrl/home2").document val doc = app.get("$mainUrl/home2").document
val home = ArrayList<HomePageList>() val home = ArrayList<HomePageList>()
@ -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( TvSeriesEpisode(
name = null, name = null,
@ -199,14 +218,54 @@ class KdramaHoodProvider : MainAPI() {
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
var count = 0 var count = 0
mapper.readValue<List<String>>(data).apmap { item -> parseJson<List<String>>(data).apmap { item ->
if (item.isNotBlank()) { if (item.isNotBlank()) {
count++ count++
var url = item.trim() if (item.startsWith(mainUrl)) {
if (url.startsWith("//")) { val text = item.substring(mainUrl.length)
url = "https:$url" //Log.i(this.name, "Result => (text) $text")
//Find video files
try {
"(?<=sources: )([\\s\\S]*?)(?<=])".toRegex().find(text)?.value?.let { vid ->
parseJson<List<ResponseDatas>>(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
)
)
} }
//Log.i(this.name, "Result => (url) ${url}") }
} catch (e: Exception) {
logError(e)
}
//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<List<ResponseDatas>>(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 { when {
url.startsWith("https://asianembed.io") -> { url.startsWith("https://asianembed.io") -> {
AsianEmbedHelper.getUrls(url, callback) AsianEmbedHelper.getUrls(url, callback)
@ -224,6 +283,7 @@ class KdramaHoodProvider : MainAPI() {
} }
} }
} }
}
return count > 0 return count > 0
} }
} }