Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
brysah committed Oct 31, 2023
1 parent 4ade58a commit aa65c4e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions js/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ export default function Song({
let correctAnswer = undefined;
let id = undefined;
const api = Api();
var apiKeyM = 'default';
var env = process.env.NODE_ENV || 'development';

if (env === 'development') {
apiKeyM = config.apiKeyMusicx;
}
if (env === 'production') {
apiKeyM = process.env.API_KEY_MUSICX;
}

async function searchLyric(nameSong, artistName) {
try {
const apiKey = process.env.API_KEY_MUSICX || config.apiKeyMusicx;
const apiUrl = `https://api.musixmatch.com/ws/1.1/track.search?q_artist=${artistName}&q_track=${nameSong}&f_has_lyrics=true&apikey=${apiKey}&format=jsonp`;
// const apiKey = process.env.API_KEY_MUSICX || config.apiKeyMusicx;
const apiUrl = `https://api.musixmatch.com/ws/1.1/track.search?q_artist=${artistName}&q_track=${nameSong}&f_has_lyrics=true&apikey=${apiKeyM}&format=jsonp`;

const script = document.createElement('script');
script.src = `${apiUrl}&callback=handleResponse`;
Expand All @@ -24,14 +33,14 @@ export default function Song({
try {
let id;
let cont = 0;
const apiKey = process.env.API_KEY_MUSICX || config.apiKeyMusicx;
//const apiKey = process.env.API_KEY_MUSICX || config.apiKeyMusicx;
while (!id) {
if (data.message.body.track_list[cont].track.has_lyrics == true) {
id = data.message.body.track_list[cont].track.track_id;
}
cont++;
}
const newApi = `https://api.musixmatch.com/ws/1.1/track.snippet.get?track_id=${id}&apikey=${apiKey}&format=jsonp`;
const newApi = `https://api.musixmatch.com/ws/1.1/track.snippet.get?track_id=${id}&apikey=${apiKeyM}&format=jsonp`;

const script = document.createElement('script');
script.src = `${newApi}&callback=handleLyricResponse`;
Expand Down

0 comments on commit aa65c4e

Please sign in to comment.