-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsongs.html
54 lines (53 loc) · 1.31 KB
/
songs.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
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.2.min.js"></script>
</head>
<script>
$(document).ready(function(){
moodmap = [];
counter = 0;
writeToDb = {};
fetchMoodsAndSongs();
});
</script>
<script>
function fetchMoodsAndSongs(){
$.get("http://developer.echonest.com/api/v4/artist/list_terms?api_key=SKU68DJYXIFKLX3RE&format=json&type=mood" , function( data ) {
for( j=0; j<data.response.terms.length; j++){
moodmap.push(data.response.terms[j].name)
}
fetchSongs();
});
}
</script>
<script>
function fetchSongs(){
if (counter == moodmap.length){
fillDb();
return
}
api = "http://developer.echonest.com/api/v4/song/search?api_key=SKU68DJYXIFKLX3RE&results=100&format=json&mood="+moodmap[counter];
$.get(api, function( data ) {
console.log("-----------------------------------------------"+moodmap[counter]+"---------------------------------------------------------------");
console.log(data);
writeToDb[moodmap[counter]] = data;
counter++;
fetchSongs();
});
}
</script>
<script>
function fillDb(){
var obj = {data:writeToDb}
$.post("download.php",obj,dataPosted,type="json");
}
</script>
<script>
function dataPosted(data){
alert("success ------- "+data.msg);
}
</script>
<body>
</body>
</html>