Keiyoushi Extensions Source

repository·main·Indexed 26 days ago

https://github.com/keiyoushi/extensions-source

Source code for content extensions compatible with readers such as Mihon or Tachiyomi. Includes libraries for internationalization (Intl), Publus authentication (PublusAuth, PublusAuthHandler), Speedbinb content handling (ServerType, ViewMode), and GraphQL variable types for Senkuro manga searches and details.

Tokens
2.2K
Snippets
4
Records
21
Agent score
78%

What's inside keiyoushi-extensions-source

  1. Add the Keiyoushi Extensions repository

    main

    To use the extensions provided by this repository, you must add the repository URL to your application. You can do this in two ways:

    1. Via the Keiyoushi Website: Visit https://keiyoushi.github.io/add-repo to follow the automated process.
    2. Manual Entry: Copy and paste the following URL directly into your application's repository management section: https://github.com/keiyoushi/extensions/raw/repo/index.pb

    For new users, it is recommended to read the Keiyoushi Getting Started guide before proceeding.

    https://github.com/keiyoushi/extensions/raw/repo/index.pb
  2. Request a new source or bug fix

    main

    If you need a new source added or a bug fixed in an existing extension, you can create an issue on GitHub.

    Note: Work is volunteer-based, so requests may not be fulfilled immediately. Some sources may be impossible or too difficult to maintain. If you have the skills to fix a bug or add a source yourself, you are encouraged to contribute by picking up an unassigned issue from the issue backlog.

  3. Organize internationalization message files

    main

    Message files for the Intl class must be stored in the assets/i18n folder. The naming convention follows the pattern messages_{iso_639_1}.properties, where {iso_639_1} is the language code in lowercase snake case (e.g., en, fr_ca).

    Important Requirements:

    • Use UTF-8 encoding for all .properties files.
    • If using Android Studio, ensure it is configured to save Properties files as UTF-8.
  4. Manage and refresh authentication with PublusAuthHandler

    main

    The PublusAuthHandler manages a cache of PublusAuth objects (e.g., per-chapter) and automatically refreshes them when they become stale. This ensures signed image URLs remain valid during a reading session.

    To use PublusAuthHandler, you must provide:

    1. An OkHttpClient for network calls.
    2. refreshSeconds: The duration in seconds before the cached auth is considered stale.
    3. cookieUrl (optional): A URL used to load cookies for the refresh request.
    4. bid (optional): A value to be passed to toAuth during refresh.
    5. buildRequest: A lambda that constructs the Request used to fetch new auth info, receiving the current session map and loaded cookies.
  5. Retrieve translated strings using Intl.get()

    main

    The get operator allows you to retrieve a string from the message files using a key. It follows a fallback hierarchy:

    1. Returns the value from the chosenLanguage bundle.
    2. If the key is missing in the chosen language, it falls back to the baseLanguage (English) bundle.
    3. If the key is missing in both, it returns the key wrapped in brackets: [key].
  6. Convert PublusAuthInfo to PublusAuth

    main

    The PublusAuthInfo class represents the auth_info block returned by a Publus content API. Use toAuth to convert this data into a PublusAuth object suitable for making requests.

    Parameters for toAuth:

    • bid: The value for the BID query parameter.
    • includeBookAuth: If false, book-scoped parameters (hti, cfg, uuid, BID) are dropped, leaving only the CloudFront signature parameters (pfCd, policy, signature, keyPairId).
  7. Generate Speedbinb content URLs with BibContentItem.getSbcUrl()

    main

    The BibContentItem class provides a getSbcUrl method to construct the appropriate URL for fetching content based on the serverType.

    Depending on the serverType, it will construct URLs for:

    • DIRECT: Appends content.js.
    • REST: Appends content.
    • SBC: Appends sbcGetCntnt.php and includes query parameters such as cid, p (if requestToken is present), q=1, vm (view mode), and dmytime (content date or current timestamp).
    fun getSbcUrl(readerUrl: HttpUrl, cid: String) = contentServer.toHttpUrl().newBuilder().apply {
        when (serverType) {
            ServerType.DIRECT -> addPathSegment("content.js")
            ServerType.REST -> addPathSegment("content")
            ServerType.SBC -> {
                addPathSegment("sbcGetCntnt.php")
                setQueryParameter("cid", cid)
                requestToken?.let { setQueryParameter("p", it) }
                setQueryParameter("q", "1")
                setQueryParameter("vm", viewMode.toString())
                setQueryParameter("dmytime", contentDate ?: System.currentTimeMillis().toString())
                copyKeyParametersFrom(readerUrl)
            }
            else -> throw UnsupportedOperationException("Unsupported ServerType value $serverType")
        }
    }.toString()