-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
55 lines (50 loc) · 1.8 KB
/
app.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
const cheerio = require('cheerio')
const http = require('http');
const axios = require('axios');
const port = process.env.PORT || 8080;
const express = require('express');
const formater = require('./src/regex_replacer')
const app = express();
const server = http.createServer(app);
app.get('/detect',(req,res) => {
const query = req.query.query;
console.log(query);
url = `https://www.google.com/search?q=lirik+lagu+${query}`;
let js = [];
axios.get(url)
.then((response) => {
let $ = cheerio.load(response.data);
try {
const title = $('span.BNeawe.tAd8D.AP7Wnd').text()
var band = $('span.BNeawe.s3v9rd.AP7Wnd')[1].children[0].data
var Penulis = new RegExp('Penulis lagu:(.*)')
const songwriter = $('div.xpc').text();
js.push({
band:band,
title:title,
song:songwriter.match(Penulis)[1]
})
const lyric = $('div.xpc').text();
(async () => {
js.push({
lyric:await formater.regex(lyric)
})
await res.json({
Status:{Response:200,Api_Version:'1.0.0'},
img:js[0].img,
Band_Name: js[0].band,
Song_Title: js[0].title,
Song_Writer:js[0].song,
lyric: js[1].lyric
})
})()
} catch (error) {
res.json({
error:'Um Sorry :( Lyric Not Found'
})
}
});
})
server.listen(port, function() {
console.log('App running on *: ' + port);
});