LyricContent ILyricParser.ParseLyric(string file) { LyricContent content = new LyricContent(); file = (file ?? string.Empty).Trim(); if (string.IsNullOrEmpty(file)) return content; using (StreamReader reader = new StreamReader(file, true)) { string line; bool isEventPass = false; LocationInfo formatLocation = null; while ((line = reader.ReadLine()) != null) { line = line.Trim(); Match eventMatch = EventRegex.Match(line); if (isEventPass == false && eventMatch.Success) { isEventPass = true; continue; } if (isEventPass) { Match formatMatch = FormatRegex.Match(line); if (formatLocation == null && formatMatch.Success) { LocationInfo tmpInfo = new LocationInfo(); string[] infos = formatMatch.Groups[1].ToString().Split(','); for (int i = 0; i < infos.Length; i++) { string info = (infos[i] ?? string.Empty).Trim().ToLower(); switch (info) { case "start": tmpInfo.StartLocation = i; break; case "end": tmpInfo.EndLocation = i; break; case "text": tmpInfo.TextLocation = i; break; } } if (tmpInfo.IsAvailable) { formatLocation = tmpInfo; } continue; } if (formatLocation != null) { Match dialogueMatch = DialogueRegex.Match(line); if (dialogueMatch.Success) { string[] infos = dialogueMatch.Groups[1].ToString().Split(','); LyricClip clip = new LyricClip(); GroupCollection group = this.matchDateTime(infos[formatLocation.StartLocation]); if (group != null) clip.AddStartTime(group[1].ToString(), group[2].ToString(), group[3].ToString(), group[4].ToString()); group = this.matchDateTime(infos[formatLocation.EndLocation]); if (group != null) clip.AddEndTime(group[1].ToString(), group[2].ToString(), group[3].ToString(), group[4].ToString()); clip.ClipLyric = infos[formatLocation.TextLocation] ?? string.Empty; content.Add(clip); } } } } } return content; }
LyricContent ILyricParser.ParseLyric(string file) { LyricContent content = new LyricContent(); file = (file ?? string.Empty).Trim(); if (string.IsNullOrEmpty(file)) return content; using (StreamReader reader = new StreamReader(file, true)) { LyricClip clip = null; string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); Match orderMatch = OrderRegex.Match(line); if (orderMatch.Success) { string subLine = (reader.ReadLine() ?? string.Empty).Trim(); Match timeMatch = TimeRegex.Match(subLine); if (timeMatch.Success) { if (clip != null) { clip.ClipLyric = (clip.ClipLyric ?? string.Empty).Trim(); } clip = new LyricClip(); GroupCollection group = timeMatch.Groups; clip.AddStartTime(group[1].ToString(), group[2].ToString(), group[3].ToString(), group[4].ToString()); clip.AddEndTime(group[5].ToString(), group[6].ToString(), group[7].ToString(), group[8].ToString()); content.Add(clip); continue; } else { if (!string.IsNullOrEmpty(subLine)) line = string.Format("{0}\r\n{1}", line, subLine); } } if (clip != null) { if (!string.IsNullOrEmpty(line)) { string lyric = clip.ClipLyric ?? string.Empty; if (string.IsNullOrEmpty(lyric)) clip.ClipLyric = line; else clip.ClipLyric = string.Format("{0}\r\n{1}", lyric, line); } } } } return content; }