fix(lib/lycoris): small changes v4

This commit is contained in:
Hayanek 2025-03-15 01:31:58 +01:00
parent bc313fa859
commit b9e9dbb2a9

View file

@ -34,7 +34,7 @@ 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() val script = document.select("script[type='application/json']").first()?.data()?.toString() ?: return emptyList()
val scriptData = script.parseAs<ScriptBody>() val scriptData = script.parseAs<ScriptBody>()
@ -77,14 +77,13 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
}?: sdLink?.takeIf { it.contains("https://") }?.let { }?: sdLink?.takeIf { it.contains("https://") }?.let {
videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it)) videos.add(Video(it, "${prefix}lycoris.cafe - 480p", it))
} }
} }
return videos return videos
} }
private fun decodeVideoLinks(encodedUrl: String?): String? { private fun decodeVideoLinks(encodedUrl: String): String? {
if (encodedUrl.isNullOrEmpty()) { if (encodedUrl.isBlank()) {
return null return null
} }
@ -108,27 +107,27 @@ class LycorisCafeExtractor(private val client: OkHttpClient) {
} }
private fun fetchAndDecodeVideo(client: OkHttpClient, episodeId: String, isSecondary: Boolean = false): String? { private fun fetchAndDecodeVideo(client: OkHttpClient, episodeId: String, isSecondary: Boolean = false): String? {
val url: HttpUrl val url: HttpUrl
if (isSecondary) { if (isSecondary) {
val convertedText = episodeId.toByteArray(Charset.forName("UTF-8")).toString(Charset.forName("ISO-8859-1")) val convertedText = episodeId.toByteArray(Charset.forName("UTF-8")).toString(Charset.forName("ISO-8859-1"))
val unicodeEscape = decodePythonEscape(convertedText) val unicodeEscape = decodePythonEscape(convertedText)
val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8) val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8)
url = GETLNKURL.toHttpUrl().newBuilder() url = GETLNKURL.toHttpUrl().newBuilder()
.addQueryParameter("link", finalText) .addQueryParameter("link", finalText)
.build() .build()
} else { } else {
url = GETSECONDARYURL.toHttpUrl().newBuilder() url = GETSECONDARYURL.toHttpUrl().newBuilder()
.addQueryParameter("id", episodeId) .addQueryParameter("id", episodeId)
.build() .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 { private fun checkLinks(client: OkHttpClient, link: String): Boolean {