Added mobile user-agent (less blocking)
This commit is contained in:
@@ -16,7 +16,7 @@ class Genius {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get_lyrics(song_id, callback) {
|
get_lyrics(song_id, use_mobile, callback) {
|
||||||
axios({
|
axios({
|
||||||
method: "get",
|
method: "get",
|
||||||
url: "https://api.genius.com/songs/" + song_id,
|
url: "https://api.genius.com/songs/" + song_id,
|
||||||
@@ -24,7 +24,8 @@ class Genius {
|
|||||||
}).then(response => {
|
}).then(response => {
|
||||||
axios({
|
axios({
|
||||||
method: "get",
|
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 => {
|
}).then(response => {
|
||||||
const texts = $("div.lyrics > p", response.data)["0"].children;
|
const texts = $("div.lyrics > p", response.data)["0"].children;
|
||||||
let lyrics;
|
let lyrics;
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -32,7 +32,7 @@ client.on('message', message => {
|
|||||||
|
|
||||||
else if (command === "play") {
|
else if (command === "play") {
|
||||||
Genius.search_song(args.join(" "), song => {
|
Genius.search_song(args.join(" "), song => {
|
||||||
Genius.get_lyrics(song.id, (err, lyrics) => {
|
Genius.get_lyrics(song.id, true, (err, lyrics) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Error while fetching lyrics: " + err.message);
|
console.log("Error while fetching lyrics: " + err.message);
|
||||||
message.channel.send("Error fetching lyrics, please retry in a few seconds");
|
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 random = Math.floor(Math.random() * tab_lyrics.length) + 4;
|
||||||
const lyricToFind = tab_lyrics[random];
|
let lyricToFind = tab_lyrics[random];
|
||||||
while (lyricToFind.indexOf("(") != -1) {
|
while (lyricToFind.indexOf("(") != -1) {
|
||||||
const start = lyricToFind.indexOf("(");
|
const start = lyricToFind.indexOf("(");
|
||||||
const end = lyricToFind.indexOf(")");
|
const end = lyricToFind.indexOf(")");
|
||||||
|
|||||||
Reference in New Issue
Block a user