home chevron_right src chevron_right Kusonime.js
code

Kusonime.js

JavaScript 4.89 KB 127 baris visibility 16 views
open_in_new
src/Kusonime.js
async function JHKusonime(action = 'search', queryOrUrl = '') {
  const axios = (await import('axios')).default;
  const cheerio = await import('cheerio');

/*
- HARGAI WOY JANGAN DIHAPUS!
- Skrep by *JH a.k.a DHIKA - FIONY BOT*
- Credits to all Fiony's Bot Admin. 
- Maaf kalo kurang maksimal atau berantakan
- Hasil gabut saja xixixi. 
*/

  const baseRes = { author_skrep: 'JH a.k.a Dhika', kesayangan: 'Fiony Alveria♡' };

  const jantung = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
    'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7'
  };

  const res = (status, payload) => {
    const out = { ...baseRes, status, action };
    if (status) out.data = payload; else out.error = payload;
    return JSON.stringify(out, null, 2);
  };

  try {
    if (action === 'search' || action === 'latest') {
      if (action === 'search' && !queryOrUrl) throw new Error('Query pencarian anime wajib diisi wak!');
      
      const targetUrl = action === 'search' 
        ? `https://kusonime.com/?s=${encodeURIComponent(queryOrUrl)}&post_type=post` 
        : 'https://kusonime.com/';
        
      const { data } = await axios.get(targetUrl, { headers: jantung });
      const $ = cheerio.load(data);
      const results = [];

      $('.venz ul .detpost').each((i, el) => {
        const title = $(el).find('h2.episodeye a').text().trim() || $(el).find('.content h2 a').text().trim();
        const url = $(el).find('h2.episodeye a').attr('href') || $(el).find('.content h2 a').attr('href') || $(el).find('a').first().attr('href');
        const thumb = $(el).find('.thumb img').attr('src');
        const date = $(el).find('.content p').first().text().trim();
        
        const genres = [];
        $(el).find('.content p a').each((j, a) => {
          genres.push($(a).text().trim());
        });

        if (title && url) {
          results.push({ title, thumb, date, genres: genres.join(', '), url });
        }
      });

      if (results.length === 0) throw new Error(action === 'search' ? 'Anime nggak ketemu wak!' : 'Gagal narik anime terbaru!');
      return res(true, results);
    }

    if (action === 'detail') {
      if (!queryOrUrl) throw new Error('URL atau Slug Kusonime wajib diisi wak!');
      
      let targetUrl = queryOrUrl.trim();
      if (!targetUrl.startsWith('http')) {
        if (targetUrl.includes('kusonime.com')) {
          targetUrl = `https://${targetUrl}`;
        } else {
          targetUrl = `https://kusonime.com/${targetUrl.replace(/^\/+|\/+$/g, '')}/`;
        }
      }
      
      const { data } = await axios.get(targetUrl, { headers: jantung });
      const $ = cheerio.load(data);

      const title = $('.post-thumb h1').text().trim() || $('.venser h1').text().trim();
      const thumb = $('.post-thumb img').attr('src') || '';
      
      let sinopsis = '';
      $('.lexot p').each((i, el) => {
        if (!$(el).find('b').length && !$(el).find('strong').length && $(el).text().trim().length > 15) {
          sinopsis += $(el).text().trim() + '\n\n';
        }
      });
      sinopsis = sinopsis.trim();

      const info = {};
      $('.info p').each((i, el) => {
        const bText = $(el).find('b').text().trim();
        const fullText = $(el).text().trim();
        if (bText && fullText.includes(':')) {
          const key = bText.toLowerCase().replace(/\s+/g, '_').replace(/[^a-z_]/g, '');
          const val = fullText.substring(fullText.indexOf(':') + 1).trim();
          info[key] = val;
        }
      });

      const downloads = [];
      $('.smokeddlrh').each((i, el) => {
        const resTitle = $(el).find('.smokettlrh').text().trim();
        const linkGroups = [];
        
        $(el).find('.smokeurlrh').each((j, row) => {
          const resolution = $(row).find('strong').text().trim();
          const links = [];
          $(row).find('a').each((k, a) => {
            links.push({ host: $(a).text().trim(), url: $(a).attr('href') });
          });
          if (resolution && links.length > 0) linkGroups.push({ resolution, links });
        });

        if (resTitle || linkGroups.length > 0) downloads.push({ title: resTitle, list: linkGroups });
      });

      return res(true, { title, thumb, ...info, sinopsis, downloads });
    }

    throw new Error('Action nggak dikenali! Pilih: latest, search, detail');
  } catch (e) {
    let err = e.response?.data || e.message;
    if (Buffer.isBuffer(err)) err = err.toString('utf-8');
    return res(false, err);
  }
}

// Test Mode
// return JHKusonime('search', 'QUERY_HERE'); // input judul biasa — JH a.k.a Dhika - Fiony Bot
// return JHKusonime('detail', 'URL/SLUG_HERE'); // input URL full maupun slug dari hasil search — JH a.k.a Dhika - Fiony Bot
// return JHKusonime('latest'); // buat cek rilisan terbaru — JH a.k.a Dhika - Fiony Bot
link

Direct URL

check Disalin!