/// <summary> /// 문자 형식으로 포맷된 가사를 현재 객체의 내용으로 불러옵니다. /// </summary> /// <param name="value">문자 형식으로 포맷된 가사 내용입니다.</param> public void Load(string value) { foreach (string str in value.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { // 헤더 분석 if (Title == null || Album == null || Artist == null) { var regexHeader = Regex.Matches(str, @"\[(TI|AL|AR):(.+?)\]", RegexOptions.IgnoreCase); foreach (Match matchHeader in regexHeader) { if (matchHeader.Success) { switch (matchHeader.Groups[1].Value.ToUpper()) { case "TI": Title = matchHeader.Groups[2].Value; break; case "AL": Album = matchHeader.Groups[2].Value; break; case "AR": Artist = matchHeader.Groups[2].Value; break; } } } } // 본문 분석 var regexSen = Regex.Match(str, @"\[([\d]{2,}:[\d]{2}.[\d]{2})\]"); var regexMap = Regex.Matches(str, @"\[([\d]{2,}:[\d]{2}.[\d]{2})~([0-9]{2,}:[\d]{2}.[\d]{2})((?:-[LPT]\d+){1,3})\]", RegexOptions.IgnoreCase); var regexLyrics = Regex.Matches(str, @"\[(LR|PR|TR):(.+?)\]", RegexOptions.IgnoreCase); // 문장 시작 시간 if (regexSen.Success) { Sentences.Add(new LyricsSentence { BeginTime = LyricsUtility.ToTime(regexSen.Groups[1].Value) }); } // 문장의 문자 매핑 foreach (Match matchMap in regexMap) { if (matchMap.Success) { var mapping = new LyricsMapping { BeginTime = LyricsUtility.ToTime(matchMap.Groups[1].Value), EndTime = LyricsUtility.ToTime(matchMap.Groups[2].Value), }; var regexMapCase = Regex.Matches(matchMap.Groups[3].Value, @"([LPT])(\d+)", RegexOptions.IgnoreCase); foreach (Match matchMapCase in regexMapCase) { if (matchMapCase.Success) { var position = new LyricsPosition { Position = int.Parse(matchMapCase.Groups[2].Value) }; switch (matchMapCase.Groups[1].Value) { case "L": mapping.Lyrics = position; break; case "P": mapping.Pronounce = position; break; case "T": mapping.Translation = position; break; } } } Sentences.Last().Mappings.Add(mapping); } } // 문장의 내용 설정 foreach (Match matchLyrics in regexLyrics) { if (matchLyrics.Success) { switch (matchLyrics.Groups[1].Value.ToUpper()) { case "LR": Sentences.Last().Lyrics = matchLyrics.Groups[2].Value; break; case "PR": Sentences.Last().Pronounce = matchLyrics.Groups[2].Value; break; case "TR": Sentences.Last().Translation = matchLyrics.Groups[2].Value; break; } } } } }