Help with HttpService

Ok this time I am gonna explain better.

I want a lyrics system. I found the website called Genius API. I don’t know how to make it get the song by the id. I have the song id. I need help or else ill commit oof.

https://api.genius.com/songs/{songId}&access_token={apiKey}
This is the api url I suppose.

local http = game:GetService("HttpService")
local apiKey = "your secret key lol"
local songId = "000000"

local url = ("https://api.genius.com/songs/%s&access_token=%s"):format(songId,apiKey)

local suc,res = pcall(function()
    return http:GetAsync(url)
end)

if suc and res then
   print(res)
end

Oooo does that give lyrics as well? Cuz idk genius man its kinda hard. Also i am no genius

Let me try it myself, I never tried genius before.

Yea… same lol.

local url = "https://api.genius.com/search?access_token="..access_token.."&q="

this is my first url to find the id i guess u can use that to figure out?

I’ve already got the lyrics, but the problem is its retured in HTML dom.
So I am creating an API on my server where you can convert that html dom to get the lyrics.

wai HOW DID U GOT THE LYRICS? man how dumb am I now? feels like -69420 iq

You only have to get the song URL then send the get request.

local http = game:GetService("HttpService")
local url = "https://genius.com"

local songPath = "/Little-mix-move-lyrics" -- (I've picked a random song)
local newUrl = url..songPath

local response = http:GetAsync(newUrl)
print(response) -- Html dom as string
1 Like

oh i also found that and i was thinking how the hell can i convert that lol
welp guess one way is if we separate the lyrics from the rest of the code by the umm get async and yea…

You aren’t calling the API service of the URL, which is why it is the HTML code

tough luck
image
image

I think you need to follow the websites API documentation…

did and didnt understand any thing at all!

According to the Node js packages / Python packages
They are getting lyrics from Html code.

Sup, I got it working.

Code:

local http = game:GetService("HttpService")
local apiKey = "key"
local songId = "237122"

local url = ("https://synitx.glitch.me/api/genius/%s/%s"):format(songId,apiKey)

local suc,res = pcall(function()
	return http:GetAsync(url)
end)

if suc and res then
	res = http:JSONDecode(res)
	print(res.data)
end
1 Like

:o waow also uhm i think u should remove the apiKey :slight_smile:

Its alr I dont need it anymore lol.
But if you say so I’ll remove it.

1 Like

well then cant wait to try it out opening studio…

If you want to make your own api then heres the code
Backend Code:
I’ve used express

// Main File

app.get(`/api/genius/:id/:api`,async (req,res) => {
    const api = require("./getSongInfo");
    var song = await api(req.params.id,req.params.api)
    res.json({data: song})
 });

getSongInfo.js
// getSongInfo

const fetch = require('node-fetch');
const extractLyrics = require('./utils/extractLyrics');

const url = 'https://api.genius.com/songs/';

module.exports = async function (id, apiKey) {
	if (!id) throw 'No id was provided';
	try {
		let a = await fetch(`${url}${id}?access_token=${apiKey}`);
    a = await a.json()
    var song = a.response.song
		let lyrics = await extractLyrics(song.url);
		return lyrics;
	} catch (e) {
		throw e;
	}
};
utils/extractLyrics.js
const axios = require('axios');
const cheerio = require('cheerio-without-node-native');

module.exports = async function (url) {
	try {
		let { data } = await axios.get(url);
		const $ = cheerio.load(data);
		let lyrics = $('div[class="lyrics"]').text().trim();
		if (!lyrics) {
			lyrics = '';
			$('div[class^="Lyrics__Container"]').each((i, elem) => {
				if ($(elem).text().length !== 0) {
					let snippet = $(elem)
						.html()
						.replace(/<br>/g, '\n')
						.replace(/<(?!\s*br\s*\/?)[^>]+>/gi, '');
					lyrics += $('<textarea/>').html(snippet).text().trim() + '\n\n';
				}
			});
		}
		if (!lyrics) return null;
		return lyrics.trim();
	} catch (e) {
		throw e;
	}
};

Broken npm package link (github)

1 Like