Esempio n. 1
0
 public LyricClip Clone()
 {
     LyricClip clip = new LyricClip();
     clip.StartTime = this.StartTime;
     clip.EndTime = this.EndTime;
     clip.ClipLyric = this.ClipLyric;
     clip.AttachedInfo = this.AttachedInfo;
     return clip;
 }
Esempio n. 2
0
 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;
 }
 private static LyricContent MergeContent(LyricContent aLyric, LyricContent bLyric, string joinSpec)
 {
     LyricContent merge = new LyricContent();
     if (aLyric == null && bLyric == null)
         return merge;
     else
     {
         if (aLyric == null)
             return bLyric;
         if (bLyric == null)
             return aLyric;
         foreach (LyricClip aClip in aLyric)
         {
             LyricClip clip = aClip.Clone();
             List<LyricClip> bClippes = bLyric.FindSameClippes(clip);
             if (bClippes != null)
             {
                 foreach (LyricClip bClip in bClippes)
                 {
                     string fLyric = (clip.ClipLyric ?? string.Empty).Trim();
                     string lLyric = (bClip.ClipLyric ?? string.Empty).Trim();
                     string mSpec = joinSpec;
                     if (string.IsNullOrEmpty(fLyric) || string.IsNullOrEmpty(lLyric))
                         mSpec = string.Empty;
                     clip.ClipLyric = string.Format("{0}{1}{2}", fLyric, mSpec, lLyric);
                     bLyric.Remove(bClip);
                 }
             }
             merge.Add(clip);
         }
         foreach (LyricClip bClip in bLyric)
         {
             List<LyricClip> mixedClippes = merge.FindMixedClippes(bClip);
             if (mixedClippes.Count == 0)
             {
                 merge.Add(bClip.Clone());
             }
             else
             {
                 mixedClippes.Add(bClip);
                 LyricClip clip = new LyricClip();
                 foreach (LyricClip mixedClip in mixedClippes)
                 {
                     clip.StartTime = (clip.StartTime < mixedClip.StartTime) ? clip.StartTime : mixedClip.StartTime;
                     clip.EndTime = (clip.EndTime > mixedClip.EndTime) ? clip.EndTime : mixedClip.EndTime;
                     string fLyric = (clip.ClipLyric ?? string.Empty).Trim();
                     string lLyric = (mixedClip.ClipLyric ?? string.Empty).Trim();
                     string mSpec = joinSpec;
                     if (string.IsNullOrEmpty(fLyric) || string.IsNullOrEmpty(lLyric))
                         mSpec = string.Empty;
                     clip.ClipLyric = string.Format("{0}{1}{2}", fLyric, mSpec, lLyric);
                     if (mixedClip == bClip)
                         continue;
                     else
                         merge.Remove(mixedClip);
                 }
                 merge.Add(clip);
             }
         }
     }
     merge.SortClip();
     return merge;
 }
Esempio n. 4
0
 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;
 }