How anime-kun32/hianime-mapper works
1. What this repo is
- Hianime-mapper is a small TypeScript/Node.js API that translates an AniList anime ID into Hianime-related data: anime details, episode/server mappings, and playable streaming sources.
2. Top-level architecture
- The project is organized as a thin HTTP layer plus a set of scraping/decryption helpers.
- The API surface is defined in src/server.ts.
- The heavy lifting is split into src/extractors/ and src/utils/.
3. HTTP entrypoint and routing
- src/server.ts is the main application bootstrap and route registry.
- It is built on Hono.js, so the server is lightweight and likely deployed as a serverless-compatible app.
- The public routes documented in the README are:
- /anime/info/:anilistId
- /anime/servers/:episodeId
- /anime/sources?serverId=...&episodeId=...
4. Request-to-response flow
- A request enters the Hono app in server.ts.
- The route handler calls into utility/extractor code to fetch remote Hianime data.
- The result is normalized into a consistent JSON shape and returned as data: ....
- This means the API is primarily an orchestration layer over external content sources, not a database-backed service.
5. AniList-to-Hianime mapping boundary
- The /anime/info/:anilistId endpoint is the main mapping layer.
- It enriches an AniList ID into a full anime payload plus episodesList, which is the key bridge from metadata to Hianime episode IDs.
- This is the core domain boundary of the repo: AniList identity on one side, Hianime episode/source discovery on the other.
6. Episode server discovery
- /anime/servers/:episodeId exposes the next boundary down the pipeline.
- Given a Hianime episode ID, it returns available sub and dub server lists.
- This is a discovery step before actual video URL extraction.
7. Streaming source extraction
- /anime/sources is the final fetch step in the data flow.
- It accepts serverId and episodeId and returns streaming metadata:
- intro/outro timings
- source URLs and formats
- subtitle tracks
- server identifier
- This endpoint is where playback-ready M3U8-style URLs are surfaced.
8. Extractor subsystem
- src/extractors/megacloud.ts is the only named extractor in the tree, so the repo likely uses a provider-specific implementation for Hianime playback hosts.
- This file is the boundary between the API and the actual host-specific extraction logic.
- The architecture suggests provider swapping is possible, even if only one extractor is currently present.
9. Utility layer responsibilities
- src/utils/client.ts likely centralizes outbound HTTP requests and request headers/session behavior.
- src/utils/decrypt.ts indicates the source URLs or tokens require decryption or signature handling before they can be used.
- src/utils/methods.ts and src/utils/constant.ts likely hold shared parsing logic, string helpers, and fixed values used across routes/extractors.
- This utility layer keeps the route handlers thin and isolates fragile scraping logic.
10. Type and contract surface
- src/index.d.ts suggests the repo defines custom TypeScript types for request/response shapes or extracted payloads.
- That matters architecturally because the API is contract-driven: the response structures in the README are part of the public interface.
11. Deployment/runtime boundary
- vercel.json shows the service is intended for Vercel deployment.
- That implies serverless/edge-style constraints may influence how requests are made, how state is handled, and why the code stays stateless.
12. Cross-origin access
- The README notes CORS is configured in server.ts via an allowlist of frontend origins.
- This indicates the API is meant to be consumed by external web clients, not just server-to-server calls.
13. External dependencies and assumptions
- The API depends on remote services rather than internal storage:
- AniList for anime identity/metadata
- Hianime for episodes/servers/sources
- a Megacloud-like streaming host for media URLs
- There is no evidence of a database, queue, or persistent cache in the repo tree, so the architecture is stateless and fetch-driven.
14. Diagramming takeaway
- The cleanest architecture diagram would show:
- client/front-end callers
- Hono API (server.ts)
- route-specific handlers
- utility/decryption layer
- extractor/provider layer
- external services: AniList, Hianime, and the streaming host
- The key flow is metadata lookup first, then episode/server discovery, then source URL extraction.
Main entry points: server.ts Anime info · megacloud.ts Megacloud · client.ts HTTP client · decrypt.ts Decrypt layer
Components 14
HTTP API
Public request surface and route handlers
- Server · HTTP bootstrap and route registry
src/server.ts - Anime info · AniList ID to anime payload and episode list
src/server.ts - Episode servers · Episode ID to sub and dub server lists
src/server.ts - Streaming sources · Server and episode ID to playback-ready source data
src/server.ts
Core pipeline
Shared utilities, extraction logic, and contracts
- HTTP client · Outbound requests and request/session behavior
src/utils/client.ts - Decrypt layer · Token or source decryption and signature handling
src/utils/decrypt.ts - Shared helpers · Common methods and constants used across routes
src/utils/methods.ts - Megacloud · Host-specific source extraction implementation
src/extractors/megacloud.ts - Contracts · Custom response and payload type definitions
src/index.d.ts
External systems
Remote services and deployment target
- Clients · Frontend or API consumers invoking the service
- AniList · Anime identity and metadata source
- Hianime · Episode, server, and source discovery target
- Stream host · Playback host behind extracted source URLs
- Vercel · Serverless deployment target
vercel.json
Connections 19
- Clients → Server: HTTP request · Consumers call the public API
- Server → Anime info: registers · Route registry exposes AniList mapping endpoint
- Server → Episode servers: registers · Route registry exposes server discovery endpoint
- Server → Streaming sources: registers · Route registry exposes streaming source endpoint
- Anime info → AniList: lookup · Resolves AniList identity and metadata
- Anime info → Hianime: map · Translates metadata into Hianime episode listings
- Anime info → HTTP client: fetch · Uses shared outbound client for remote requests
- Anime info → Shared helpers: normalize · Applies shared parsing and shaping logic
- Anime info → Contracts: contracts · Returns typed API payloads
- Episode servers → Hianime: discover · Fetches episode server lists from Hianime
- Episode servers → HTTP client: fetch · Uses shared outbound client for remote requests
- Episode servers → Shared helpers: parse · Reuses shared parsing and constants
- Streaming sources → Hianime: resolve · Uses episode and server IDs to reach source data
- Streaming sources → Megacloud: extract · Delegates host-specific playback extraction
- Streaming sources → Decrypt layer: decrypt · Decodes signed or protected source data
- Megacloud → Stream host: load · Pulls playable media URLs from the host
- Megacloud → HTTP client: fetch · Uses shared outbound client for remote requests
- Megacloud → Decrypt layer: decrypt · Handles provider-specific protected payloads
- Server → Vercel: deploys on · Configured for Vercel runtime