From 88f955f2dae2112eef5ac8f4204d08a14ce45c92 Mon Sep 17 00:00:00 2001 From: Ashley Date: Mon, 15 Aug 2022 11:55:41 +0200 Subject: [PATCH] Update 'src/lyrics.js' --- src/lyrics.js | 58 ++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/src/lyrics.js b/src/lyrics.js index 86bd51d9..ed00222a 100644 --- a/src/lyrics.js +++ b/src/lyrics.js @@ -1,46 +1,14 @@ - const fetch = require('node-fetch'); - const htmlToText = require('html-to-text'); - const encoding = require('encoding'); - const delim1 = '
'; - const delim2 = '
'; - const url = "https://www.google.com/search?q="; +const fetch = require("node-fetch"); - async function main(e="", d="") { - let i; - try { - i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+lyrics`); - i = await i.textConverted(); - [, i] = i.split(delim1); - [i] = i.split(delim2); - } catch (m) { - try { - i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+song+lyrics`); - i = await i.textConverted(); - [, i] = i.split(delim1); - [i] = i.split(delim2); - } catch (n) { - try { - i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+song`); - i = await i.textConverted(); - [, i] = i.split(delim1); - [i] = i.split(delim2); - } catch (o) { - try { - i = await fetch(`${url}${encodeURIComponent(d + " " + e)}`); - i = await i.textConverted(); - [, i] = i.split(delim1); - [i] = i.split(delim2); - } catch (p) { - i = ''; - } - } - } - } - const ret = i.split('\n'); - let final = ''; - for (let j = 0; j < ret.length; j += 1) { - final = `${final}${htmlToText.fromString(ret[j])}\n`; - } - return String(encoding.convert(final)).trim(); - } - module.exports = main; +async function main(e = "", d = "") { + const lyrics = await fetch( + `https://p.poketube.fun/api/lyrics?query=${e}` + ).then((res) => res.json()); + + if (lyrics == undefined) lyrics = "Lyrics not found"; + if (lyrics != undefined) { + return lyrics; + } +} + +module.exports = main;