fix(lib/lycoris): small changes v5
This commit is contained in:
parent
00b958f79c
commit
9a8ea456b4
2 changed files with 19 additions and 15 deletions
|
@ -5,13 +5,11 @@ import eu.kanade.tachiyomi.network.GET
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
import eu.kanade.tachiyomi.util.parseAs
|
import eu.kanade.tachiyomi.util.parseAs
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
class LycorisCafeExtractor(private val client: OkHttpClient) {
|
class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
|
@ -20,8 +18,6 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
|
|
||||||
private val GETLNKURL = "https://www.lycoris.cafe/api/watch/getLink"
|
private val GETLNKURL = "https://www.lycoris.cafe/api/watch/getLink"
|
||||||
|
|
||||||
private val json: Json by injectLazy()
|
|
||||||
|
|
||||||
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
|
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
|
||||||
fun getVideosFromUrl(url: String, headers: Headers, prefix: String): List<Video> {
|
fun getVideosFromUrl(url: String, headers: Headers, prefix: String): List<Video> {
|
||||||
|
|
||||||
|
@ -34,17 +30,25 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
GET(url, headers = embedHeaders),
|
GET(url, headers = embedHeaders),
|
||||||
).execute().asJsoup()
|
).execute().asJsoup()
|
||||||
|
|
||||||
val script = document.select("script[type='application/json']").first()?.data()?.toString() ?: return emptyList()
|
val script = document.selectFirst("script[type='application/json']")?.data() ?: return emptyList()
|
||||||
|
|
||||||
val scriptData = script.parseAs<ScriptBody>()
|
val scriptData = script.parseAs<ScriptBody>()
|
||||||
|
|
||||||
val data = scriptData.body.parseAs<ScriptEpisode>()
|
val data = scriptData.body.parseAs<ScriptEpisode>()
|
||||||
|
|
||||||
val linkList: String? = fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false)
|
val linkList = data.episodeInfo.id?.let {
|
||||||
|
fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false)
|
||||||
|
}
|
||||||
|
|
||||||
val fhdLink = fetchAndDecodeVideo(client, data.episodeInfo.FHD.toString(), isSecondary = true)
|
val fhdLink = data.episodeInfo.FHD?.let {
|
||||||
val sdLink = fetchAndDecodeVideo(client, data.episodeInfo.SD.toString(), isSecondary = true)
|
fetchAndDecodeVideo(client, data.episodeInfo.FHD, isSecondary = true)
|
||||||
val hdLink = fetchAndDecodeVideo(client, data.episodeInfo.HD.toString(), 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)
|
||||||
|
}
|
||||||
|
|
||||||
if (linkList.isNullOrBlank() || linkList == "{}") {
|
if (linkList.isNullOrBlank() || linkList == "{}") {
|
||||||
if (!fhdLink.isNullOrBlank()) {
|
if (!fhdLink.isNullOrBlank()) {
|
||||||
|
@ -56,25 +60,24 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
if (!sdLink.isNullOrBlank()) {
|
if (!sdLink.isNullOrBlank()) {
|
||||||
videos.add(Video(sdLink, "${prefix}lycoris.cafe - 480p", sdLink))
|
videos.add(Video(sdLink, "${prefix}lycoris.cafe - 480p", sdLink))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val videoLinks = linkList.parseAs<VideoLinksApi>()
|
val videoLinks = linkList.parseAs<VideoLinksApi>()
|
||||||
|
|
||||||
videoLinks.FHD?.takeIf { checkLinks(client, it) }?.let {
|
videoLinks.FHD?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
||||||
}?: fhdLink?.takeIf { it.contains("https://") }?.let {
|
} ?: fhdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 1080p", it))
|
||||||
}
|
}
|
||||||
|
|
||||||
videoLinks.HD?.takeIf { checkLinks(client, it) }?.let {
|
videoLinks.HD?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
||||||
}?: hdLink?.takeIf { it.contains("https://") }?.let {
|
} ?: hdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
|
||||||
}
|
}
|
||||||
|
|
||||||
videoLinks.SD?.takeIf { checkLinks(client, it) }?.let {
|
videoLinks.SD?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
||||||
}?: sdLink?.takeIf { it.contains("https://") }?.let {
|
} ?: sdLink?.takeIf { checkLinks(client, it) }?.let {
|
||||||
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +128,7 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
client.newCall(GET(url))
|
client.newCall(GET(url))
|
||||||
.execute()
|
.execute()
|
||||||
.use { response ->
|
.use { response ->
|
||||||
val data = response.body.string() ?: ""
|
val data = response.body.string()
|
||||||
return decodeVideoLinks(data)
|
return decodeVideoLinks(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +145,7 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
|
||||||
// 1. Obsługa kontynuacji linii (backslash + newline)
|
// 1. Obsługa kontynuacji linii (backslash + newline)
|
||||||
val withoutLineContinuation = text.replace("\\\n", "")
|
val withoutLineContinuation = text.replace("\\\n", "")
|
||||||
|
|
||||||
|
|
||||||
// 2. Regex do wykrywania wszystkich sekwencji escape
|
// 2. Regex do wykrywania wszystkich sekwencji escape
|
||||||
val regex = Regex(
|
val regex = Regex(
|
||||||
"""\\U([0-9a-fA-F]{8})|""" + // \UXXXXXXXX
|
"""\\U([0-9a-fA-F]{8})|""" + // \UXXXXXXXX
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Docchi'
|
extName = 'Docchi'
|
||||||
extClass = '.Docchi'
|
extClass = '.Docchi'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue