-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusic.html
121 lines (112 loc) · 4.44 KB
/
music.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Analysis Tool</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
}
h1 {
text-align: center;
}
.form-group {
margin-bottom: 15px;
}
label {
font-weight: bold;
}
input[type="text"], select {
width: 100%;
padding: 8px;
margin-top: 5px;
margin-bottom: 10px;
}
button {
padding: 10px 15px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 20px;
}
.result-item {
border-bottom: 1px solid #ddd;
padding: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>Music Analysis Tool</h1>
<form id="music-form">
<div class="form-group">
<label for="music-input">Enter Music Object (Song, Artist, or Album):</label>
<input type="text" id="music-input" name="music-input" required>
</div>
<div class="form-group">
<label for="music-type">Select Type:</label>
<select id="music-type" name="music-type" required>
<option value="track">Track</option>
<option value="artist">Artist</option>
<option value="album">Album</option>
</select>
</div>
<button type="submit">Search</button>
</form>
<div class="results" id="results"></div>
</div>
<script>
document.getElementById('music-form').addEventListener('submit', function(event) {
event.preventDefault();
const musicInput = document.getElementById('music-input').value;
const musicType = document.getElementById('music-type').value;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = 'Searching...';
fetch(`/search?q=${encodeURIComponent(musicInput)}&type=${musicType}`)
.then(response => response.json())
.then(data => {
resultsDiv.innerHTML = ''; // Clear previous results
if (data.error) {
resultsDiv.innerHTML = `<p style="color: red;">Error: ${data.error}</p>`;
} else if (data.length === 0) {
resultsDiv.innerHTML = '<p>No results found.</p>';
} else {
data.forEach(item => {
const div = document.createElement('div');
div.classList.add('result-item');
if (musicType === 'track') {
div.innerHTML = `<strong>Track:</strong> ${item.track_name}<br>
<strong>Artist:</strong> ${item.artist_name}<br>
<strong>Album:</strong> ${item.album_name}`;
} else if (musicType === 'artist') {
div.innerHTML = `<strong>Artist:</strong> ${item.artist_name}<br>
<strong>Popularity:</strong> ${item.popularity}<br>
<strong>Genres:</strong> ${item.genres.join(', ')}`;
} else if (musicType === 'album') {
div.innerHTML = `<strong>Album:</strong> ${item.album_name}<br>
<strong>Artist:</strong> ${item.artist_name}<br>
<strong>Release Date:</strong> ${item.release_date}`;
}
resultsDiv.appendChild(div);
});
}
})
.catch(error => {
resultsDiv.innerHTML = `<p style="color: red;">An error occurred: ${error}</p>`;
});
});
</script>
</body>
</html>