Introducing a new way to review your PRs.

Read the announcement

keiyoushi / extensions-source

Source code of extensions in https://github.com/keiyoushi/extensions

View on GitHub

13 documents · Updated Nov 19, 2026

docs / core-extension-api

Core extension API

Overview

The core/** module is the shared Kotlin/Android library that extension modules compile against. core/build.gradle.kts declares it as an Android library under namespace keiyoushi.core, with Tachiyomi/Mihon and common dependencies as compileOnly; extension authors get API types and helpers without bundling the host app implementation.

The main extension base class is keiyoushi.source.KeiSource in core/…/KeiSource.kt. It extends Tachiyomi's HttpSource, makes the inherited headers eager, and exposes suspend-first entry points for popular/latest/search, URL search resolution, manga updates, related manga, page lists, and image requests. Subclasses implement getPopularManga, getLatestUpdates, getSearchMangaList, fetchMangaUpdate, and getPageList; URL queries are intercepted in getSearchManga and routed to getMangasByUrl/getMangaByUrl when the query parses as an HttpUrl. getMangaUpdate serializes concurrent updates by SManga.url, requires at least one of details/chapters, and always marks returned manga initialized before handing the SMangaUpdate back to the host.

KeiSource.client centralizes the extension HTTP stack. It starts from the host default client, checks that important host interceptors are present or absent, optionally installs BaseUrlFetchInterceptor before source interceptors, runs the source's configureClient, moves Cloudflare handling below source-specific interceptors, then adds browser request tagging/compression/cache/browser-header behavior. Extension authors customize it by overriding OkHttpClient.Builder.configureClient() rather than overriding client; request helpers in core/…/OkHttp.kt provide suspend get, post, put, head, and call overloads, including context-receiver forms that pull HttpSource.headers automatically.

Base URL state is modeled in core/…/FetchableBaseUrl.kt, CustomUrlPreferences.kt, and MirrorPreferences.kt. CustomUrlPreferences stores overrideBaseUrl, defaultBaseUrl, and fetchedBaseUrl, sanitizes user-entered URLs to scheme/host/port, and exposes an EditTextPreference. MirrorPreferences stores a selected mirror index plus fetched mirror lists and exposes a ListPreference only when there are at least two options. KeiSource.fetchBaseUrls runs once per app launch before the first source request when fetchableBaseUrl is present, normalizes and de-duplicates fetched URLs, and updates either custom URL or mirror state.

Dynamic filters are also handled by KeiSource.kt. Sources that set supportsFilterFetching = true implement fetchFilterData() and a fast, synchronous getFilterList(data: JsonElement?). Core caches fetched JSON as applicationContext.cacheDir/source_$id/filters.json.zst for three days, limits retries to three failures per launch, and returns the source's fallback filters plus a localized header hint while cache data is unavailable.

core/…/UrlActivity.kt is a tiny deep-link shim: when launched with a data URI it starts the host eu.kanade.tachiyomi.SEARCH action with query set to that URI and filter set to the extension package, then exits. core/…/Source.kt provides a source-retention class annotation used by extension tooling.

Key packages/classes

How extension authors use the APIs

Extension sources should subclass KeiSource from core/…/KeiSource.kt and override the documented suspend methods instead of Tachiyomi's older callback-style parsing methods. Use configureHeaders() to add source headers; core always sets Referer to $baseUrl/, and KeiSource.client later augments per-request browser headers based on Fetch. Use configureClient() to install per-source interceptors, cookies, rate limits, custom DNS/cache/timeouts, GraphQL error interceptors, or XOR/AES decoding.

For HTTP calls, prefer client.get(url, Fetch.XHR), client.get(url, Fetch.DOCUMENT.from(pageUrl)), client.post(url, Fetch.XHR, body), or a manually built Request.Builder().fetch(Fetch.SCRIPT) from core/…/OkHttp.kt and BrowserRequests.kt. Fetch.from controls referrer trimming across redirects and cross-origin hops. Fetch.NONE deliberately sends a request as built; KeiSource.imageRequest adds imageFetch to normal GET image loads when a custom image request did not already set a fetch kind.

Use OkHttpClient.Builder.rateLimit from core/…/RateLimit.kt for sliding-window request limits, defining specific URL predicates before broad rules because the first matching rule wins. Use addCookie from core/…/Cookie.kt to mirror source cookies into both OkHttp requests and Android CookieManager for matching domains.

For common response processing, Json.kt and JsonElement.kt provide parseAs, toJsonRequestBody, toJsonElement, and ergonomic JSON accessors; Jsoup.kt parses responses or strings into Jsoup documents and offers nullable selectors/text helpers; Markdown.kt builds safe Tachiyomi descriptions from text, HTML, ratings, fields, alt titles, and links. GraphQL.kt builds POST bodies or GET query parameters, persisted query extensions, and parseGraphQLAs envelopes. NextJs.kt extracts serializable models from Next.js Pages Router hydration, App Router self.__next_f.push scripts, or raw text/x-component RSC responses, resolving React Flight markers, outlined model refs, maps/sets, lazy refs, promises, large text chunks, dates, bigints, and non-finite numbers.

For encrypted or binary sources, Crypto.kt covers hex decoding, MD5/SHA/HMAC, RC4, XOR response/source transforms, AES CBC/GCM/CTR/ECB, AES streaming response decryption, prepended-IV decryption, EVP_BytesToKey, and CryptoJS-compatible salted AES. Protobuf.kt supports injected ProtoBuf, byte-array/base64 encode/decode, streaming BufferedSource decode, and chunked protobuf RequestBody creation. Zip.kt/RemoteZip.kt let an extension list and fetch image archives without downloading the full ZIP, provided the server honors range requests.

For JavaScript-heavy or protected sites, runWebView in core/…/WebView.kt is the extension-facing WebView DSL. Call loadUrl or loadData once, then resolve/reject from page hooks, polling, JS evaluation, web-message bridges, or intercepted requests. proxyRequest converts selected WebView GETs into OkHttp requests with an inferred Fetch kind so the source client can add the same browser headers and share cookies. showToUser/hideFromUser expose a WebView or selected CSS area when a human tap is needed; getTurnstileToken in TurnstileHelper.kt packages that flow for Cloudflare Turnstile.

Notable tests/resources/translations

Coupling

Risks

  • core/…/KeiSource.kt uses reflection to replace Tachiyomi HttpSource's private headers$delegate. If the upstream field name or lazy contract changes, source initialization can fail before any network request.
  • core/…/WebView.kt falls back from native origin-scoped messaging to addJavascriptInterface on old Chromium versions; the fallback ignores allowedOriginRules and reports null sender origin, so a bridge handler that trusts origin checks may accept messages from unexpected frames unless it requires modern WebView support.
  • core/…/RemoteZip.kt assumes servers honor byte range requests and provide a valid Content-Range total. If a source points it at a CDN that strips Range, rangeSource() throws and archive-backed chapters cannot load.