forked from recloudstream/cloudstream
kdramahood: add default source and subtitle (#629)
* kdramahood: add default source and subtitle * applied PR changes
This commit is contained in:
parent
d1278f97e7
commit
56fb9fcb7c
1 changed files with 78 additions and 18 deletions
|
@ -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<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(
|
||||
name = null,
|
||||
|
@ -199,14 +218,54 @@ class KdramaHoodProvider : MainAPI() {
|
|||
callback: (ExtractorLink) -> Unit
|
||||
): Boolean {
|
||||
var count = 0
|
||||
mapper.readValue<List<String>>(data).apmap { item ->
|
||||
parseJson<List<String>>(data).apmap { item ->
|
||||
if (item.isNotBlank()) {
|
||||
count++
|
||||
var url = item.trim()
|
||||
if (url.startsWith("//")) {
|
||||
url = "https:$url"
|
||||
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<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 {
|
||||
url.startsWith("https://asianembed.io") -> {
|
||||
AsianEmbedHelper.getUrls(url, callback)
|
||||
|
@ -224,6 +283,7 @@ class KdramaHoodProvider : MainAPI() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count > 0
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue