Added mobile user-agent (less blocking)

This commit is contained in:
2020-12-19 10:28:53 +01:00
parent 7d2015a249
commit e2201ded4a
2 changed files with 5 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ class Genius {
})
}
get_lyrics(song_id, callback) {
get_lyrics(song_id, use_mobile, callback) {
axios({
method: "get",
url: "https://api.genius.com/songs/" + song_id,
@@ -24,7 +24,8 @@ class Genius {
}).then(response => {
axios({
method: "get",
url: response.data.response.song.url
url: response.data.response.song.url,
headers: { "User-Agent": use_mobile ? "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" }
}).then(response => {
const texts = $("div.lyrics > p", response.data)["0"].children;
let lyrics;

View File

@@ -32,7 +32,7 @@ client.on('message', message => {
else if (command === "play") {
Genius.search_song(args.join(" "), song => {
Genius.get_lyrics(song.id, (err, lyrics) => {
Genius.get_lyrics(song.id, true, (err, lyrics) => {
if (err) {
console.log("Error while fetching lyrics: " + err.message);
message.channel.send("Error fetching lyrics, please retry in a few seconds");
@@ -47,7 +47,7 @@ client.on('message', message => {
}
}
const random = Math.floor(Math.random() * tab_lyrics.length) + 4;
const lyricToFind = tab_lyrics[random];
let lyricToFind = tab_lyrics[random];
while (lyricToFind.indexOf("(") != -1) {
const start = lyricToFind.indexOf("(");
const end = lyricToFind.indexOf(")");