1、word完整版)酷狗KRC歌词文件解析和与LRC的转换using System;using System.Collections。 Generic;using System.IO;using System.Linq;using System。 Text;using Sy对行的时间标签,如2781,3355 let timeKrc=Convert。 ToInt32(timeKrcLabel.Split(splitChars,StringSplitOptions。 RemoveEmptyEntries)0)*10000/获取每行的开始时刻,以100纳秒为单位 。
2、stem.Text。 RegularExpressions;using zlib;/using前要先引用namespace KrcLib public class KrcReader:IDisposable private Stream _sourceStream=neIsMatch(row)=true let newRow2=timeLableReg2.Replace(row,)/去除对每个字的时间标签,如0,751,0 let timeKrcLabel=timeLableReg1.Match(newRow2).Value/获取。
3、w MemoryStream();public Stream SourceStream get return _sourceStream;private set _sourceStream=value;/summary /用包含krc数据的流创建 /summary /lList=from row in krcList where idLabelReg.IsMatch(row)=true select row;IEnumerablestring lrcTextList=from row in krcList where rowReg。
4、param name=sourceStream包含krc数据的流/param public KrcReader(Stream sourceStream)sourceStream。 CopyTo(this。 SourceStream);this.SourceStream.P/用于取得每行的开始时刻 Regex idLabelReg=new Regex(artaal|byoffsetencoding|la|fm|wlwm|co|ad):。 *$”,RegexOptions.IgnoreCase);IEnumerable lrcIdLabe。
5、osition=0;/将包含krc数据的流解析为包含明码的流 /returns明码流/returns public Stream GetKrcStream()/krc数据需要先解密再解压缩 /在这之前先去掉头部4字节的krc歌词版本号:krc1 其HEX为:6b 72一行krc格式的歌词 Regex timeLableReg1=new Regex(d+,d+);/匹配krc格式行的时间 Regex timeLableReg2=new Regex(d+,d+,d+”);/匹配krc格式字的时间 char splitChars=,,,。
6、 63 31 /解密:遍历字节时循环地使每个字节与数组h中对应元素异或运算 /解压缩:zlib使用LZ77的变种算法,DEFLATE的算法 char h=,G,a,w,2,t,G,Q,6,1,,,n,i;MemoryStream outStream=new Memor /summary /returnslrc格式列表 public IEnumerable ToLrcList()List lrcList=new Liststring();Regex rowReg=new Regex(”d+,d+(d+,d+,d+。 +)*”);/匹配。
7、yStream();ZOutputStream outZStream=new ZOutputStream(outStream);SourceStream。 Position=4;/去掉头部4字节 int len=0;byte databuffer=new byte102eader(GetKrcStream(),Encoding.UTF8)while(!sr.EndOfStream)rowList。 Add(sr.ReadLine());return rowList;/summary /将包含krc数据的流转换为按行存储的lrc格式列表。
8、4;while(len=SourceStream。 Read(databuffer,0,1024)0)int m;for(int k=0;k len;k+)m=k 16;databufferk=(byte)(databufferk hm);/异或解密 outZStrea数据的流解析为按行存储的列表 /summary /解析后的行列表/returns public List GetKrcList()Liststring rowList=new Liststring();using(StreamReader sr=new StreamR。
9、m.Write(databuffer,0,len);/zlib解压缩 outZStream.finish();MemoryStream tmp=new MemoryStream();outStream.Position=0;outStream.CopyTo(tmp);uffer=new bytedecodedStream。 Length;int i=decodedStream.Read(buffer,0,buffer.Length);return Encoding.UTFGetString(buffer,0,i);/将包含krc。
10、/复制新的流以便outZStream。 Close()时不会关闭要返回的流 tmp.Position=0;/tmp被CopyTo时到了尾部,返回前需要重置位置 outStream=tmp;/指向刚复制的流用于返回 outZStream.Close();return outStream;/将包含krc数据的流解析为字符串 /summary /returns解析后的字符串/returns public string GetKrcString()using(Stream decodedStream=GetKrcStream()byte b。