Exemplo n.º 1
0
 public void ImportQRC(string fileName)
 {
     try
     {
         XmlDocument document = new XmlDocument();
         document.Load(fileName);
         string          attribute = document.SelectSingleNode("QrcInfos/LyricInfo")["Lyric_1"].GetAttribute("LyricContent");
         Regex           regex     = new Regex(@"\[ti:[^\r]+\r");
         Regex           regex2    = new Regex(@"\[ar:[^\r]+\r");
         Regex           regex3    = new Regex(@"\[al:[^\r]+\r");
         Regex           regex4    = new Regex(@"\[by:[^\r]+\r");
         Regex           regex5    = new Regex(@"\[\d{2,}[^\r]+\r");
         Regex           regex6    = new Regex(@"\[[^\]]+\]");
         Regex           regex7    = new Regex(@"\(\d{2,},\d{2,}\)");
         MatchCollection matchs    = regex5.Matches(attribute);
         foreach (Match match in matchs)
         {
             string[]   strArray;
             string     input = match.ToString();
             OneLineLrc item  = new OneLineLrc();
             string     str3  = regex6.Match(input).ToString();
             if (str3.Trim().Length > 1)
             {
                 strArray       = str3.Substring(1, str3.Length - 2).Split(new char[] { ',' });
                 item.StartTime = Convert.ToInt32(strArray[0]);
                 item.EndTime   = Convert.ToInt32(strArray[0]) + Convert.ToInt32(strArray[1]);
             }
             input = Regex.Replace(Regex.Replace(Regex.Replace(input, @"\[[^\]]+\]", ""), "\r", ""), "\r\n", "");
             MatchCollection matchs2 = regex7.Matches(input);
             string          str4    = "";
             foreach (Match match2 in matchs2)
             {
                 strArray = match2.ToString().Substring(1, match2.ToString().Length - 2).Split(new char[] { ',' });
                 str4     = str4 + strArray[0] + ",";
             }
             str4         = str4.Substring(0, str4.Length - 1);
             item.MidTime = str4;
             input        = Regex.Replace(input, @"\(\d{2,},\d{2,}\)", ",");
             input        = input.Substring(0, input.Length - 1);
             item.LrcText = input;
             this._lrcList.Add(item);
         }
         this._isLoad = true;
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Exemplo n.º 2
0
        public void ImportKSC(string text)
        {
            Regex regex  = new Regex("'[^']+'");
            Regex regex2 = new Regex(@"\d{2}:\d{2}");
            Regex regex3 = new Regex(@"karaoke\.add\([^\r]+\r");
            Regex regex4 = new Regex("蓝天阁");

            try
            {
                MatchCollection matchs = regex3.Matches(text);
                foreach (Match match in matchs)
                {
                    if (!regex4.IsMatch(match.ToString()))
                    {
                        MatchCollection matchs2 = regex.Matches(match.ToString());
                        if (matchs2.Count == 4)
                        {
                            OneLineLrc item = new OneLineLrc
                            {
                                StartTime = this.FormatTime(matchs2[0].ToString()),
                                EndTime   = this.FormatTime(matchs2[1].ToString()),
                                LrcText   = this.CheckLrc(matchs2[2].ToString().Substring(1, matchs2[2].ToString().Length - 2) + "\r")
                            };
                            string[] strArray  = matchs2[3].ToString().Substring(1, matchs2[3].ToString().Length - 2).Split(new char[] { ',' });
                            string   str       = "";
                            int      startTime = item.StartTime;
                            foreach (string str2 in strArray)
                            {
                                int num2 = Convert.ToInt32(str2);
                                str = str + ((startTime + num2)).ToString() + ",";
                            }
                            item.MidTime = str.Substring(0, str.Length - 1);
                            this._lrcList.Add(item);
                        }
                    }
                }
                this._isLoad = true;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Exemplo n.º 3
0
        public void ImportLRC(string text)
        {
            Regex         regex  = new Regex(@"\[ti:[^\r]+\r");
            Regex         regex2 = new Regex(@"\[ar:[^\r]+\r");
            Regex         regex3 = new Regex(@"\[al:[^\r]+\r");
            Regex         regex4 = new Regex(@"\[by:[^\r]+\r");
            Regex         regex5 = new Regex(@"[^\]]+\r");
            Regex         regex6 = new Regex(@"\[\d{2}:\d{2}(?:\]|\.\d{2}\]|\.\d{3}\])");
            Regex         regex7 = new Regex(@"\[\d{2}[^\r]+\r");
            List <string> list   = new List <string>();

            this.LrcTextString = this.LrcTextString.Replace("|", "|");
            this.LrcTextString = this.LrcTextString.Replace(",", ",");
            try
            {
                this._title = regex.Match(this.LrcTextString).ToString().Trim();
                this._ar    = regex2.Match(this.LrcTextString).ToString().Trim();
                this._album = regex3.Match(this.LrcTextString).ToString().Trim();
                this._by    = regex4.Match(this.LrcTextString).ToString().Trim();
                if (!string.IsNullOrEmpty(this._title.Trim()))
                {
                    this._title = Regex.Replace(this._title, "ti", "歌名") + "\r";
                }
                if (!string.IsNullOrEmpty(this._ar))
                {
                    this._ar = Regex.Replace(this._ar, "ar", "歌手") + "\r";
                }
                if (!string.IsNullOrEmpty(this._album))
                {
                    this._album = Regex.Replace(this._album, "al", "专辑") + "\r";
                }
                if (!string.IsNullOrEmpty(this._by))
                {
                    this._by = Regex.Replace(this._by, "by", "出处") + "\r";
                }
                MatchCollection matchs = regex7.Matches(this.LrcTextString);
                foreach (Match match in matchs)
                {
                    string str = regex5.Match(match.ToString()).ToString();
                    if (str.Trim().Length > 1)
                    {
                        MatchCollection matchs2 = regex6.Matches(match.ToString());
                        foreach (Match match2 in matchs2)
                        {
                            list.Add(match2.ToString() + "|" + this.CheckLrc(str));
                        }
                    }
                }
                list.Sort();
                foreach (string str in list)
                {
                    string[] strArray = str.Split(new char[] { '|' });
                    if (strArray.Length == 2)
                    {
                        OneLineLrc item = new OneLineLrc
                        {
                            StartTime    = this.FormatTime(strArray[0]),
                            StartTimeStr = strArray[0],
                            LrcText      = strArray[1]
                        };
                        this._lrcList.Add(item);
                    }
                }
                for (int i = 0; i < this._lrcList.Count; i++)
                {
                    int    num7;
                    int    num2 = this._lrcList[i].LrcText.Split(new char[] { ',' }).Count <string>();
                    string str2 = "";
                    if (i < (this._lrcList.Count - 1))
                    {
                        int num3      = (this._lrcList[i + 1].StartTime - this._lrcList[i].StartTime) - 500;
                        int num4      = num3 % num2;
                        int num5      = num3 / num2;
                        int startTime = this._lrcList[i].StartTime;
                        num7 = 0;
                        while (num7 < num2)
                        {
                            if (num7 < (num2 - 1))
                            {
                                startTime += num5;
                                str2       = str2 + startTime.ToString() + ",";
                            }
                            else
                            {
                                str2 = str2 + (((startTime + num5) + num4)).ToString();
                            }
                            num7++;
                        }
                        this._lrcList[i].EndTime = this._lrcList[i + 1].StartTime - 500;
                        this._lrcList[i].MidTime = str2;
                    }
                    else
                    {
                        for (num7 = 0; num7 < num2; num7++)
                        {
                            if (num7 < (num2 - 1))
                            {
                                str2 = str2 + "0,";
                            }
                            else
                            {
                                str2 = str2 + "0";
                            }
                        }
                        this._lrcList[i].EndTime = this._lrcList[i].StartTime + 0x3e8;
                        this._lrcList[i].MidTime = str2;
                    }
                }
                this._isLoad = true;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }