예제 #1
0
        private static List <string> GetAllTimeLine(string line, out string lyric)
        {
            var list     = new List <string>();
            var lineInfo = new LyricLine(line);

            if (lineInfo.IsLyric)
            {
                list.Add(lineInfo.GetInfo());
                list.AddRange(GetAllTimeLine(lineInfo.Lyric, out lyric));
            }
            else
            {
                lyric = line;
            }
            return(list);
        }
예제 #2
0
        public LyricConverter(string s, bool message = true)
        {
            if (s.Trim().StartsWith("["))
            {
                lyric = s;
            }
            else if (s.Trim().StartsWith("{"))
            {
                lyric       = s.Trim();
                ignoreIndex = new List <int>();
                searchIndex = 0;
                while (searchIndex != -1)
                {
                    ignoreIndex.Add(GetNextIndex('\\'));
                }
                ignoreIndex.Remove(-1);
                searchIndex = 0;
                List <CloudMusicInfo> lyricInfo = GetLyricInfo();
                try
                {
                    //if (!(GetVal(lyricInfo, "nolyric") || GetVal(lyricInfo, "uncollected")))
                    if (GetVal(lyricInfo, "lrc") != null &&
                        GetVal(GetVal(lyricInfo, "lrc"), "version") > 0)
                    {
                        string ol = Escape(GetVal(GetVal(lyricInfo, "lrc"), "lyric"));

                        string[] newline = { Environment.NewLine };
                        string[] olg     = ol.Split(newline, StringSplitOptions.RemoveEmptyEntries);

                        List <string> total = new List <string>();

                        if (GetVal(GetVal(lyricInfo, "tlyric"), "version") > 0)
                        {
                            #region translate
                            string tl = Escape(GetVal(GetVal(lyricInfo, "tlyric"), "lyric"));

                            string[] tlg = tl.Split(newline, StringSplitOptions.RemoveEmptyEntries);

                            List <string> olgd = Expand(olg);
                            List <string> tlgd = Expand(tlg);


                            int n = olgd.Count();
                            int nt = tlgd.Count();
                            int i = 0, it = 0;

                            //List<string> oinfo = new List<string>();
                            //List<string> tinfo = new List<string>();

                            while (i < n && it < nt)
                            {
                                LyricLine o = new LyricLine(olgd[i]);
                                LyricLine t = new LyricLine(tlgd[it], true);
                                if (!o.IsLyric)
                                {
                                    i++;
                                    total.Add(o.GetInfo());
                                    continue;
                                }
                                if (!t.IsLyric)
                                {
                                    it++;
                                    total.Add(t.GetInfo());
                                    continue;
                                }
                                if (o.IsLyric && t.IsLyric)
                                {
                                    if (o.GetInfo().Contains("-"))
                                    {
                                        i++;
                                        continue;
                                    }
                                    if (t.GetInfo().Contains("-"))
                                    {
                                        it++;
                                        continue;
                                    }

                                    if (string.Compare(o.GetInfo(), t.GetInfo()) > 0)
                                    {
                                        it++;
                                        total.Add(t.GetInfo() + "译:" + t.Lyric);
                                    }
                                    else if (string.Compare(o.GetInfo(), t.GetInfo()) < 0)
                                    {
                                        total.Add(o.GetInfo() + o.Lyric);
                                        i++;
                                    }
                                    else
                                    {
                                        if (string.IsNullOrWhiteSpace(o.Lyric) ||
                                            string.IsNullOrWhiteSpace(t.Lyric))
                                        {
                                            total.Add(o.GetInfo() + o.Lyric + t.Lyric);
                                        }
                                        else if (o.Lyric != t.Lyric)
                                        {
                                            total.Add(o.GetInfo() + o.Lyric + "/" + t.Lyric);
                                        }
                                        else
                                        {
                                            total.Add(o.GetInfo() + o.Lyric);
                                        }

                                        i++;
                                        it++;
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {// 保证秒的小数点后面是两位
                            foreach (string line in olg)
                            {
                                LyricLine o = new LyricLine(line);
                                total.Add(o.GetInfo() + o.Lyric);
                            }
                        }

                        lyric = RemoveRepeatedLinesAndConnect(total);
                    }
                }
                catch
                {
                    //if (message) MessageBox.Show("请检查歌词文件"
                    //+ Environment.NewLine + s
                    //);
                    lyric = null;
                }
            }
            else
            {
                lyric = null;
            }
        }