UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

82 lines (69 loc) 2.48 kB
/* * SCRAPER BY HERZA * ################# * DONT DELETE MY WM * ##################### * JOIN MY WA CHANNEL * https://whatsapp.com/channel/0029VaGVOvq1iUxY6WgHLv2R * #################### * FOLLOW MY GITHUB * https://github.com/herzonly * ##################### * DONT DELETE MY WM PLEASE * ####################### */ const axios = require('axios'); const cheerio = require('cheerio'); const SPOTIFY_CLIENT_ID = '0821bccce6cb4904b32f51a0317d802e'; const SPOTIFY_CLIENT_SECRET = '8170bb5f16354e2eb35dad7fc73717b0'; async function getSpotifyToken() { const { data } = await axios.post('https://accounts.spotify.com/api/token', new URLSearchParams({ grant_type: 'client_credentials' }), { headers: { Authorization: `Basic ${Buffer.from(`${SPOTIFY_CLIENT_ID}:${SPOTIFY_CLIENT_SECRET}`).toString('base64')}` } } ); return data.access_token; } async function searchSpotify(song) { const token = await getSpotifyToken(); const { data } = await axios.get(`https://api.spotify.com/v1/search`, { headers: { Authorization: `Bearer ${token}` }, params: { q: song, type: 'track', limit: 1 } }); if (!data.tracks.items.length) return null; const track = data.tracks.items[0]; return { album: track.album.name, release_date: track.album.release_date, rating: track.popularity, }; } async function lyrics(song) { const baseUrl = 'https://www.lyrics.com/'; const searchUrl = `${baseUrl}lyrics/${encodeURIComponent(song)}`; const { data } = await axios.get(searchUrl); const $ = cheerio.load(data); const firstResult = $('.lyric-meta.within-lyrics.fll').first(); const title = firstResult.find('.lyric-meta-title a').text().trim(); const artist = firstResult.find('.lyric-meta-album-artist a').text().trim(); const lyricsPath = firstResult.find('.lyric-meta-title a').attr('href'); if (!title || !artist || !lyricsPath) return null; const lyricsUrl = `${baseUrl}${lyricsPath}`; const lyricsPage = await axios.get(lyricsUrl); const $$ = cheerio.load(lyricsPage.data); const lyrics = $$('#lyric-body-text').text().trim(); const spotifyData = await searchSpotify(song); return { author: "Herza", status: 200, results: { title, artist, rating: spotifyData ? spotifyData.rating : "N/A", release_date: spotifyData ? spotifyData.release_date : "N/A", album: spotifyData ? spotifyData.album : "N/A", url: lyricsUrl, lyrics, } }; } module.exports = { lyrics }