Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nijiero-ch extension 1.0 #3245

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

Moddimation
Copy link

This extension is NSFW related, and is less a manga reader, and more an image browser for NSFW content.
The original is "https://nijiero-ch.com/".
Latest is not supported, as i could not get a dedicated link that points to latest content. The website is a little dated anyways.

I tested it multiple times, and it should work. The search is only meant to search for tags or categories. If a genre/tag is specified, search is overriden. If it could not find either category/ or tag/, it searches for the other. I have not tested invalid search results yet, but everything else should work quite decently.

Please ask if needed, my discord is "Moddimation", aka "Moddigi Luigi".

@Moddimation
Copy link
Author

I am done with my fixup, requesting review

@Moddimation
Copy link
Author

oh nvm im dumb

@choppeh
Copy link
Contributor

choppeh commented May 27, 2024

You can use the code below to get the tags. (I had some problems making a PR for your fork)

    class Tag(val name: String, val ref: String) {
        override fun toString() = name
    }
    class TagFilter(name: String, values: Array<Tag>) :
        Filter.Select<Tag>(name, values) {
        fun selectedValue() = values[state].ref
    }

    override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
        val keyword = when {
            query.isBlank() -> filters.filterIsInstance<TagFilter>().firstOrNull()?.selectedValue() ?: "various"
            else -> query
        }.replace(spaceRegex, "-").lowercase()

        val uniqueParam = System.currentTimeMillis()

        var url = "$baseUrl/category/$keyword/page/$page/".toHttpUrl().newBuilder()
            .addQueryParameter("refresh", "$uniqueParam")
            .build()

        // if 404, recheck
        if (client.newCall(GET(url, headers)).execute().code == 404) {
            url = "$baseUrl/tag/$keyword/page/$page".toHttpUrl().newBuilder()
                .addQueryParameter("refresh", uniqueParam.toString())
                .build()
            // if there is a better solution just *tell me* .
        }

        return GET(url, headers)
    }

    override fun getFilterList(): FilterList {
        CoroutineScope(Dispatchers.IO).launch { fetchTags() }

        val filters = mutableListOf<Filter<*>>(
            Filter.Header("You can search for a tag or category, anything else will result in 404(NOT FOUND)."),
            Filter.Header("To use category, make sure the search box is empty."),
        )

        filters += when {
            nijieroTags.isNotEmpty() -> listOf(TagFilter("Category", nijieroTags))
            else -> listOf(Filter.Separator(), Filter.Header("Press 'Reset' to attempt to show the tags"))
        }

        return FilterList(filters)
    }

    private var fetchTagsAttempts: Int = 0

    private fun fetchTags() {
        if (fetchTagsAttempts < 3 && nijieroTags.isEmpty()) {
            try {
                nijieroTags = client.newCall(tagsRequest()).execute().use { parseTags(it.asJsoup()) }
            } catch (_: Exception) {
            } finally {
                fetchTagsAttempts++
            }
        }
    }

    fun tagsRequest(): Request {
        return GET("$baseUrl/allsearch.html", headers)
    }

    private fun parseTags(document: Document): Array<Tag> {
        return document.select("dl.tagList02 dd a")
            .map { element ->
                Tag(
                    element.text().split(" ").first(),
                    element.attr("href").substringAfter("category/"),
                )
            }
            .toTypedArray()
    }

Run

This is just a quick copy and paste from other implementations I've done; you need to treat the keyword properly, as I only considered the tag paths

Comment on lines +58 to +64
url = baseUrl.toHttpUrl().newBuilder()
.addEncodedPathSegment("tag")
.addEncodedPathSegment(keyword)
.addEncodedPathSegment("page")
.addEncodedPathSegment(page.toString())
.addQueryParameter("refresh", uniqueParam.toString())
.build()
Copy link
Contributor

@choppeh choppeh May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find this path in the source

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...? You mean, like, file path? If you mean the website, try $baseurl/tag/gif, that should exist.

@choppeh
Copy link
Contributor

choppeh commented May 27, 2024

All the content (titles and tags) is in Japanese, I think it would be better to localize it to “jp” instead of “all”.

@choppeh
Copy link
Contributor

choppeh commented May 27, 2024

You need to create a new branch from the m̀ain. See: Submitting the changes

.build()

// if 404, recheck
if (client.newCall(GET(url, headers)).execute().code == 404) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to do this in an interceptor, so you can simply return the response as is if available or make new request and return it's response

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should actually check if the current page was not found as a tag, so it tries again with category... not sure what you mean by that, sorry.

Copy link
Contributor

@AwkwardPeak7 AwkwardPeak7 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean instead of make a call just to check if it exists, add an interceptor to detect it and make new call there.

basically return the tag request from here, in the interceptor prceed the call and check if it is 404 and url contains tag (this request) and if so, modify the request and call again, otherwise just return the original response.

something like this:

private fun tagCategoryInterceptor(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val url = request.url.toString()
        val response = chain.proceed(request)

        if (!response.isSuccessful && response.code == 404 && url.contains("/category/")) {
            val newUrl = url.replace("/category/","/tag/")
            val newRequest = request.newBuilder()
                .url(newUrl)
                .build()
            
            return chain.proceed(newRequest)
        }

        return response
    }

@Moddimation
Copy link
Author

All the content (titles and tags) is in Japanese, I think it would be better to localize it to “jp” instead of “all”.

@ttony2chopper I originally made the extension so that i can read it, so i made some stuff english. Is it required to move it all onto japanese in this case? I am not fluent in that language...

@Moddimation
Copy link
Author

Moddimation commented May 27, 2024

The tag and category links are, in reverse, almost all english/romanji, except some tags, thats why i just put english/romanji tags here. This is related to the former comment

@Moddimation
Copy link
Author

To the branch: I commited to a branch called "pr", how do i set this PR to the branch? Do i need to create a new PR?

@AwkwardPeak7
Copy link
Contributor

To the branch: I commited to a branch called "pr", how do i set this PR to the branch? Do i need to create a new PR?

you should push those commits in this branch, otherwise you would have to make a new pr

Copy link
Contributor

@AwkwardPeak7 AwkwardPeak7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra changes in common.gradle and settings.gradle.kts

@Moddimation
Copy link
Author

I actually found several bugs, such as popular not showing images, some non manga entries included in recent sometimes, and tags with / dont work (%2F).

I dont think i have time to update this, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants