home chevron_right src chevron_right SongHub.js
code

SongHub.js

JavaScript 4.21 KB 114 baris visibility 21 views
open_in_new
src/SongHub.js
async function JHSongHub(mode, input) {
  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♡' };

  if (!mode || !input) return JSON.stringify({ ...baseRes, status: false, error: 'Mode dan Target wajib diisi bray!' }, null, 2);

  const jantung = {
    'Accept': '*/*',
    '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'
  };

  const get = url => axios.get(url, { headers: jantung }).then(r => r.data);

  try {
    if (mode === 'detail' || mode === 'download') {
      const targetUrl = input.startsWith('http') ? input : `https://songhub.lk/song/${input}`;
      const html = await get(targetUrl);
      const $ = cheerio.load(html);

      const mp3_url = $('#play').attr('url') || '';
      if (!mp3_url) throw new Error('Link MP3 gak ditemukan bray! (Cek lagi slug/URL kau)');

      const title = $('h1.title').text().trim() || $('meta[property="og:title"]').attr('content') || '';
      const thumb = $('meta[property="og:image"]').attr('content') || '';
      const lyrics_page = $('.lyrics-btn-wrp a').attr('href') || '';
      
      let lyrics_text = $('.lyrics-btn-wrp').next('.d-none').text().trim();
      if (!lyrics_text) {
        $('.d-none p').each((_, el) => {
          const txt = $(el).text().trim();
          if (txt.length > 30) lyrics_text = txt;
        });
      }
      lyrics_text = lyrics_text.replace(/\.\.\.\s*/g, '...\n\n').trim() || 'Lirik text gak ditemukan bray!';

      const getMeta = lbl => $(`th:contains("${lbl}")`).next('td').text().replace(/\s+/g, ' ').trim() || '-';

      let lyrics_img = '';
      if (lyrics_page) {
        const lyrHtml = await get(lyrics_page).catch(() => '');
        if (lyrHtml) lyrics_img = cheerio.load(lyrHtml)('meta[property="og:image"]').attr('content') || '';
      }

      return JSON.stringify({
        ...baseRes,
        status: true,
        type: 'detail',
        data: {
          title,
          artist: getMeta('Voice'),
          music: getMeta('Music'),
          lyricist: getMeta('Lyrics'),
          category: getMeta('Categories'),
          thumb,
          mp3_url,
          lyrics_text,
          lyrics_img,
          lyrics_page_url: lyrics_page
        }
      }, null, 2);
    }

    if (mode === 'search') {
      const cx = 'partner-pub-5272826017460586:9179973291';
      const js = await get(`https://cse.google.com/cse.js?cx=${cx}&language=en`);
      const token = js.match(/cse_token": "(.*?)"/)?.[1];
      if (!token) throw new Error('Gagal ngekstrak token CSE bray!');

      const params = new URLSearchParams({
        rsz: 'filtered_cse', num: '10', hl: 'en', source: 'gcsc',
        cselibv: js.match(/cselibVersion": "(.*?)"/)?.[1] || '',
        cx, q: input, safe: 'off', cse_tok: token, gl: 'lk',
        callback: `JHcb${Date.now()}`, rurl: 'https://songhub.lk/'
      });

      const cseRaw = await get(`https://cse.google.com/cse/element/v1?${params}`);
      const cseJson = JSON.parse(`{${cseRaw.match(/\(\{([\s\S]*?)\}\);?$/)?.[1]}}`);

      if (!cseJson.results?.length) throw new Error('Lagu gak ditemukan bray! Coba keyword lain.');

      return JSON.stringify({
        ...baseRes,
        status: true,
        type: 'search',
        query: input,
        data: cseJson.results.map(i => ({
          title: i.titleNoFormatting || i.title,
          url: i.url,
          snippet: i.contentNoFormatting || i.snippet,
          thumb: i.richSnippet?.cse_image?.[0]?.src || i.richSnippet?.metatags?.[0]?.['og:image'] || ''
        }))
      }, null, 2);
    }

    throw new Error('Mode tidak dikenali bray! Pilih Search atau Detail.');

  } catch (e) {
    return JSON.stringify({ ...baseRes, status: false, error: e.response?.data || e.message }, null, 2);
  }
}

// Test Mode
// return JHSongHub('search', 'TITLE_HERE'); // Input query biasa — JH a.k.a Dhika - Fiony Bot
// return JHSongHub('detail', 'URL/SLUG'); // Input URL/slug dari hasil 'search' — JH a.k.a Dhika - Fiony Bot
link

Direct URL

check Disalin!