forked from AlmightyHak/extensions-source
fix(lib/lycoris&lulu) Repair decode json and work LuluStream (#810)
* fix(lib/lycoris): fix parse json * fix(lib/lycoris): small changes * fix(lib/lycoris): small changes v2 * fix(lib/lycoris): small changes v3 * fix(lib/lycoris): small changes v4 * fix(lib/lycoris): small changes v5 * fix(lib/lycoris&lulu): big change v1 * fix(lib/lycoris&lulu): small change v2 * fix(lib/lycoris&lulu): small change v3 * fix(lib/lycoris&lulu&docchi): small change v4 * fix(pl/docchi): tiny change v1 * fix(lib/lulu): tiny change v2
This commit is contained in:
parent
2574c7fbf8
commit
8d9e763dc4
4 changed files with 124 additions and 109 deletions
|
@ -3,16 +3,18 @@ package eu.kanade.tachiyomi.lib.luluextractor
|
|||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class LuluExtractor(private val client: OkHttpClient) {
|
||||
class LuluExtractor(private val client: OkHttpClient, headers: Headers) {
|
||||
|
||||
private val headers = Headers.Builder()
|
||||
.add("Referer", "https://luluvdo.com")
|
||||
private val headers = headers.newBuilder()
|
||||
.add("Referer", "https://luluvdo.com/")
|
||||
.add("Origin", "https://luluvdo.com")
|
||||
.build()
|
||||
|
||||
//Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lulustream.py
|
||||
fun videosFromUrl(url: String, prefix: String): List<Video> {
|
||||
val videos = mutableListOf<Video>()
|
||||
|
||||
|
@ -22,7 +24,7 @@ class LuluExtractor(private val client: OkHttpClient) {
|
|||
val fixedUrl = fixM3u8Link(m3u8Url)
|
||||
val quality = getResolution(fixedUrl)
|
||||
|
||||
videos.add(Video(fixedUrl, "${prefix}Lulu - $quality", fixedUrl))
|
||||
videos.add(Video(fixedUrl, "${prefix}Lulu - $quality", fixedUrl, headers))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -50,34 +52,41 @@ class LuluExtractor(private val client: OkHttpClient) {
|
|||
|
||||
private fun fixM3u8Link(link: String): String {
|
||||
val paramOrder = listOf("t", "s", "e", "f")
|
||||
val baseUrl = link.split("?").first()
|
||||
val params = link.split("?").getOrNull(1)?.split("&") ?: emptyList()
|
||||
val params = Pattern.compile("[?&]([^=]*)=([^&]*)").matcher(link).let { matcher ->
|
||||
generateSequence { if (matcher.find()) matcher.group(1) to matcher.group(2) else null }.toList()
|
||||
}
|
||||
|
||||
val paramMap = mutableMapOf<String, String>()
|
||||
val extraParams = mutableMapOf(
|
||||
"i" to "0.3",
|
||||
"sp" to "0"
|
||||
)
|
||||
val paramDict = mutableMapOf<String, String>()
|
||||
val extraParams = mutableMapOf<String, String>()
|
||||
|
||||
params.forEachIndexed { index, param ->
|
||||
val parts = param.split("=")
|
||||
when {
|
||||
parts.size == 2 -> {
|
||||
val (key, value) = parts
|
||||
if (key in paramOrder) paramMap[key] = value
|
||||
else extraParams[key] = value
|
||||
params.forEachIndexed { index, (key , value) ->
|
||||
if (key.isNullOrEmpty()) {
|
||||
if (index < paramOrder.size) {
|
||||
if (value != null) {
|
||||
paramDict[paramOrder[index]] = value
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (value != null) {
|
||||
extraParams[key] = value
|
||||
}
|
||||
index < paramOrder.size -> paramMap[paramOrder[index]] = parts.firstOrNull() ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
return buildString {
|
||||
append(baseUrl)
|
||||
append("?")
|
||||
append(paramOrder.joinToString("&") { "$it=${paramMap[it]}" })
|
||||
append("&")
|
||||
append(extraParams.map { "${it.key}=${it.value}" }.joinToString("&"))
|
||||
extraParams["i"] = "0.3"
|
||||
extraParams["sp"] = "0"
|
||||
|
||||
val baseUrl = link.split("?")[0]
|
||||
|
||||
val fixedLink = baseUrl.toHttpUrl().newBuilder()
|
||||
paramOrder.filter { paramDict.containsKey(it) }.forEach { key ->
|
||||
fixedLink.addQueryParameter(key, paramDict[key])
|
||||
}
|
||||
extraParams.forEach { (key, value) ->
|
||||
fixedLink.addQueryParameter(key, value)
|
||||
}
|
||||
|
||||
return fixedLink.build().toString()
|
||||
}
|
||||
|
||||
private fun getResolution(m3u8Url: String): String {
|
||||
|
@ -98,11 +107,10 @@ class LuluExtractor(private val client: OkHttpClient) {
|
|||
}
|
||||
|
||||
object JavaScriptUnpacker {
|
||||
private val UNPACK_REGEX = Regex(
|
||||
"""}\('(.*)', *(\d+), *(\d+), *'(.*?)'\.split\('\|'\)""",
|
||||
RegexOption.DOT_MATCHES_ALL
|
||||
)
|
||||
|
||||
private val UNPACK_REGEX by lazy {
|
||||
Regex("""\}\('(.*)', *(\d+), *(\d+), *'(.*?)'\.split\('\|'\)""",
|
||||
RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
fun unpack(encodedJs: String): String? {
|
||||
val match = UNPACK_REGEX.find(encodedJs) ?: return null
|
||||
val (payload, radixStr, countStr, symtabStr) = match.destructured
|
||||
|
@ -121,8 +129,8 @@ object JavaScriptUnpacker {
|
|||
return Regex("""\b\w+\b""").replace(payload) { mr ->
|
||||
symtab.getOrNull(unbase(mr.value, radix, baseDict)) ?: mr.value
|
||||
}.replace("\\", "")
|
||||
}
|
||||
|
||||
}
|
||||
private fun unbase(value: String, radix: Int, dict: Map<Char, Int>): Int {
|
||||
var result = 0
|
||||
var multiplier = 1
|
||||
|
|
|
@ -4,13 +4,12 @@ import eu.kanade.tachiyomi.animesource.model.Video
|
|||
import eu.kanade.tachiyomi.network.GET
|
||||
import android.util.Base64
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import eu.kanade.tachiyomi.util.parseAs
|
||||
import kotlinx.serialization.Serializable
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||
|
@ -19,7 +18,15 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
|||
|
||||
private val GETLNKURL = "https://www.lycoris.cafe/api/watch/getLink"
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
private val wordsRegex by lazy {
|
||||
Regex(
|
||||
"""\\U([0-9a-fA-F]{8})|""" + // \UXXXXXXXX
|
||||
"""\\u([0-9a-fA-F]{4})|""" + // \uXXXX
|
||||
"""\\x([0-9a-fA-F]{2})|""" + // \xHH
|
||||
"""\\([0-7]{1,3})|""" + // \OOO (octal)
|
||||
"""\\([btnfr"'$\\])""" // \n, \t, itd.
|
||||
)
|
||||
}
|
||||
|
||||
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
|
||||
fun getVideosFromUrl(url: String, headers: Headers, prefix: String): List<Video> {
|
||||
|
@ -33,72 +40,63 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
|||
GET(url, headers = embedHeaders),
|
||||
).execute().asJsoup()
|
||||
|
||||
val scripts = document.select("script")
|
||||
val script = document.selectFirst("script[type='application/json']")?.data() ?: return emptyList()
|
||||
|
||||
val episodeDataPattern = Regex("episodeInfo\\s*:\\s*(\\{.*?\\}),", RegexOption.DOT_MATCHES_ALL)
|
||||
var episodeData: String? = null
|
||||
val scriptData = script.parseAs<ScriptBody>()
|
||||
|
||||
for (script in scripts) {
|
||||
val content = script.data()
|
||||
val match = episodeDataPattern.find(content)
|
||||
val data = scriptData.body.parseAs<ScriptEpisode>()
|
||||
|
||||
if (match != null) {
|
||||
episodeData = match.groupValues[1]
|
||||
break
|
||||
}
|
||||
val linkList = data.episodeInfo.id?.let {
|
||||
fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false)
|
||||
}
|
||||
|
||||
val result = mutableMapOf<String, String?>()
|
||||
|
||||
val patterns = listOf(
|
||||
"id" to Regex("id\\s*:\\s*(\\d+)"),
|
||||
"FHD" to Regex("FHD\\s*:\\s*\"([^\"]+)\""),
|
||||
"HD" to Regex("HD\\s*:\\s*\"([^\"]+)\""),
|
||||
"SD" to Regex("SD\\s*:\\s*\"([^\"]+)\"")
|
||||
)
|
||||
|
||||
patterns.forEach { (key, pattern) ->
|
||||
result[key] = episodeData?.let { pattern.find(it)?.groups?.get(1)?.value }
|
||||
val fhdLink = data.episodeInfo.FHD?.let {
|
||||
fetchAndDecodeVideo(client, data.episodeInfo.FHD, isSecondary = true)
|
||||
}
|
||||
val sdLink = data.episodeInfo.SD?.let {
|
||||
fetchAndDecodeVideo(client, data.episodeInfo.SD, isSecondary = true)
|
||||
}
|
||||
val hdLink = data.episodeInfo.HD?.let {
|
||||
fetchAndDecodeVideo(client, data.episodeInfo.HD, isSecondary = true)
|
||||
}
|
||||
|
||||
var linkList: String? = fetchAndDecodeVideo(client, result["id"].toString(), isSecondary = false).toString()
|
||||
|
||||
val fhdLink = fetchAndDecodeVideo(client, result["FHD"].toString(), isSecondary = true).toString()
|
||||
val sdLink = fetchAndDecodeVideo(client, result["SD"].toString(), isSecondary = true).toString()
|
||||
val hdLink = fetchAndDecodeVideo(client, result["HD"].toString(), isSecondary = true).toString()
|
||||
|
||||
|
||||
if (linkList.isNullOrBlank() || linkList == "{}") {
|
||||
if (fhdLink.isNotEmpty()) {
|
||||
if (!fhdLink.isNullOrBlank()) {
|
||||
videos.add(Video(fhdLink, "${prefix}lycoris.cafe - 1080p", fhdLink))
|
||||
}
|
||||
if (hdLink.isNotEmpty()) {
|
||||
if (!hdLink.isNullOrBlank()) {
|
||||
videos.add(Video(hdLink, "${prefix}lycoris.cafe - 720p", hdLink))
|
||||
}
|
||||
if (sdLink.isNotEmpty()) {
|
||||
if (!sdLink.isNullOrBlank()) {
|
||||
videos.add(Video(sdLink, "${prefix}lycoris.cafe - 480p", sdLink))
|
||||
}
|
||||
}else {
|
||||
val videoLinks = Json.decodeFromString<VideoLinks>(linkList)
|
||||
} else {
|
||||
val videoLinks = linkList.parseAs<VideoLinksApi>()
|
||||
|
||||
videoLinks.FHD?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
||||
}?: videos.add(Video(fhdLink, "${prefix}lycoris.cafe - 1080p", fhdLink))
|
||||
} ?: fhdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
||||
}
|
||||
|
||||
videoLinks.HD?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
||||
}?: videos.add(Video(hdLink, "${prefix}lycoris.cafe - 720p", hdLink))
|
||||
} ?: hdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
||||
}
|
||||
|
||||
videoLinks.SD?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
||||
}?: videos.add(Video(sdLink, "${prefix}lycoris.cafe - 480p", sdLink))
|
||||
} ?: sdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
||||
}
|
||||
}
|
||||
return videos
|
||||
|
||||
}
|
||||
|
||||
private fun decodeVideoLinks(encodedUrl: String?): Any? {
|
||||
if (encodedUrl.isNullOrEmpty()) {
|
||||
private fun decodeVideoLinks(encodedUrl: String): String? {
|
||||
if (encodedUrl.isBlank()) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
@ -121,31 +119,33 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun fetchAndDecodeVideo(client: OkHttpClient, episodeId: String, isSecondary: Boolean = false): Any? {
|
||||
val url: HttpUrl
|
||||
private fun fetchAndDecodeVideo(client: OkHttpClient, episodeId: String, isSecondary: Boolean = false): String? {
|
||||
val url: HttpUrl
|
||||
|
||||
if (isSecondary) {
|
||||
val convertedText = episodeId.toByteArray(Charset.forName("UTF-8")).toString(Charset.forName("ISO-8859-1"))
|
||||
val unicodeEscape = decodePythonEscape(convertedText)
|
||||
val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8)
|
||||
if (isSecondary) {
|
||||
val convertedText = episodeId.toByteArray(Charset.forName("UTF-8")).toString(Charset.forName("ISO-8859-1"))
|
||||
val unicodeEscape = decodePythonEscape(convertedText)
|
||||
val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8)
|
||||
|
||||
url = GETLNKURL.toHttpUrl().newBuilder()
|
||||
?.addQueryParameter("link", finalText)
|
||||
?.build() ?: throw IllegalStateException("Invalid URL")
|
||||
} else {
|
||||
url = GETSECONDARYURL.toHttpUrl().newBuilder()
|
||||
?.addQueryParameter("id", episodeId)
|
||||
?.build() ?: throw IllegalStateException("Invalid URL")
|
||||
url = GETLNKURL.toHttpUrl().newBuilder()
|
||||
.addQueryParameter("link", finalText)
|
||||
.build()
|
||||
} else {
|
||||
url = GETSECONDARYURL.toHttpUrl().newBuilder()
|
||||
.addQueryParameter("id", episodeId)
|
||||
.build()
|
||||
}
|
||||
client.newCall(GET(url))
|
||||
.execute()
|
||||
.use { response ->
|
||||
val data = response.body.string()
|
||||
return decodeVideoLinks(data)
|
||||
}
|
||||
client.newCall(GET(url))
|
||||
.execute()
|
||||
.use { response ->
|
||||
val data = response.body.string() ?: ""
|
||||
return decodeVideoLinks(data)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
|
||||
if (!link.contains("https://")) return false
|
||||
|
||||
client.newCall(GET(link)).execute().use { response ->
|
||||
return response.code.toString() == "200"
|
||||
}
|
||||
|
@ -155,16 +155,7 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
|||
// 1. Obsługa kontynuacji linii (backslash + newline)
|
||||
val withoutLineContinuation = text.replace("\\\n", "")
|
||||
|
||||
// 2. Regex do wykrywania wszystkich sekwencji escape
|
||||
val regex = Regex(
|
||||
"""\\U([0-9a-fA-F]{8})|""" + // \UXXXXXXXX
|
||||
"""\\u([0-9a-fA-F]{4})|""" + // \uXXXX
|
||||
"""\\x([0-9a-fA-F]{2})|""" + // \xHH
|
||||
"""\\([0-7]{1,3})|""" + // \OOO (octal)
|
||||
"""\\([btnfr"'$\\\\])""" // \n, \t, itd.
|
||||
)
|
||||
|
||||
return regex.replace(withoutLineContinuation) { match ->
|
||||
return wordsRegex.replace(withoutLineContinuation) { match ->
|
||||
val (u8, u4, x2, octal, simple) = match.destructured
|
||||
when {
|
||||
u8.isNotEmpty() -> handleUnicode8(u8)
|
||||
|
@ -208,16 +199,32 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
|||
}
|
||||
|
||||
@Serializable
|
||||
data class VideoLinks(
|
||||
data class ScriptBody(
|
||||
val body: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ScriptEpisode(
|
||||
val episodeInfo: EpisodeInfo
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EpisodeInfo(
|
||||
val id: Int? = null,
|
||||
val FHD: String? = null,
|
||||
val HD: String? = null,
|
||||
val SD: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class VideoLinksApi(
|
||||
val HD: String? = null,
|
||||
val SD: String? = null,
|
||||
val FHD: String? = null,
|
||||
val Source: String? = null,
|
||||
val preview: String? = null,
|
||||
val SourceMKV: String? = null
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'Docchi'
|
||||
extClass = '.Docchi'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ class Docchi : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
private val sibnetExtractor by lazy { SibnetExtractor(client) }
|
||||
private val doodExtractor by lazy { DoodExtractor(client) }
|
||||
private val lycorisExtractor by lazy { LycorisCafeExtractor(client) }
|
||||
private val luluExtractor by lazy { LuluExtractor(client) }
|
||||
private val luluExtractor by lazy { LuluExtractor(client, headers) }
|
||||
private val googledriveExtractor by lazy { GoogleDriveExtractor(client, headers) }
|
||||
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
|
@ -278,7 +278,7 @@ class Docchi : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
val genres: List<String>,
|
||||
val broadcast_day: String?,
|
||||
val aired_from: String?,
|
||||
val episodes: Int,
|
||||
val episodes: Int?,
|
||||
val season: String,
|
||||
val season_year: Int,
|
||||
val series_type: String,
|
||||
|
@ -294,7 +294,7 @@ class Docchi : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
val cover: String,
|
||||
val adult_content: String,
|
||||
val series_type: String,
|
||||
val episodes: Int,
|
||||
val episodes: Int?,
|
||||
val season: String,
|
||||
val season_year: Int,
|
||||
)
|
||||
|
@ -315,7 +315,7 @@ class Docchi : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
val genres: List<String>,
|
||||
val broadcast_day: String?,
|
||||
val aired_from: String?,
|
||||
val episodes: Int,
|
||||
val episodes: Int?,
|
||||
val season: String,
|
||||
val season_year: Int,
|
||||
val series_type: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue