import * as cheerio from 'cheerio' import { pathToFileURL } from 'node:url' import dns from 'node:dns' dns.setDefaultResultOrder('ipv4first') /** * Otakudesu Scraper (otakudesu.fit) * Sumber: kyiov/mithra-ex (system/lib/scraper/otakudesu.js) */ const BASE = 'https://otakudesu.fit' const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' async function get(url) { const r = await fetch(url, { headers: { 'User-Agent': UA, Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'id-ID,id;q=0.9,en;q=0.8', Referer: BASE + '/', Cookie: 'sg=1', // Bypass searchguard check }, redirect: 'follow', signal: AbortSignal.timeout(25000), }) const body = await r.text() if (r.status !== 200) throw new Error(`HTTP ${r.status} untuk ${url}`) return body } function toAbs(u) { if (!u) return '' if (u.startsWith('http')) return u return BASE + (u.startsWith('/') ? u : '/' + u) } /** * Cari anime via ?s=&post_type=anime */ export async function searchAnime(query) { const q = String(query || '').trim() if (!q) return [] try { const html = await get(`${BASE}/?s=${encodeURIComponent(q)}&post_type=anime`) const $ = cheerio.load(html) const results = [] $('article.bs').each((i, el) => { const a = $(el).find('a.tip[href*="/series/"]').first() const href = a.attr('href') || '' const title = (a.attr('title') || a.text().trim() || '').replace(/\s+/g, ' ') const img = $(el).find('img').first().attr('src') || '' if (!href || !title) return results.push({ source: 'otakudesu', title, url: toAbs(href), image: img, type: $(el).find('.typez').first().text().trim() || 'Anime', rating: $(el).find('.rating').first().text().trim() || '', status: $(el).find('.epx, .status').first().text().trim() || '', }) }) return results } catch (e) { console.error('[otakudesu] search error:', e.message) return [] } } /** * Ambil detail anime: info, genre, sinopsis, dan daftar episode */ export async function getAnimeDetail(url) { const html = await get(url) const $ = cheerio.load(html) const title = $('h1').first().text().trim() || $('title').text().replace(/ - Otaku Desu.*$/i, '').trim() const img = $('.single-info .thumb img, .info-left img, .bixbox .thumb img').first().attr('src') || '' let status = '' let studio = '' const spe = $('.spe').first().text().replace(/\s+/g, ' ') const stM = spe.match(/Status:\s*([^,]+?)(?:\s+(?:Studio|Released|Season|Type|Duration|Score|Producer|Total|Rating):|$)/i) if (stM) status = stM[1].trim() const stuM = spe.match(/Studio:\s*([^,]+?)(?:\s+(?:Released|Season|Type|Duration|Score|Producer|Total|Rating):|$)/i) if (stuM) studio = stuM[1].trim() const genres = [] $('a[href*="/genres/"]').each((i, el) => { const t = $(el).text().trim() if (t && !genres.includes(t)) genres.push(t) }) const episodes = [] const seen = new Set() // Parsing dari daftar .eplister jika tersedia $('.eplister ul li').each((i, el) => { const a = $(el).find('a').first() const href = a.attr('href') || '' const epNumStr = $(el).find('.epl-num').first().text().trim() const epTitle = $(el).find('.epl-title').first().text().trim() || a.text().trim() const date = $(el).find('.epl-date').first().text().trim() const num = parseInt(epNumStr, 10) || i + 1 if (href && !seen.has(href)) { seen.add(href) episodes.push({ number: num, title: epTitle || `Episode ${num}`, url: toAbs(href), date: date || '', }) } }) // Fallback ke pola regex jika eplister kosong if (episodes.length === 0) { $('a[href*="-episode-"]').each((i, el) => { const href = $(el).attr('href') || '' const m = href.match(/-episode-(\d+)(?:-subtitle-indonesia)?/i) if (!m) return const num = parseInt(m[1], 10) if (seen.has(href)) return seen.add(href) episodes.push({ number: num, title: `Episode ${num}`, url: toAbs(href), date: '', }) }) } episodes.sort((a, b) => a.number - b.number) const synopsis = $('.entry-content[itemprop="description"], .sinopc').first().text().trim() || '' return { source: 'otakudesu', title, image: img, status, studio, genres, synopsis, episodes } } /** * Ambil episode: iframe video embed dan link download */ export async function getEpisode(url) { const html = await get(url) const $ = cheerio.load(html) const title = $('h1').first().text().trim() || $('title').text().replace(/ - Otaku Desu.*$/i, '').trim() let iframe = '' $('iframe').each((i, el) => { const src = $(el).attr('src') || $(el).attr('data-src') || '' if (src) { iframe = src; return false } }) const downloadLinks = [] const seenDl = new Set() $('.dlbox a, .downloadbox a').each((i, el) => { const href = $(el).attr('href') || '' if (!href || href === '#' || seenDl.has(href)) return seenDl.add(href) downloadLinks.push({ label: $(el).text().trim().replace(/\s+/g, ' ').slice(0, 60) || 'link', url: href }) }) return { source: 'otakudesu', title, iframe, downloadLinks } } export default { searchAnime, getAnimeDetail, getEpisode } // ───────────────────────────────────────────────────────────────────── // Direct Execution / CLI Runner // ───────────────────────────────────────────────────────────────────── if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { const args = process.argv.slice(2) ;(async () => { try { if (args.length === 0) { console.log('[+] Menjalankan default search: "one piece"...\n') const results = await searchAnime('one piece') console.log(JSON.stringify(results, null, 2)) return } const cmd = args[0].toLowerCase() if (cmd === 'search' || cmd === 'cari') { const query = args.slice(1).join(' ') || 'one piece' console.log(`[+] Mencari: "${query}"...`) const results = await searchAnime(query) console.log(JSON.stringify(results, null, 2)) } else if (cmd === 'detail') { const url = args[1] if (!url) { console.error('Format: node otakudesu.js detail ') process.exit(1) } console.log(`[+] Detail: ${url}`) const detail = await getAnimeDetail(url) console.log(JSON.stringify(detail, null, 2)) } else if (cmd === 'episode' || cmd === 'ep') { const url = args[1] if (!url) { console.error('Format: node otakudesu.js episode ') process.exit(1) } console.log(`[+] Episode: ${url}`) const ep = await getEpisode(url) console.log(JSON.stringify(ep, null, 2)) } else if (args[0].startsWith('http://') || args[0].startsWith('https://')) { const url = args[0] if (url.includes('/series/')) { console.log(`[+] Terdeteksi Series: ${url}`) const detail = await getAnimeDetail(url) console.log(JSON.stringify(detail, null, 2)) } else if (url.includes('-episode-')) { console.log(`[+] Terdeteksi Episode: ${url}`) const ep = await getEpisode(url) console.log(JSON.stringify(ep, null, 2)) } else { const detail = await getAnimeDetail(url) console.log(JSON.stringify(detail, null, 2)) } } else { const query = args.join(' ') console.log(`[+] Mencari: "${query}"...`) const results = await searchAnime(query) console.log(JSON.stringify(results, null, 2)) } } catch (err) { console.error('Error:', err.message || err) process.exitCode = 1 } })() }