Update PlyrXExtractor.kt
This commit is contained in:
parent
a17484250a
commit
903969b0ea
1 changed files with 40 additions and 24 deletions
|
@ -3,39 +3,55 @@ package eu.kanade.tachiyomi.animeextension.hi.anisaga.extractors
|
||||||
import eu.kanade.tachiyomi.animesource.model.SubtitleFile
|
import eu.kanade.tachiyomi.animesource.model.SubtitleFile
|
||||||
import eu.kanade.tachiyomi.animesource.model.Video
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import okhttp3.OkHttpClient
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||||
import org.jsoup.Jsoup
|
import kotlinx.serialization.json.Json
|
||||||
import java.net.URLDecoder
|
import kotlinx.serialization.json.jsonArray
|
||||||
|
import kotlinx.serialization.json.jsonObject
|
||||||
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
import okhttp3.Headers
|
||||||
|
|
||||||
class PlyrXExtractor(private val client: OkHttpClient) {
|
class PlyrXExtractor(
|
||||||
|
private val network: NetworkHelper,
|
||||||
|
private val headers: Headers,
|
||||||
|
) {
|
||||||
|
private val client = network.client
|
||||||
|
private val json = Json { ignoreUnknownKeys = true }
|
||||||
|
|
||||||
fun videosFromUrl(
|
fun videosFromUrl(
|
||||||
url: String,
|
url: String,
|
||||||
referer: String,
|
referer: String,
|
||||||
subtitleCallback: (SubtitleFile) -> Unit
|
subtitleCallback: (SubtitleFile) -> Unit,
|
||||||
): List<Video> {
|
): List<Video> {
|
||||||
val response = client.newCall(GET(url, headers = mapOf("Referer" to referer))).execute()
|
val response = client.newCall(
|
||||||
val doc = Jsoup.parse(response.body.string())
|
GET(url, headers.newBuilder().set("Referer", referer).build()),
|
||||||
|
).execute()
|
||||||
|
|
||||||
val script = doc.select("script").firstOrNull { it.data().contains("sources:") }?.data()
|
val document = response.body?.string() ?: return emptyList()
|
||||||
|
|
||||||
|
val masterUrl = Regex("sources:\\s*\\\{\\s*file:\\s*\"(https[^\"]+\\.m3u8)\"")
|
||||||
|
.find(document)
|
||||||
|
?.groupValues?.get(1)
|
||||||
?: return emptyList()
|
?: return emptyList()
|
||||||
|
|
||||||
// Extract video sources
|
val subtitleRegex = Regex("tracks:\\s*\(.*?)\")
|
||||||
val sources = Regex("""file:\s*["'](.*?)["']""").findAll(script).map { it.groupValues[1] }.toList()
|
val subtitleMatch = subtitleRegex.find(document)?.groupValues?.get(1)
|
||||||
val videos = sources.mapIndexed { i, source ->
|
subtitleMatch?.let { subText ->
|
||||||
val decoded = URLDecoder.decode(source, "UTF-8")
|
Regex("""\{file:"(.*?)",label:"(.*?)"\}""")
|
||||||
Video(url, "PlyrXCDN - ${i + 1}", decoded, headers = mapOf("Referer" to referer))
|
.findAll(subText)
|
||||||
}
|
.forEach { match ->
|
||||||
|
val subUrl = match.groupValues[1]
|
||||||
// Extract subtitles (if any)
|
val label = match.groupValues[2]
|
||||||
Regex("""tracks:\s*(.*?)""", RegexOption.DOT_MATCHES_ALL).find(script)?.groupValues?.get(1)?.let { tracksBlock ->
|
|
||||||
Regex("""file:\s*["'](.*?)["'],\s*label:\s*["'](.*?)["']""").findAll(tracksBlock).forEach {
|
|
||||||
val subUrl = URLDecoder.decode(it.groupValues[1], "UTF-8")
|
|
||||||
val label = it.groupValues[2]
|
|
||||||
subtitleCallback(SubtitleFile(label, subUrl))
|
subtitleCallback(SubtitleFile(label, subUrl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return videos
|
return listOf(
|
||||||
|
Video(
|
||||||
|
url = masterUrl,
|
||||||
|
quality = "HLS",
|
||||||
|
videoUrl = masterUrl,
|
||||||
|
headers = mapOf("Referer" to referer),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue