Example #1
0
        /// <summary>
        /// 현재 매핑의 전체 문자열을 반환합니다.
        /// </summary>
        /// <returns>현재 매핑의 문자열 변환 결과입니다.</returns>
        public override string ToString()
        {
            string lyrics      = Lyrics != null ? $"-L{Lyrics.Position}" : null;
            string pronounce   = Pronounce != null ? $"-P{Pronounce.Position}" : null;
            string translation = Translation != null ? $"-T{Translation.Position}" : null;

            return($"[{LyricsUtility.ToString(BeginTime)}~{LyricsUtility.ToString(EndTime)}{lyrics}{pronounce}{translation}]");
        }
Example #2
0
        /// <summary>
        /// 현재 가사의 전체 문자열을 반환합니다.
        /// </summary>
        /// <returns>현재 가사의 문자열 변환 결과입니다.</returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"[{LyricsUtility.ToString(BeginTime)}]");

            foreach (LyricsMapping mapping in Mappings)
            {
                builder.AppendLine(mapping.ToString());
            }

            builder.AppendLine($"[LR:{Lyrics}]");
            if (Pronounce != null)
            {
                builder.AppendLine($"[PR:{Pronounce}]");
            }
            if (Translation != null)
            {
                builder.AppendLine($"[TR:{Translation}]");
            }

            return(builder.ToString());
        }
Example #3
0
        /// <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;
                        }
                    }
                }
            }
        }