Back to Home
Gistify Snippet
Public
Otakudesu Anime Scraper & Detail Fetcher
Scrapes Otakudesu.fit for anime search results and detailed information including title, image, status, studio, genres, and episode lists using Cheerio.
#scraper#anime#otakudesu#cheerio#nodejs#javascript
6
Rawotakudesu.jsjavascript
240 lines| 1 | import * as cheerio from 'cheerio' |
| 2 | import { pathToFileURL } from 'node:url' |
| 3 | import dns from 'node:dns' |
| 4 | |
| 5 | dns.setDefaultResultOrder('ipv4first') |
| 6 | |
| 7 | /** |
| 8 | * Otakudesu Scraper (otakudesu.fit) |
| 9 | * Sumber: kyiov/mithra-ex (system/lib/scraper/otakudesu.js) |
| 10 | */ |
| 11 | |
| 12 | const BASE = 'https://otakudesu.fit' |
| 13 | 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' |
| 14 | |
| 15 | async function get(url) { |
| 16 | const r = await fetch(url, { |
| 17 | headers: { |
| 18 | 'User-Agent': UA, |
| 19 | Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 20 | 'Accept-Language': 'id-ID,id;q=0.9,en;q=0.8', |
| 21 | Referer: BASE + '/', |
| 22 | Cookie: 'sg=1', // Bypass searchguard check |
| 23 | }, |
| 24 | redirect: 'follow', |
| 25 | signal: AbortSignal.timeout(25000), |
| 26 | }) |
| 27 | const body = await r.text() |
| 28 | if (r.status !== 200) throw new Error(`HTTP ${r.status} untuk ${url}`) |
| 29 | return body |
| 30 | } |
| 31 | |
| 32 | function toAbs(u) { |
| 33 | if (!u) return '' |
| 34 | if (u.startsWith('http')) return u |
| 35 | return BASE + (u.startsWith('/') ? u : '/' + u) |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Cari anime via ?s=<query>&post_type=anime |
| 40 | */ |
| 41 | export async function searchAnime(query) { |
| 42 | const q = String(query || '').trim() |
| 43 | if (!q) return [] |
| 44 | try { |
| 45 | const html = await get(`${BASE}/?s=${encodeURIComponent(q)}&post_type=anime`) |
| 46 | const $ = cheerio.load(html) |
| 47 | const results = [] |
| 48 | $('article.bs').each((i, el) => { |
| 49 | const a = $(el).find('a.tip[href*="/series/"]').first() |
| 50 | const href = a.attr('href') || '' |
| 51 | const title = (a.attr('title') || a.text().trim() || '').replace(/\s+/g, ' ') |
| 52 | const img = $(el).find('img').first().attr('src') || '' |
| 53 | if (!href || !title) return |
| 54 | results.push({ |
| 55 | source: 'otakudesu', |
| 56 | title, |
| 57 | url: toAbs(href), |
| 58 | image: img, |
| 59 | type: $(el).find('.typez').first().text().trim() || 'Anime', |
| 60 | rating: $(el).find('.rating').first().text().trim() || '', |
| 61 | status: $(el).find('.epx, .status').first().text().trim() || '', |
| 62 | }) |
| 63 | }) |
| 64 | return results |
| 65 | } catch (e) { |
| 66 | console.error('[otakudesu] search error:', e.message) |
| 67 | return [] |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Ambil detail anime: info, genre, sinopsis, dan daftar episode |
| 73 | */ |
| 74 | export async function getAnimeDetail(url) { |
| 75 | const html = await get(url) |
| 76 | const $ = cheerio.load(html) |
| 77 | |
| 78 | const title = $('h1').first().text().trim() || $('title').text().replace(/ - Otaku Desu.*$/i, '').trim() |
| 79 | const img = $('.single-info .thumb img, .info-left img, .bixbox .thumb img').first().attr('src') || '' |
| 80 | |
| 81 | let status = '' |
| 82 | let studio = '' |
| 83 | const spe = $('.spe').first().text().replace(/\s+/g, ' ') |
| 84 | const stM = spe.match(/Status:\s*([^,]+?)(?:\s+(?:Studio|Released|Season|Type|Duration|Score|Producer|Total|Rating):|$)/i) |
| 85 | if (stM) status = stM[1].trim() |
| 86 | const stuM = spe.match(/Studio:\s*([^,]+?)(?:\s+(?:Released|Season|Type|Duration|Score|Producer|Total|Rating):|$)/i) |
| 87 | if (stuM) studio = stuM[1].trim() |
| 88 | |
| 89 | const genres = [] |
| 90 | $('a[href*="/genres/"]').each((i, el) => { |
| 91 | const t = $(el).text().trim() |
| 92 | if (t && !genres.includes(t)) genres.push(t) |
| 93 | }) |
| 94 | |
| 95 | const episodes = [] |
| 96 | const seen = new Set() |
| 97 | |
| 98 | // Parsing dari daftar .eplister jika tersedia |
| 99 | $('.eplister ul li').each((i, el) => { |
| 100 | const a = $(el).find('a').first() |
| 101 | const href = a.attr('href') || '' |
| 102 | const epNumStr = $(el).find('.epl-num').first().text().trim() |
| 103 | const epTitle = $(el).find('.epl-title').first().text().trim() || a.text().trim() |
| 104 | const date = $(el).find('.epl-date').first().text().trim() |
| 105 | const num = parseInt(epNumStr, 10) || i + 1 |
| 106 | |
| 107 | if (href && !seen.has(href)) { |
| 108 | seen.add(href) |
| 109 | episodes.push({ |
| 110 | number: num, |
| 111 | title: epTitle || `Episode ${num}`, |
| 112 | url: toAbs(href), |
| 113 | date: date || '', |
| 114 | }) |
| 115 | } |
| 116 | }) |
| 117 | |
| 118 | // Fallback ke pola regex jika eplister kosong |
| 119 | if (episodes.length === 0) { |
| 120 | $('a[href*="-episode-"]').each((i, el) => { |
| 121 | const href = $(el).attr('href') || '' |
| 122 | const m = href.match(/-episode-(\d+)(?:-subtitle-indonesia)?/i) |
| 123 | if (!m) return |
| 124 | const num = parseInt(m[1], 10) |
| 125 | if (seen.has(href)) return |
| 126 | seen.add(href) |
| 127 | episodes.push({ |
| 128 | number: num, |
| 129 | title: `Episode ${num}`, |
| 130 | url: toAbs(href), |
| 131 | date: '', |
| 132 | }) |
| 133 | }) |
| 134 | } |
| 135 | |
| 136 | episodes.sort((a, b) => a.number - b.number) |
| 137 | const synopsis = $('.entry-content[itemprop="description"], .sinopc').first().text().trim() || '' |
| 138 | |
| 139 | return { source: 'otakudesu', title, image: img, status, studio, genres, synopsis, episodes } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Ambil episode: iframe video embed dan link download |
| 144 | */ |
| 145 | export async function getEpisode(url) { |
| 146 | const html = await get(url) |
| 147 | const $ = cheerio.load(html) |
| 148 | |
| 149 | const title = $('h1').first().text().trim() || $('title').text().replace(/ - Otaku Desu.*$/i, '').trim() |
| 150 | |
| 151 | let iframe = '' |
| 152 | $('iframe').each((i, el) => { |
| 153 | const src = $(el).attr('src') || $(el).attr('data-src') || '' |
| 154 | if (src) { iframe = src; return false } |
| 155 | }) |
| 156 | |
| 157 | const downloadLinks = [] |
| 158 | const seenDl = new Set() |
| 159 | $('.dlbox a, .downloadbox a').each((i, el) => { |
| 160 | const href = $(el).attr('href') || '' |
| 161 | if (!href || href === '#' || seenDl.has(href)) return |
| 162 | seenDl.add(href) |
| 163 | downloadLinks.push({ |
| 164 | label: $(el).text().trim().replace(/\s+/g, ' ').slice(0, 60) || 'link', |
| 165 | url: href |
| 166 | }) |
| 167 | }) |
| 168 | |
| 169 | return { source: 'otakudesu', title, iframe, downloadLinks } |
| 170 | } |
| 171 | |
| 172 | export default { searchAnime, getAnimeDetail, getEpisode } |
| 173 | |
| 174 | // ───────────────────────────────────────────────────────────────────── |
| 175 | // Direct Execution / CLI Runner |
| 176 | // ───────────────────────────────────────────────────────────────────── |
| 177 | if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 178 | const args = process.argv.slice(2) |
| 179 | |
| 180 | ;(async () => { |
| 181 | try { |
| 182 | if (args.length === 0) { |
| 183 | console.log('[+] Menjalankan default search: "one piece"...\n') |
| 184 | const results = await searchAnime('one piece') |
| 185 | console.log(JSON.stringify(results, null, 2)) |
| 186 | return |
| 187 | } |
| 188 | |
| 189 | const cmd = args[0].toLowerCase() |
| 190 | |
| 191 | if (cmd === 'search' || cmd === 'cari') { |
| 192 | const query = args.slice(1).join(' ') || 'one piece' |
| 193 | console.log(`[+] Mencari: "${query}"...`) |
| 194 | const results = await searchAnime(query) |
| 195 | console.log(JSON.stringify(results, null, 2)) |
| 196 | } else if (cmd === 'detail') { |
| 197 | const url = args[1] |
| 198 | if (!url) { |
| 199 | console.error('Format: node otakudesu.js detail <url>') |
| 200 | process.exit(1) |
| 201 | } |
| 202 | console.log(`[+] Detail: ${url}`) |
| 203 | const detail = await getAnimeDetail(url) |
| 204 | console.log(JSON.stringify(detail, null, 2)) |
| 205 | } else if (cmd === 'episode' || cmd === 'ep') { |
| 206 | const url = args[1] |
| 207 | if (!url) { |
| 208 | console.error('Format: node otakudesu.js episode <url>') |
| 209 | process.exit(1) |
| 210 | } |
| 211 | console.log(`[+] Episode: ${url}`) |
| 212 | const ep = await getEpisode(url) |
| 213 | console.log(JSON.stringify(ep, null, 2)) |
| 214 | } else if (args[0].startsWith('http://') || args[0].startsWith('https://')) { |
| 215 | const url = args[0] |
| 216 | if (url.includes('/series/')) { |
| 217 | console.log(`[+] Terdeteksi Series: ${url}`) |
| 218 | const detail = await getAnimeDetail(url) |
| 219 | console.log(JSON.stringify(detail, null, 2)) |
| 220 | } else if (url.includes('-episode-')) { |
| 221 | console.log(`[+] Terdeteksi Episode: ${url}`) |
| 222 | const ep = await getEpisode(url) |
| 223 | console.log(JSON.stringify(ep, null, 2)) |
| 224 | } else { |
| 225 | const detail = await getAnimeDetail(url) |
| 226 | console.log(JSON.stringify(detail, null, 2)) |
| 227 | } |
| 228 | } else { |
| 229 | const query = args.join(' ') |
| 230 | console.log(`[+] Mencari: "${query}"...`) |
| 231 | const results = await searchAnime(query) |
| 232 | console.log(JSON.stringify(results, null, 2)) |
| 233 | } |
| 234 | } catch (err) { |
| 235 | console.error('Error:', err.message || err) |
| 236 | process.exitCode = 1 |
| 237 | } |
| 238 | })() |
| 239 | } |
| 240 | |
Discussion & Comments0
No comments yet — be the first to leave feedback or start a code discussion.
Sign in with your GitHub account to write comments and join the discussion.