Example #1
0
 /// <summary>
 /// Unifies two CardInfo into one (merging). The two CardInfo have to be compatible
 /// which can be checked with IsMergePossbile().
 /// </summary>
 public CardInfo(CardInfo first, CardInfo second)
 {
     this.targetLanguageLines = first.targetLanguageLines.Concat(second.targetLanguageLines).ToList();
     this.nativeLanguageLines = first.nativeLanguageLines.Concat(second.nativeLanguageLines).ToList();
     this.episodeInfo         = first.episodeInfo;
     this.startTimestamp      = Math.Min(first.startTimestamp, second.startTimestamp);
     this.endTimestamp        = Math.Max(first.endTimestamp, second.endTimestamp);
     this.audioStartTimestamp = Math.Min(first.audioStartTimestamp, second.audioStartTimestamp);
     this.audioEndTimestamp   = Math.Max(first.audioEndTimestamp, second.audioEndTimestamp);
     this.isActive            = first.isActive || second.isActive;
 }
Example #2
0
        /// <summary>
        /// Creates an card information for LineInfo (without matching/without native language LineInfos).
        /// </summary>
        public static List <CardInfo> GetCardInfo(Settings settings, EpisodeInfo episodeInfo, List <LineInfo> lines)
        {
            var cardInfos = new List <CardInfo>();

            foreach (var line in lines)
            {
                var thisCardLineInfos = new List <LineInfo>();
                thisCardLineInfos.Add(line);
                cardInfos.Add(new CardInfo(thisCardLineInfos, new List <LineInfo>(), episodeInfo,
                                           line.StartTime, line.EndTime,
                                           line.StartTime - settings.AudioPaddingBefore,
                                           line.EndTime + settings.AudioPaddingAfter));
            }
            return(cardInfos);
        }
Example #3
0
 public CardInfo(List <LineInfo> targetLanguageLines,
                 List <LineInfo> nativeLanguageLines,
                 EpisodeInfo episodeInfo,
                 double startTimestamp,
                 double endTimestamp,
                 double audioStartTimestamp,
                 double audioEndTimestamp)
 {
     this.targetLanguageLines = targetLanguageLines;
     this.nativeLanguageLines = nativeLanguageLines;
     this.episodeInfo         = episodeInfo;
     this.startTimestamp      = startTimestamp;
     this.endTimestamp        = endTimestamp;
     this.audioStartTimestamp = audioStartTimestamp;
     this.audioEndTimestamp   = audioEndTimestamp;
     this.isActive            = true;
 }
Example #4
0
        /// <summary>
        /// Align subtitle line by constant value, to audio or to other subtitle based on settings in "perSubSettings".
        /// </summary>
        public static void AlignSub(List <LineInfo> lineList, List <LineInfo> referenceList, EpisodeInfo epInfo, Settings settings, PerSubtitleSettings thisSubSettings)
        {
            switch (thisSubSettings.AlignMode)
            {
            case PerSubtitleSettings.AlignModes.ByConstantValue:
                UtilsSubtitle.ShiftByTime(lineList, thisSubSettings.SubDelay);
                break;

            case PerSubtitleSettings.AlignModes.ToAudio:
                UtilsAlignSubToAudio alignToAudio = new UtilsAlignSubToAudio(lineList, epInfo.AudioFileDesc);
                UtilsSubtitle.ShiftByTime(lineList, alignToAudio.GetBestShiftValue());
                break;

            case PerSubtitleSettings.AlignModes.ToSubtitle:
                if (referenceList == null)
                {
                    throw new Exception("Can not align subtitle to other non-existent subtitle.");
                }
                UtilsAlignSubToSub alignToSub = new UtilsAlignSubToSub(lineList, referenceList);
                alignToSub.Retime();
                break;
            }
        }
Example #5
0
        /// <summary>
        /// Creates an card information for every BiMatchedLine object.
        /// </summary>
        public static List <CardInfo> GetCardInfo(Settings settings, EpisodeInfo episodeInfo, IEnumerable <SubtitleMatcher.BiMatchedLines> matchedLinesList)
        {
            var returnList = new LinkedList <CardInfo> ();

            foreach (SubtitleMatcher.BiMatchedLines matchedLines in matchedLinesList)
            {
                // ignore line when no counterpart was found
                bool deactivated = false;
                if (matchedLines.listlines [0].Count == 0 || matchedLines.listlines [1].Count == 0)
                {
                    deactivated = true;
                }

                bool   timestamspUninitialized = true;
                double startTimestamp          = 0;
                double endTimestamp            = 0;


                Func <IEnumerable <LineInfo>, String> catenateString = delegate(IEnumerable <LineInfo> lineInfos) {
                    StringBuilder thisStringBuilder = new StringBuilder();
                    foreach (var thisLineInfo in lineInfos)
                    {
                        thisStringBuilder.Append(thisLineInfo.text + "|");

                        // adjust timestamps to this line
                        if (timestamspUninitialized)
                        {
                            // initialize timestamps
                            startTimestamp          = thisLineInfo.StartTime;
                            endTimestamp            = thisLineInfo.EndTime;
                            timestamspUninitialized = false;
                        }
                        else
                        {
                            startTimestamp = Math.Min(startTimestamp, thisLineInfo.StartTime);
                            endTimestamp   = Math.Max(endTimestamp, thisLineInfo.EndTime);
                        }
                    }
                    return(thisStringBuilder.ToString());
                };

                catenateString(matchedLines.listlines [0]);
                catenateString(matchedLines.listlines [1]);

                var cardInfo = new CardInfo(
                    matchedLines.listlines[0].ToList(),
                    matchedLines.listlines[1].ToList(),
                    episodeInfo,
                    startTimestamp, endTimestamp,
                    startTimestamp - settings.AudioPaddingBefore,
                    endTimestamp + settings.AudioPaddingAfter);
                cardInfo.isActive = !deactivated;
                returnList.AddLast(cardInfo);
            }


            var retList = new List <CardInfo>(returnList);

            retList.Sort();
            return(retList);
        }