diff --git a/genius.js b/genius.js index 1e10989..98b7dfe 100644 --- a/genius.js +++ b/genius.js @@ -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; diff --git a/index.js b/index.js index db1a757..fa3816f 100644 --- a/index.js +++ b/index.js @@ -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(")");