-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlrc.js
55 lines (44 loc) · 1.2 KB
/
lrc.js
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
/**
* @author Okeowo Aderemi
* @description LRC Simple Parser
*/
(function(jquery){
//Parses the LRC Data
function lrcParser(data){
//LRC Parsing
//Split the Data into Arrays
var _arrayOfLrc=data.split("\n");
var _LRC={
meta:{},
text:[],
lyrics:[]
};
_arrayOfLrc.forEach(function(item,index,ar){
//Meta Data
var metaData=/\[(\D+):(\D+)\]/;
var textData=/^(\w+)/;
var timeData=/^(\[\d+:\d+\.\d+\]|\[\d+:\d+\])(.+)/;
//Meta Data
if(metaData.test(item)){
var d=metaData.exec(item);
//push tp meta
_LRC.meta[d[1]]=d[2];
}
else if(textData.test(item)){
_LRC.text.push(textData.exec(item)[1]);
}
else if(timeData.test(item)){
var data=timeData.exec(item);
_LRC.lyrics.push({'time':data[1],'lyrics':data[2]});
data=null; //clean
}
});
return _LRC;
}
//Invoke the Function here
jquery.ajax("Bon Jovi - Always.lrc").then(function(data){
console.group("LRC Ajax");
console.log(lrcParser(data));
console.groupEnd();
});
})(jQuery);