mirror of
https://codeberg.org/ashley/poke.git
synced 2024-12-01 09:47:22 +01:00
Update 'src/lyrics.js'
This commit is contained in:
parent
ac48876c03
commit
88f955f2da
1 changed files with 13 additions and 45 deletions
|
@ -1,46 +1,14 @@
|
||||||
const fetch = require('node-fetch');
|
const fetch = require("node-fetch");
|
||||||
const htmlToText = require('html-to-text');
|
|
||||||
const encoding = require('encoding');
|
|
||||||
const delim1 = '</div></div></div></div><div class="hwc"><div class="BNeawe tAd8D AP7Wnd"><div><div class="BNeawe tAd8D AP7Wnd">';
|
|
||||||
const delim2 = '</div></div></div></div></div><div><span class="hwc"><div class="BNeawe uEec3 AP7Wnd">';
|
|
||||||
const url = "https://www.google.com/search?q=";
|
|
||||||
|
|
||||||
async function main(e="", d="") {
|
async function main(e = "", d = "") {
|
||||||
let i;
|
const lyrics = await fetch(
|
||||||
try {
|
`https://p.poketube.fun/api/lyrics?query=${e}`
|
||||||
i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+lyrics`);
|
).then((res) => res.json());
|
||||||
i = await i.textConverted();
|
|
||||||
[, i] = i.split(delim1);
|
if (lyrics == undefined) lyrics = "Lyrics not found";
|
||||||
[i] = i.split(delim2);
|
if (lyrics != undefined) {
|
||||||
} catch (m) {
|
return lyrics;
|
||||||
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 = '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
module.exports = main;
|
||||||
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;
|
|
||||||
|
|
Loading…
Reference in a new issue