fix(lib/lycoris&lulu) Repair decode json and work LuluStream #810

Merged
Hayanek merged 14 commits from fix-lycoris into main 2025-04-06 13:41:23 -05:00
Hayanek commented 2025-03-10 19:40:34 -05:00 (Migrated from github.com)

Checklist:

  • Updated extVersionCode value in build.gradle for individual extensions
  • Updated overrideVersionCode or baseVersionCode as needed for all multisrc extensions
  • Referenced all related issues in the PR body (e.g. "Closes #xyz")
  • Added the isNsfw = true flag in build.gradle when appropriate
  • Have not changed source names
  • Have explicitly kept the id if a source's name or language were changed
  • Have tested the modifications by compiling and running the extension through Android Studio
  • Have removed web_hi_res_512.png when adding a new extension
  • Have made sure all the icons are in png format
Checklist: - [ ] Updated `extVersionCode` value in `build.gradle` for individual extensions - [ ] Updated `overrideVersionCode` or `baseVersionCode` as needed for all multisrc extensions - [ ] Referenced all related issues in the PR body (e.g. "Closes #xyz") - [ ] Added the `isNsfw = true` flag in `build.gradle` when appropriate - [x] Have not changed source names - [ ] Have explicitly kept the `id` if a source's name or language were changed - [x] Have tested the modifications by compiling and running the extension through Android Studio - [ ] Have removed `web_hi_res_512.png` when adding a new extension - [ ] Have made sure all the icons are in png format
cuong-tran (Migrated from github.com) reviewed 2025-03-10 19:40:34 -05:00
cuong-tran (Migrated from github.com) reviewed 2025-03-12 10:20:10 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-12 10:20:09 -05:00

Json injekt should already have ignoreUnknownKeys = true, while need to change?

Json injekt should already have `ignoreUnknownKeys = true`, while need to change?
cuong-tran commented 2025-03-12 12:06:25 -05:00 (Migrated from github.com)

this line seems to have a redundant slash:

"""\\([btnfr"'$\\\\])"""         // \n, \t, itd.

=>

"""\\([btnfr"'$\\])"""         // \n, \t, itd.
this line seems to have a redundant slash: ```kotlin """\\([btnfr"'$\\\\])""" // \n, \t, itd. ``` => ```kotlin """\\([btnfr"'$\\])""" // \n, \t, itd. ```
Hayanek (Migrated from github.com) reviewed 2025-03-12 12:14:59 -05:00
Hayanek (Migrated from github.com) commented 2025-03-12 12:14:58 -05:00

I genuinely didn't know about it but good to know, thank you.

I genuinely didn't know about it but good to know, thank you.
cuong-tran (Migrated from github.com) requested changes 2025-03-12 12:29:15 -05:00
@ -23,2 +28,4 @@
)
}
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
cuong-tran (Migrated from github.com) commented 2025-03-12 11:51:48 -05:00

this will send a string "null" to json.decode and cause a crash

this will send a string `"null"` to json.decode and cause a crash
cuong-tran (Migrated from github.com) commented 2025-03-12 11:52:59 -05:00

use script.parseAs<ScriptBody>()

use `script.parseAs<ScriptBody>()`
cuong-tran (Migrated from github.com) commented 2025-03-12 11:53:47 -05:00

same here

same here
cuong-tran (Migrated from github.com) commented 2025-03-12 11:54:37 -05:00
        val linkList: String? = fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false)

also fix fetchAndDecodeVideo() & decodeVideoLinks() so they both return String?

```suggestion val linkList: String? = fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false) ``` also fix `fetchAndDecodeVideo()` & `decodeVideoLinks()` so they both return `String?`
cuong-tran (Migrated from github.com) commented 2025-03-12 12:18:42 -05:00
        val fhdLink = fetchAndDecodeVideo(client, data.episodeInfo.FHD.toString(), isSecondary = true)
        val sdLink = fetchAndDecodeVideo(client, data.episodeInfo.SD.toString(), isSecondary = true)
        val hdLink = fetchAndDecodeVideo(client, data.episodeInfo.HD.toString(), isSecondary = true)
```suggestion val fhdLink = fetchAndDecodeVideo(client, data.episodeInfo.FHD.toString(), isSecondary = true) val sdLink = fetchAndDecodeVideo(client, data.episodeInfo.SD.toString(), isSecondary = true) val hdLink = fetchAndDecodeVideo(client, data.episodeInfo.HD.toString(), isSecondary = true) ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:27:09 -05:00
            if (!fhdLink.isNullOrBlank()) {
```suggestion if (!fhdLink.isNullOrBlank()) { ```
@ -59,3 +53,1 @@
patterns.forEach { (key, pattern) ->
result[key] = episodeData?.let { pattern.find(it)?.groups?.get(1)?.value }
val fhdLink = data.episodeInfo.FHD?.let {
cuong-tran (Migrated from github.com) commented 2025-03-12 12:15:19 -05:00
        } else {
```suggestion } else { ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:21:44 -05:00
            val videoLinks = linkList.parseAs<VideoLinksApi>()
```suggestion val videoLinks = linkList.parseAs<VideoLinksApi>() ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:27:35 -05:00
            if (!sdLink.isNullOrBlank()) {
```suggestion if (!sdLink.isNullOrBlank()) { ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:28:12 -05:00
            }?: fhdLink?.takeIf { it.contains("https://") }?.let {
```suggestion }?: fhdLink?.takeIf { it.contains("https://") }?.let { ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:28:33 -05:00
            }?: hdLink?.takeIf { it.contains("https://") }?.let {
```suggestion }?: hdLink?.takeIf { it.contains("https://") }?.let { ```
cuong-tran (Migrated from github.com) commented 2025-03-12 12:28:49 -05:00
            }?: sdLink?.takeIf { it.contains("https://") }?.let {
```suggestion }?: sdLink?.takeIf { it.contains("https://") }?.let { ```
Hayanek (Migrated from github.com) reviewed 2025-03-12 12:49:49 -05:00
@ -23,2 +28,4 @@
)
}
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
Hayanek (Migrated from github.com) commented 2025-03-12 12:49:49 -05:00

with this I was aware of it but had no idea how to fix it so that such a problem would not occur

with this I was aware of it but had no idea how to fix it so that such a problem would not occur
cuong-tran (Migrated from github.com) reviewed 2025-03-12 23:47:41 -05:00
@ -23,2 +28,4 @@
)
}
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
cuong-tran (Migrated from github.com) commented 2025-03-12 23:47:41 -05:00

Add ?. before toString and conditional action if it's null

Add `?.` before `toString` and conditional action if it's null
cuong-tran (Migrated from github.com) reviewed 2025-03-13 08:15:12 -05:00
@ -23,3 +29,4 @@
}
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
fun getVideosFromUrl(url: String, headers: Headers, prefix: String): List<Video> {
cuong-tran (Migrated from github.com) commented 2025-03-13 08:15:11 -05:00
    private fun decodeVideoLinks(encodedUrl: String): String? {
        if (encodedUrl.isBlank()) {
```suggestion private fun decodeVideoLinks(encodedUrl: String): String? { if (encodedUrl.isBlank()) { ```
cuong-tran (Migrated from github.com) reviewed 2025-03-13 08:16:21 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-13 08:16:21 -05:00
        val url: HttpUrl

        if (isSecondary) {
```suggestion val url: HttpUrl if (isSecondary) { ```
cuong-tran (Migrated from github.com) reviewed 2025-03-13 08:17:32 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-13 08:17:32 -05:00
            val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8)

            url = GETLNKURL.toHttpUrl().newBuilder()
```suggestion val finalText = unicodeEscape.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8) url = GETLNKURL.toHttpUrl().newBuilder() ```
cuong-tran (Migrated from github.com) reviewed 2025-03-13 08:17:56 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-13 08:17:56 -05:00
                 addQueryParameter("link", finalText)
                .build()
        } else {
            url = GETSECONDARYURL.toHttpUrl().newBuilder()
```suggestion addQueryParameter("link", finalText) .build() } else { url = GETSECONDARYURL.toHttpUrl().newBuilder() ```
cuong-tran (Migrated from github.com) reviewed 2025-03-13 08:18:18 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-13 08:18:18 -05:00
                .addQueryParameter("id", episodeId)
                .build()
        }
        client.newCall(GET(url))
            .execute()
```suggestion .addQueryParameter("id", episodeId) .build() } client.newCall(GET(url)) .execute() ```
cuong-tran (Migrated from github.com) reviewed 2025-03-13 10:32:29 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-13 10:32:29 -05:00

also fix indent for the rest of this function (and the whole file?)

also fix indent for the rest of this function (and the whole file?)
Hayanek commented 2025-03-20 06:35:31 -05:00 (Migrated from github.com)

A little delay in approval 😥

A little delay in approval 😥
cuong-tran commented 2025-03-24 00:00:36 -05:00 (Migrated from github.com)

@Hayanek I cannot access the site from my place, got "IP blocked". Have you tested the pl/docchi ext making sure it's working?

@Hayanek I cannot access the site from my place, got "IP blocked". Have you tested the pl/docchi ext making sure it's working?
cuong-tran (Migrated from github.com) reviewed 2025-03-24 01:08:11 -05:00
cuong-tran (Migrated from github.com) commented 2025-03-24 00:39:43 -05:00
```suggestion ```
cuong-tran (Migrated from github.com) commented 2025-03-24 00:40:01 -05:00

also remove the injectLazy import

also remove the injectLazy import
cuong-tran (Migrated from github.com) commented 2025-03-24 00:40:49 -05:00

and the

private val json: Json by injectLazy()
and the ```kotlin private val json: Json by injectLazy() ```
@ -23,3 +29,4 @@
}
// Credit: https://github.com/skoruppa/docchi-stremio-addon/blob/main/app/players/lycoris.py
fun getVideosFromUrl(url: String, headers: Headers, prefix: String): List<Video> {
cuong-tran (Migrated from github.com) commented 2025-03-24 00:41:52 -05:00
        val script = document.selectFirst("script[type='application/json']")?.data() ?: return emptyList()
```suggestion val script = document.selectFirst("script[type='application/json']")?.data() ?: return emptyList() ```
cuong-tran (Migrated from github.com) commented 2025-03-24 01:03:44 -05:00
        val linkList = data.episodeInfo.id?.let { fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false) }

        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) }
```suggestion val linkList = data.episodeInfo.id?.let { fetchAndDecodeVideo(client, data.episodeInfo.id.toString(), isSecondary = false) } 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) } ```
cuong-tran (Migrated from github.com) commented 2025-03-24 01:04:12 -05:00
```suggestion ```
cuong-tran (Migrated from github.com) commented 2025-03-24 01:04:54 -05:00
            } ?: hdLink?.takeIf { it.contains("https://") }?.let {
                videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it))
            }
```suggestion } ?: hdLink?.takeIf { it.contains("https://") }?.let { videos.add(Video(it, "${prefix}lycoris.cafe - 720p", it)) } ```
cuong-tran (Migrated from github.com) commented 2025-03-24 01:05:40 -05:00
            } ?: sdLink?.takeIf { it.contains("https://") }?.let {
```suggestion } ?: sdLink?.takeIf { it.contains("https://") }?.let { ```
cuong-tran (Migrated from github.com) commented 2025-03-24 01:05:47 -05:00

could we use checkLinks() instead of it.contains()?

could we use `checkLinks()` instead of `it.contains()`?
cuong-tran (Migrated from github.com) commented 2025-03-24 01:05:55 -05:00

could we use checkLinks() instead of it.contains()?

could we use `checkLinks()` instead of `it.contains()`?
cuong-tran (Migrated from github.com) commented 2025-03-24 00:42:29 -05:00
                val data = response.body.string()
```suggestion val data = response.body.string() ```
@ -146,3 +144,4 @@
}
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
if (!link.contains("https://")) return false
cuong-tran (Migrated from github.com) commented 2025-03-24 01:06:48 -05:00

Move regex outside and make it lazy load

Move regex outside and make it lazy load
cuong-tran commented 2025-03-24 01:39:15 -05:00 (Migrated from github.com)

Probably need to manually bump pl/docchi version too, since tj-actions/changed-files is disabled.

Probably need to manually bump pl/docchi version too, since `tj-actions/changed-files` is disabled.
Hayanek commented 2025-03-24 10:21:50 -05:00 (Migrated from github.com)

Probably need to manually bump pl/docchi version too, since tj-actions/changed-files is disabled.

ok 😢

> Probably need to manually bump pl/docchi version too, since `tj-actions/changed-files` is disabled. ok 😢
Hayanek (Migrated from github.com) reviewed 2025-03-24 10:42:33 -05:00
@ -146,3 +144,4 @@
}
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
if (!link.contains("https://")) return false
Hayanek (Migrated from github.com) commented 2025-03-24 10:42:33 -05:00

I'll be honest I have no idea why, and how I could do it.

I'll be honest I have no idea why, and how I could do it.
cuong-tran (Migrated from github.com) reviewed 2025-03-24 15:26:12 -05:00
@ -146,3 +144,4 @@
}
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
if (!link.contains("https://")) return false
cuong-tran (Migrated from github.com) commented 2025-03-24 15:26:12 -05:00

move out so it's only needed to be initialized once, not every time the function is called.

Example:

private val wordRegex by lazy { Regex("""\w+""") }
move out so it's only needed to be initialized once, not every time the function is called. Example: ```kotlin private val wordRegex by lazy { Regex("""\w+""") } ```
Hayanek (Migrated from github.com) reviewed 2025-03-24 16:10:12 -05:00
@ -146,3 +144,4 @@
}
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
if (!link.contains("https://")) return false
Hayanek (Migrated from github.com) commented 2025-03-24 16:10:12 -05:00

Will it be good this way?

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.
        ) 
    }

or do I have to knock them all down one by one :(

Will it be good this way? ```kotlin 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. ) } ``` or do I have to knock them all down one by one :(
cuong-tran (Migrated from github.com) reviewed 2025-03-24 22:24:12 -05:00
@ -146,3 +144,4 @@
}
private fun checkLinks(client: OkHttpClient, link: String): Boolean {
if (!link.contains("https://")) return false
cuong-tran (Migrated from github.com) commented 2025-03-24 22:24:12 -05:00

Just move the whole thing out like that is OK

Just move the whole thing out like that is OK
Hayanek commented 2025-03-25 19:39:20 -05:00 (Migrated from github.com)

Probably due to the fact that I also had to fix the Lulu I will wait longer, but less I will wait.

ps. I was sitting for 10 hours and at the very end it turned out that this Lulu User-Agent was missing

Probably due to the fact that I also had to fix the Lulu I will wait longer, but less I will wait. ps. I was sitting for 10 hours and at the very end it turned out that this Lulu User-Agent was missing
cuong-tran (Migrated from github.com) reviewed 2025-03-25 21:55:14 -05:00
@ -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
cuong-tran (Migrated from github.com) commented 2025-03-25 21:55:14 -05:00

It's exact the same as the old headers, why need a new one?
Also, where it was, outside, is better. Same as the Regex one.

It's exact the same as the old headers, why need a new one? Also, where it was, outside, is better. Same as the Regex one.
Hayanek (Migrated from github.com) reviewed 2025-03-25 22:36:05 -05:00
@ -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
Hayanek (Migrated from github.com) commented 2025-03-25 22:36:05 -05:00

Well, not entirely the same if the current one has a user-agent from the application and the previous form relied solely on these 2 headers.
I don't understand which Regex you mean :(

Well, not entirely the same if the current one has a user-agent from the application and the previous form relied solely on these 2 headers. I don't understand which Regex you mean :(
cuong-tran (Migrated from github.com) reviewed 2025-03-26 03:35:20 -05:00
@ -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
cuong-tran (Migrated from github.com) commented 2025-03-26 03:35:20 -05:00

Just change the Headers.Builder() to headers.Builder() then. Keep it outside like you did with the wordRegex previously.
if you meant creating a header based on parameter headers passed in to the function, find where the actual function called and restructure it so the original caller should pass the existed lulu one.

Just change the `Headers.Builder()` to `headers.Builder()` then. Keep it outside like you did with the wordRegex previously. if you meant creating a header based on parameter `headers` passed in to the function, find where the actual function called and restructure it so the original caller should pass the existed lulu one.
cuong-tran (Migrated from github.com) reviewed 2025-04-02 11:51:55 -05:00
@ -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
cuong-tran (Migrated from github.com) commented 2025-04-02 11:49:07 -05:00
        .add("Referer", "https://luluvdo.com/")
```suggestion .add("Referer", "https://luluvdo.com/") ```
cuong-tran (Migrated from github.com) commented 2025-04-02 11:50:18 -05:00
            val quality = getResolution(fixedUrl)
```suggestion val quality = getResolution(fixedUrl) ```
cuong-tran (Migrated from github.com) commented 2025-04-02 11:49:27 -05:00

user urlBuilder instead so it can handles encoding

user `urlBuilder` instead so it can handles encoding
cuong-tran (Migrated from github.com) commented 2025-04-02 11:50:01 -05:00
    private fun getResolution(m3u8Url: String): String {
```suggestion private fun getResolution(m3u8Url: String): String { ```
cuong-tran (Migrated from github.com) reviewed 2025-04-02 13:34:12 -05:00
cuong-tran (Migrated from github.com) commented 2025-04-02 13:34:12 -05:00

trailing slash only for Referer, Origin no trailing

trailing slash only for Referer, Origin no trailing
Hayanek (Migrated from github.com) reviewed 2025-04-03 18:09:03 -05:00
cuong-tran commented 2025-04-06 10:53:32 -05:00 (Migrated from github.com)

All good, I guess.

All good, I guess.
Sign in to join this conversation.
No description provided.