-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchLyrics.js
More file actions
23 lines (21 loc) · 899 Bytes
/
fetchLyrics.js
File metadata and controls
23 lines (21 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
async function fetchLyrics(artist, title) {
const lyricsDiv = document.getElementById('lyrics');
lyricsDiv.innerHTML = '<p class="loading">Loading lyrics...</p>';
try {
// Using lyrics.ovh API (free and no API key required)
const response = await fetch(`https://api.lyrics.ovh/v1/${encodeURIComponent(artist)}/${encodeURIComponent(title)}`);
const data = await response.json();
if (data.lyrics) {
lyricsDiv.innerHTML = `
<div class="lyrics-content">
<h2>${artist} - ${title}</h2>
<pre>${data.lyrics}</pre>
</div>`;
} else {
lyricsDiv.innerHTML = '<p class="error">Lyrics not found</p>';
}
} catch (error) {
lyricsDiv.innerHTML = '<p class="error">Error fetching lyrics</p>';
console.error('Lyrics error:', error);
}
}