Files
documentation/sdk/vyla-sdk/manga.md

131 lines
4.0 KiB
Markdown

# Manga Resolution Module
<p class="page-description">How to integrate manga title discovery, chapter listings, and high-resolution page resolution using the Vyla SDK.</p>
## Overview
In addition to video streaming, `@vyla-entertainment/sdk` includes a native Manga resolution module. Powered by `atsu.moe` and leveraging `node-tls-client`, the module bypasses anti-bot TLS fingerprinting by mimicking real Google Chrome 131 cryptographic handshakes.
This allows developers to build responsive, ad-free manga reading interfaces directly into their applications.
---
## Technical Architecture
Upstream manga archives frequently block standard Node.js `fetch` or `axios` requests using JA3/JA4 TLS fingerprinting. To ensure reliable connectivity:
1. **TLS Emulation**: Uses `node-tls-client` configured with `ClientIdentifier.chrome_131`.
2. **Session Persistence**: Reuses keep-alive TLS sessions across search and chapter page requests.
3. **Structured Geometry**: Returns explicit image dimensions (`width`, `height`) and pre-calculated aspect ratios so mobile and desktop readers can prevent layout shifts during image loading.
---
## Manga Methods
### 1. Searching for Titles
Search the manga catalog by query string with pagination support:
```javascript
import VylaSDK from '@vyla-entertainment/sdk';
const sdk = new VylaSDK();
const searchResult = await sdk.searchManga('Chainsaw Man', 1, 10);
console.log(`Total results: ${searchResult.total}`);
searchResult.results.forEach((manga) => {
console.log(`[ID: ${manga.id}] ${manga.title} (${manga.status})`);
});
```
#### Search Response Structure
```json
{
"page": 1,
"total": 42,
"results": [
{
"id": "chainsaw-man",
"title": "Chainsaw Man",
"englishTitle": "Chainsaw Man",
"authors": ["Tatsuki Fujimoto"],
"type": "Manga",
"medium": "MANGA",
"status": "Ongoing",
"year": 2018,
"rating": 8.7,
"popularity": 120000,
"poster": "https://cdn.atsu.moe/static/covers/chainsaw-man.webp",
"posterSmall": "https://cdn.atsu.moe/static/covers/chainsaw-man-sm.webp",
"posterMedium": "https://cdn.atsu.moe/static/covers/chainsaw-man-md.webp"
}
]
}
```
---
### 2. Fetching Manga Details & Chapters
Retrieve full metadata, synopsis, genres, and the complete chapter index:
```javascript
const mangaDetails = await sdk.getManga('chainsaw-man');
console.log('Title:', mangaDetails.title);
console.log('Synopsis:', mangaDetails.synopsis);
console.log('Genres:', mangaDetails.genres.join(', '));
console.log('Available Chapters:', mangaDetails.chapters.length);
const latest = mangaDetails.chapters[0];
console.log(`Latest Chapter: ${latest.number} (ID: ${latest.id})`);
```
---
### 3. Resolving Chapter Pages
To render the reader view, fetch the ordered page image assets for a specific chapter:
```javascript
const mangaId = 'chainsaw-man';
const chapterId = 'chapter-1';
const chapter = await sdk.getMangaChapter(mangaId, chapterId);
console.log(`Chapter ${chapter.number} contains ${chapter.pages.length} pages.`);
chapter.pages.forEach((page) => {
console.log(`Page ${page.number}: ${page.url} [${page.width}x${page.height}]`);
});
```
#### Chapter Response Structure
```json
{
"id": "chapter-1",
"number": 1,
"title": "Dog & Chainsaw",
"scanlatorId": null,
"pages": [
{
"number": 1,
"url": "https://cdn.atsu.moe/static/data/.../01.webp",
"width": 1080,
"height": 1600,
"aspectRatio": 0.675
}
]
}
```
---
## Reader Layout Best Practices
When rendering manga pages in a frontend reader:
1. **Prevent Cumulative Layout Shift (CLS)**: Use the provided `aspectRatio` or `width`/`height` in CSS (`aspect-ratio: attr(width) / attr(height);`) to reserve vertical scroll space before each image finishes downloading.
2. **Preload Neighboring Pages**: Implement a 2-page lookahead preloader so viewers turning pages experience instantaneous transitions.
3. **Session Cleanup**: In long-running background tasks, invoke `cleanup()` from `src/manga/atsu.js` when closing reader sessions to terminate idle TLS sockets.