Represents the root class of all the subtitles.
A Subtitles class is created using the SubtitleFactory.
상속: ICloneable
예제 #1
0
        public void OpenTranslation(string path, Encoding encoding)
        {
            if (this.IsTranslationLoaded)
            {
                CloseTranslation();
            }

            SubtitleFactory factory = new SubtitleFactory();

            factory.Encoding         = encoding;
            factory.FallbackEncoding = GetFallbackEncoding();

            SubLib.Core.Domain.Subtitles openedTranslation = factory.Open(path);
            FileProperties newTranslationFile = factory.FileProperties;

            AddExtraSubtitles(openedTranslation);

            Translations translations = new Translations();

            translations.Import(subtitles, openedTranslation, Base.Config.TimingsTimeBetweenSubtitles);

            if (newTranslationFile.SubtitleType != SubtitleType.Unknown)
            {
                canTranslationBeSaved = true;
            }

            this.translationFile     = newTranslationFile;
            this.isTranslationLoaded = true;
        }
예제 #2
0
        /* Used in the object construction */
        private void Open(string path, Encoding encoding)
        {
            SubtitleFactory factory = new SubtitleFactory();

            factory.Encoding         = encoding;
            factory.FallbackEncoding = GetFallbackEncoding();
            factory.InputFrameRate   = Base.Ui.Menus.TimingsInputFrameRateActive;

            SubLib.Core.Domain.Subtitles openedSubtitles = null;
            try {
                openedSubtitles = factory.Open(path);
            }
            catch (FileNotFoundException) {
                New(path);
                return;
            }

            subtitles = new Ui.View.Subtitles(openedSubtitles);
            textFile  = factory.FileProperties;

            if (textFile.SubtitleType != SubtitleType.Unknown)
            {
                canTextBeSaved = true;
            }
        }
예제 #3
0
	/// <summary>Copies the translation to the subtitles.</summary>
	private void CopyTranslation (Subtitles subtitles, Subtitles translation) {
		for (int subtitleNumber = 0 ; subtitleNumber < translation.Collection.Count ; subtitleNumber++) {
			Subtitle translated = translation.Collection[subtitleNumber];
			Subtitle original = subtitles.Collection[subtitleNumber];

			string translatedText = translated.Text.Get();
			original.Translation.Set(translatedText);
		}
	}
예제 #4
0
        private void AddExtraSubtitles(SubLib.Core.Domain.Subtitles translation)
        {
            int extraCount = translation.Collection.Count - subtitles.Collection.Count;

            if (extraCount > 0)
            {
                subtitles.AddExtra(extraCount);
            }
        }
예제 #5
0
	/* Public methods */

	/// <summary>Saves subtitles to the file with the specified properties.</summary>
	/// <param name="subtitles">The subtitles to save.</param>
	/// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to
	/// choose the timing mode for subtitle formats that support both time and frame modes.</param>
	/// <param name="textType">The type of text content to save.</param>
	/// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks>
	public void Save (Subtitles subtitles, FileProperties properties, SubtitleTextType textType) {
		SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
		SubtitleOutput output = new SubtitleOutput(format, textType);

		string text = output.Build(subtitles.Collection, subtitles.Properties, properties);
		FileInputOutput.WriteFile(properties.Path, text, properties.Encoding);

		fileProperties = GetUpdatedFileProperties(properties);
		VerboseConsole.WriteLine("[*] Saved " + textType + " \"" + properties.Path + "\" with encoding \"" + properties.Encoding + "\", format \"" + format.Name + "\" and frame rate \"" + subtitles.Properties.CurrentFrameRate + "\"");
	}
예제 #6
0
	/// <summary>Adds the number of subtitles missing comparing to the translation.</summary>
	private void AddExtraSubtitles (Subtitles subtitles, Subtitles translation, int timeBetweenSubtitles) {
		int translationCount = translation.Collection.Count;
		int subtitlesCount = subtitles.Collection.Count;
		int extraCount = translationCount - subtitlesCount;

		if (extraCount <= 0)
			return;

		for (int position = subtitlesCount - 1 ; position < translationCount - 1 ; position++) {
			subtitles.Collection.AddNewAfter(position, subtitles.Properties, timeBetweenSubtitles);
		}
	}
예제 #7
0
 private bool SaveFile(SubLib.Core.Domain.Subtitles subtitles, FileProperties properties, SubtitleTextType textType)
 {
     try {
         SubtitleSaver saver = new SubtitleSaver();
         saver.Save(subtitles, properties, textType);
         return(true);
     }
     catch (Exception e) {
         Logger.Error(e, "Caught an exception while saving backup file");
         return(false);
     }
 }
예제 #8
0
	/// <summary>Auto syncs a range of subtitles given their first and last correct frames.</summary>
	/// <remarks>The subtitles are first shifted to the first subtitle's correct frame, and then proportionally
	/// adjusted using the last subtitle's correct frame.</remarks>
	/// <param name="subtitles">The subtitles to sync.</param>
	/// <param name="startIndex">The subtitle index to start the adjustment with.</param>
	/// <param name="startFrame">The correct start frame for the first subtitle.</param>
	/// <param name="endIndex">The subtitle index to end the adjustment with.</param>
	/// <param name="endFrame">The correct start frame for the last subtitle.</param>
	/// <param name="syncLast">Whether to sync the last subtitle.</param>
	/// <returns>Whether the subtitles could be adjusted.</returns>
	public static bool Sync (Subtitles subtitles, int startIndex, int startFrame, int endIndex, int endFrame, bool syncLast) {
		if (!AreSyncArgsValid(subtitles, startIndex, startFrame, endIndex, endFrame))
			return false;

		/* Perform initial calculations */
		int syncEndIndex = (syncLast ? endIndex : endIndex - 1);
		Subtitle startSubtitle = subtitles.Collection.Get(startIndex);
		int shift = (int)(startFrame - startSubtitle.Frames.PreciseStart);
		Subtitle endSubtitle = subtitles.Collection.Get(endIndex);
		double factor = (endFrame - startFrame) / (endSubtitle.Frames.PreciseStart - startFrame);

		/* Shift subtitles to the start point */
		if (shift != 0) {
			ShiftOperator shiftOp = new ShiftOperator(subtitles);
			shiftOp.Shift(shift, startIndex, syncEndIndex);
		}

		/* Auto adjust timings with proportion */
		for (int index = startIndex ; index <= syncEndIndex ; index++) {
			Subtitle subtitle = subtitles.Collection.Get(index);
			subtitle.Frames.Scale(factor, startFrame);
		}
		return true;
	}
예제 #9
0
	/// <summary>Auto syncs a range of subtitles given their first and last correct times.</summary>
	/// <remarks>The subtitles are first shifted to the first subtitle's correct time, and then proportionally
	/// adjusted using the last subtitle's correct time.</remarks>
	/// <param name="subtitles">The subtitles to sync.</param>
	/// <param name="startIndex">The subtitle index to start the adjustment with.</param>
	/// <param name="startTime">The correct start time for the first subtitle.</param>
	/// <param name="endIndex">The subtitle index to end the adjustment with.</param>
	/// <param name="endTime">The correct start time for the last subtitle.</param>
	/// <param name="syncLast">Whether to sync the last subtitle.</param>
	/// <returns>Whether the subtitles could be adjusted.</returns>
	public static bool Sync (Subtitles subtitles, int startIndex, TimeSpan startTime, int endIndex, TimeSpan endTime, bool syncLast) {
		if (!AreSyncArgsValid(subtitles, startIndex, startTime, endIndex, endTime))
			return false;

		/* Perform initial calculations */
		int syncEndIndex = (syncLast ? endIndex : endIndex - 1);
		Subtitle startSubtitle = subtitles.Collection.Get(startIndex);
		TimeSpan shift = startTime - startSubtitle.Times.PreciseStart;
		Subtitle endSubtitle = subtitles.Collection.Get(endIndex);
		double factor = (endTime - startTime).TotalMilliseconds / (endSubtitle.Times.PreciseStart - startSubtitle.Times.PreciseStart).TotalMilliseconds;

		/* Shift subtitles to the start point */
		if (shift != TimeSpan.Zero) {
			ShiftOperator shiftOp = new ShiftOperator(subtitles);
			shiftOp.Shift(shift, startIndex, syncEndIndex);
		}

		/* Sync timings with proportion */
		for (int index = startIndex ; index <= syncEndIndex ; index++) {
			Subtitle subtitle = subtitles.Collection.Get(index);
			subtitle.Times.Scale(factor, startTime);
		}
		return true;
	}
예제 #10
0
	/// <summary>Removes the entire translation from existing subtitles.</summary>
	/// <param name="subtitles">The subtitles to remove the translation from.</param>
	public void Clear (Subtitles subtitles) {
		foreach (Subtitle subtitle in subtitles.Collection)
			subtitle.ClearTranslation();
	}
예제 #11
0
	public static bool AreSyncPointsValid (Subtitles subtitles, SyncPoint start, SyncPoint end) {
		return AreSyncArgsValid(subtitles, start.SubtitleNumber, start.Correct.Time, end.SubtitleNumber, end.Correct.Time)
			&& AreSyncArgsValid(subtitles, start.SubtitleNumber, start.Correct.Frame, end.SubtitleNumber, end.Correct.Frame);
	}
예제 #12
0
	private static bool AreSyncArgsValid (Subtitles subtitles, int startIndex, int startTime, int endIndex, int endTime) {
		if (!AreSyncIndicesValid(subtitles, startIndex, endIndex))
			return false;
		else if (!(startTime < endTime))
			return false;
		else
			return true;
	}
예제 #13
0
	public AdjustOperator (Subtitles subtitles) {
		this.subtitles = subtitles;
	}
예제 #14
0
	private static bool AreSyncIndicesValid (Subtitles subtitles, int startIndex, int endIndex) {
		int subtitleCount = subtitles.Collection.Count;
		if (subtitleCount < 2)
			return false;
		else if (!(startIndex < endIndex))
			return false;
		else if ((startIndex < 0) || (startIndex >= (subtitleCount - 1)))
			return false;
		else if (endIndex >= subtitleCount)
			return false;
		else
			return true;
	}
예제 #15
0
	public SearchOperator (Subtitles subtitles) {
		this.subtitles = subtitles;
	}
예제 #16
0
	public FrameRateOperator (Subtitles subtitles) {
		this.subtitles = subtitles;
	}
예제 #17
0
	/* Public methods */

	//TODO have more elaborate heuristics, taking the times into account and reporting errors
	/// <summary>Imports translated subtitles into existing subtitles.</summary>
	/// <param name="subtitles">The subtitles to import the translation to.</param>
	/// <param name="translation">The translated subtitles.</param>
	public void Import (Subtitles subtitles, Subtitles translation, int timeBetweenSubtitles) {
		AddExtraSubtitles(subtitles, translation, timeBetweenSubtitles);
		CopyTranslation(subtitles, translation);
	}
예제 #18
0
	public static bool Sync (Subtitles subtitles, SyncPoint start, SyncPoint end, bool syncLast) {
		return Sync(subtitles, start.SubtitleNumber, start.Correct.Time, end.SubtitleNumber, end.Correct.Time, syncLast);
	}
예제 #19
0
	/* Private methods */

	/// <summary>Adds the number of subtitles that the translation has more than the original subtitles.</summary>
	/// <remarks>A gap between subtitles of <see cref="SubtitleConstants.MinTimeBetweenSubtitles" /> will be used.</remarks>
	private void AddExtraSubtitles (Subtitles subtitles, Subtitles translation) {
		AddExtraSubtitles(subtitles, translation, (int)(SubtitleConstants.MinTimeBetweenSubtitles));
	}
예제 #20
0
 public Subtitles(SubLib.Core.Domain.Subtitles subtitles) : base(subtitles.Collection, subtitles.Properties)
 {
     LoadModelFromCollection();
 }