fix: Voe extractor (#2878)
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id("lib-android")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":lib:playlist-utils"))
|
||||
}
|
@ -1,26 +1,44 @@
|
||||
package eu.kanade.tachiyomi.lib.voeextractor
|
||||
|
||||
import android.util.Base64
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.OkHttpClient
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class VoeExtractor(private val client: OkHttpClient) {
|
||||
fun videoFromUrl(url: String, quality: String? = null, prefix: String = ""): Video? {
|
||||
val document = client.newCall(GET(url)).execute().asJsoup()
|
||||
val script = document.selectFirst("script:containsData(const sources), script:containsData(var sources)")
|
||||
?.data()
|
||||
?: return null
|
||||
val videoUrl = script.substringAfter("hls': '").substringBefore("'")
|
||||
val resolution = script.substringAfter("video_height': ").substringBefore(",")
|
||||
val qualityStr = when {
|
||||
prefix.isNotEmpty() -> "$prefix${resolution}p"
|
||||
else -> quality ?: "VoeCDN(${resolution}p)"
|
||||
}
|
||||
return Video(url, qualityStr, videoUrl)
|
||||
}
|
||||
|
||||
fun videosFromUrl(url: String, quality: String? = null, prefix: String = ""): List<Video> {
|
||||
return videoFromUrl(url, quality, prefix)?.let(::listOf).orEmpty()
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
private val playlistUtils by lazy { PlaylistUtils(client) }
|
||||
|
||||
@Serializable
|
||||
data class VideoLinkDTO(val file: String)
|
||||
|
||||
fun videosFromUrl(url: String, prefix: String = ""): List<Video> {
|
||||
val document = client.newCall(GET(url)).execute().asJsoup()
|
||||
val script = document.selectFirst("script:containsData(const sources), script:containsData(var sources), script:containsData(wc0)")
|
||||
?.data()
|
||||
?: return emptyList()
|
||||
val playlistUrl = when {
|
||||
// Layout 1
|
||||
script.contains("sources") -> {
|
||||
script.substringAfter("hls': '").substringBefore("'")
|
||||
}
|
||||
// Layout 2
|
||||
script.contains("wc0") -> {
|
||||
val base64 = Regex("'.*'").find(script)!!.value
|
||||
val decoded = Base64.decode(base64, Base64.DEFAULT).let(::String)
|
||||
json.decodeFromString<VideoLinkDTO>(decoded).file
|
||||
}
|
||||
else -> return emptyList()
|
||||
}
|
||||
return playlistUtils.extractFromHls(playlistUrl,
|
||||
videoNameGen = { quality -> "${prefix}Voe: $quality" }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user