-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
40 lines (33 loc) · 1.04 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const axios = require("axios");
const cheerio = require("cheerio");
const getList = async (name) => {
let URL = "https://www.musixmatch.com";
let links = [];
await axios.get(`${URL}/search/${name}`).then(async (res) => {
const $ = await cheerio.load(res.data);
$(".media-card-text").each(async (index, item) => {
const rawLink = $(item)
.children(".media-card-title")
.children("a")
.attr("href");
const link = `${URL}${rawLink}`;
const title = $(item).children("h2").text();
const subtitle = $(item).children("h3").text();
links[index] = { title, subtitle, link };
});
});
return links;
};
const getLyrics = async (link) => {
let lyrics = "";
await axios.get(link).then(async (res) => {
const $ = await cheerio.load(res.data);
$(".mxm-lyrics__content").each(async (index, item) => {
const lyricsItem = $(item).children("span").text();
lyrics += lyricsItem;
lyrics += "/n";
});
});
return lyrics;
};
module.exports = { getLyrics, getList };