Skip to content

Instantly share code, notes, and snippets.

@dayudodo
Last active April 13, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayudodo/4fa147739ebd85cc02a4da04866ebeb5 to your computer and use it in GitHub Desktop.
Save dayudodo/4fa147739ebd85cc02a4da04866ebeb5 to your computer and use it in GitHub Desktop.
LRC解析器
//node程序
//传递读取到的lrc文件内容content
function lrcParser(content){
//将数据分解为数组
var data = content.replace(/\r/g,'')
var _arrayOfLrc=data.split("\n");
var _LRC={
lyrics:[]
};
_arrayOfLrc.forEach(function(item){
//有的第一行可能含有非法字符,所以不能以^开头!
var timeData=/(\[\d+:\d+\.\d+\]|\[\d+:\d+\])(.+)/;
if(timeData.test(item)){
var data=timeData.exec(item);
_LRC.lyrics.push({'time':data[1],'lyrics':data[2]});
data=null; //清除
}
})
return _LRC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment