-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlirik.js
60 lines (44 loc) · 1.15 KB
/
lirik.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const axios = require('axios')
const cheerio = require('cheerio')
// Add a connect listener
const test = function(x){
this.value = x
}
async function lyrics(query){
const pageurl = `https:\/\/search.azlyrics.com/search.php?q=${query}`
return axios.get(pageurl)
.then( (response)=>{
const html = response.data
const page = cheerio.load(html)
let result = page('.visitedlyr a')[0].attribs['href']
return axios.get(result)
.then((response)=>{
const html = response.data
const page = cheerio.load(html)
let lyrics = page('.ringtone')[0].next
let text = ''
while(true){
if(lyrics.name == 'b' ){
// add title
text += lyrics.children[0].data
}
lyrics = lyrics.next
if (lyrics.type == 'tag' && lyrics.name=='div'){
break
}
}
lyrics = text + lyrics.childNodes
.filter((tag)=> tag.type=='text').map((tag)=>tag.data).join()
test.value=lyrics
return(lyrics)
})
.catch((error)=>{
console.log("Error consulting", error)
})
}).catch((error)=>{
console.log("Error consulting ", error)
})
}
module.exports = {
lyrics
}