Last active
April 13, 2017 09:09
-
-
Save dayudodo/4fa147739ebd85cc02a4da04866ebeb5 to your computer and use it in GitHub Desktop.
LRC解析器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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