/** * Komikcast Scraper (Inertia.js SSR State Bypass) * Target: https://komikcast.info * Author: Vamz Spectre (VamxAPI) * * Features: * - Manga Search with pagination, status, and latest chapter info * - Latest Manga Updates & Popular Manga * - Manga Detail (synopsis, author, artist, genres, full chapters list) * - Chapter Reader (high-res direct R2 CDN image list, prev/next chapter navigation) * * Usage: * curl -sL "https://code.vamxapi.my.id/snippet/raw/komikcast-scraper" -o komikcast-scraper.js * node komikcast-scraper.js "solo" * node komikcast-scraper.js "solo-swordmaster" * node komikcast-scraper.js "solo-swordmaster" 23 * node komikcast-scraper.js "https://komikcast.info/manga/solo-swordmaster/chapter/23" */ const https = require('https'); const http = require('http'); const { URL } = require('url'); class KomikcastScraper { constructor(options = {}) { this.baseUrl = options.baseUrl || 'https://komikcast.info'; this.timeout = options.timeout || 15000; this.userAgent = options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'; } /** * Internal request to fetch and parse Inertia.js data-page props */ fetchProps(endpoint) { return new Promise((resolve, reject) => { const targetUrl = endpoint.startsWith('http') ? endpoint : `${this.baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`; const client = targetUrl.startsWith('https') ? https : http; const req = client.get(targetUrl, { timeout: this.timeout, headers: { 'User-Agent': this.userAgent, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.9,id;q=0.8', 'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"', 'Sec-Ch-Ua-Mobile': '?0', 'Sec-Ch-Ua-Platform': '"Windows"' } }, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { const redirectUrl = new URL(res.headers.location, targetUrl).toString(); return resolve(this.fetchProps(redirectUrl)); } if (res.statusCode !== 200) { return reject(new Error(`Gagal menghubungi Komikcast (HTTP ${res.statusCode})`)); } let body = ''; res.on('data', (chunk) => body += chunk); res.on('end', () => { try { const match = body.match(/data-page="([^"]+)"/); if (!match) { return reject(new Error('Gagal mengekstrak data-page dari respons Komikcast.')); } const decoded = match[1] .replace(/"/g, '"') .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/'/g, "'"); const pageJson = JSON.parse(decoded); resolve(pageJson.props || {}); } catch (err) { reject(new Error(`Gagal mem-parsing data Komikcast: ${err.message}`)); } }); }); req.on('error', reject); req.on('timeout', () => { req.destroy(); reject(new Error('Request timeout saat menghubungi Komikcast.')); }); }); } /** * Search manga by keyword */ async search(query, page = 1) { if (!query) throw new Error('Query pencarian manga tidak boleh kosong.'); const props = await this.fetchProps(`/manga?search=${encodeURIComponent(query)}&page=${page}`); const mangas = props.mangas || {}; const items = (mangas.data || []).map((item) => ({ id: item.id, title: item.title, slug: item.slug, url: `${this.baseUrl}/manga/${item.slug}`, poster: item.poster, type: item.type, status: item.status, rating: item.rating, release_year: item.release_year, author: item.author, artist: item.artist, genres: (item.genres || []).map((g) => g.name), last_chapter: item.last_chapter ? { id: item.last_chapter.id, title: item.last_chapter.title, chapter_number: item.last_chapter.chapter_number, url: `${this.baseUrl}/manga/${item.slug}/chapter/${item.last_chapter.chapter_number}` } : null })); return { status: true, creator: 'Vamz Spectre', data: { query, current_page: mangas.current_page || 1, last_page: mangas.last_page || 1, total_results: mangas.total || items.length, results: items } }; } /** * Get latest updated mangas */ async latest(page = 1) { const props = await this.fetchProps(`/manga?sort=latest&page=${page}`); const mangas = props.mangas || {}; const items = (mangas.data || []).map((item) => ({ id: item.id, title: item.title, slug: item.slug, url: `${this.baseUrl}/manga/${item.slug}`, poster: item.poster, type: item.type, status: item.status, rating: item.rating, genres: (item.genres || []).map((g) => g.name), last_chapter: item.last_chapter ? { id: item.last_chapter.id, title: item.last_chapter.title, chapter_number: item.last_chapter.chapter_number, url: `${this.baseUrl}/manga/${item.slug}/chapter/${item.last_chapter.chapter_number}` } : null })); return { status: true, creator: 'Vamz Spectre', data: { page: mangas.current_page || 1, last_page: mangas.last_page || 1, total: mangas.total || items.length, results: items } }; } /** * Get popular mangas */ async popular(page = 1) { const props = await this.fetchProps(`/manga?sort=popular&page=${page}`); const mangas = props.mangas || {}; const items = (mangas.data || []).map((item) => ({ id: item.id, title: item.title, slug: item.slug, url: `${this.baseUrl}/manga/${item.slug}`, poster: item.poster, type: item.type, status: item.status, rating: item.rating, genres: (item.genres || []).map((g) => g.name), last_chapter: item.last_chapter ? { id: item.last_chapter.id, title: item.last_chapter.title, chapter_number: item.last_chapter.chapter_number, url: `${this.baseUrl}/manga/${item.slug}/chapter/${item.last_chapter.chapter_number}` } : null })); return { status: true, creator: 'Vamz Spectre', data: { page: mangas.current_page || 1, last_page: mangas.last_page || 1, total: mangas.total || items.length, results: items } }; } /** * Get full manga details & chapter list */ async detail(slugOrUrl) { let slug = slugOrUrl; if (slugOrUrl.includes('/manga/')) { const match = slugOrUrl.match(/\/manga\/([^/?#]+)/); if (match) slug = match[1]; } slug = slug.trim().replace(/^\/+|\/+$/g, ''); const props = await this.fetchProps(`/manga/${slug}`); const m = props.manga; if (!m) throw new Error(`Manga dengan slug "${slug}" tidak ditemukan.`); const chapters = (m.chapters || []).map((c) => ({ id: c.id, title: c.title, slug: c.slug, chapter_number: c.chapter_number, url: `${this.baseUrl}/manga/${m.slug}/chapter/${c.chapter_number}`, views_count: c.views_count, created_at: c.created_at })); return { status: true, creator: 'Vamz Spectre', data: { id: m.id, title: m.title, slug: m.slug, url: `${this.baseUrl}/manga/${m.slug}`, poster: m.poster, synopsis: m.synopsis, type: m.type, status: m.status, author: m.author, artist: m.artist, rating: m.rating, release_year: m.release_year, views_count: m.views_count, genres: (m.genres || []).map((g) => ({ name: g.name, slug: g.slug, icon: g.icon })), total_chapters: chapters.length, first_chapter: props.firstChapter ? { chapter_number: props.firstChapter.chapter_number, url: `${this.baseUrl}/manga/${m.slug}/chapter/${props.firstChapter.chapter_number}` } : null, chapters } }; } /** * Get chapter reading pages / images */ async chapter(slugOrUrl, chapterNumber = null) { let targetPath = ''; if (slugOrUrl.startsWith('http')) { const urlObj = new URL(slugOrUrl); targetPath = urlObj.pathname; } else if (chapterNumber !== null && chapterNumber !== undefined) { targetPath = `/manga/${slugOrUrl}/chapter/${chapterNumber}`; } else if (slugOrUrl.includes('/chapter/')) { targetPath = slugOrUrl; } else { throw new Error('Format pemanggilan chapter tidak valid. Gunakan (slug, chapterNumber) atau URL chapter.'); } const props = await this.fetchProps(targetPath); const ch = props.chapter; const m = props.manga; if (!ch) throw new Error('Data chapter tidak ditemukan.'); const images = (ch.images || []).map((img, idx) => ({ order: img.order !== undefined ? img.order : idx, url: img.r2_url || img.image_path, bytes: img.r2_bytes || null })); return { status: true, creator: 'Vamz Spectre', data: { chapter_id: ch.id, manga_title: m?.title || null, manga_slug: m?.slug || null, chapter_title: ch.title, chapter_number: ch.chapter_number, total_images: images.length, navigation: { prev: props.prev ? `${this.baseUrl}/manga/${m?.slug}/chapter/${props.prev.chapter_number}` : null, next: props.next ? `${this.baseUrl}/manga/${m?.slug}/chapter/${props.next.chapter_number}` : null }, images } }; } } // CLI Runner if (require.main === module) { const arg1 = process.argv[2]; const arg2 = process.argv[3]; if (!arg1) { console.log(JSON.stringify({ status: false, message: 'Parameter query/slug/URL komikcast wajib disertakan.', usage: [ 'node komikcast-scraper.js "solo"', 'node komikcast-scraper.js "latest"', 'node komikcast-scraper.js "popular"', 'node komikcast-scraper.js "solo-swordmaster"', 'node komikcast-scraper.js "solo-swordmaster" 23', 'node komikcast-scraper.js "https://komikcast.info/manga/solo-swordmaster/chapter/23"' ] }, null, 2)); process.exit(1); } const scraper = new KomikcastScraper(); (async () => { if (arg1 === 'latest') { return await scraper.latest(Number(arg2) || 1); } if (arg1 === 'popular') { return await scraper.popular(Number(arg2) || 1); } if (arg2) { return await scraper.chapter(arg1, arg2); } if (arg1.startsWith('http')) { if (arg1.includes('/chapter/')) { return await scraper.chapter(arg1); } return await scraper.detail(arg1); } // If it looks like a clean slug without spaces, fetch detail, otherwise search if (/^[a-z0-9-]+$/i.test(arg1) && !arg1.includes(' ')) { try { return await scraper.detail(arg1); } catch (_) { return await scraper.search(arg1); } } return await scraper.search(arg1); })() .then((res) => { console.log(JSON.stringify(res, null, 2)); }) .catch((err) => { console.log(JSON.stringify({ status: false, error: err.message }, null, 2)); process.exit(1); }); } module.exports = KomikcastScraper;