A container that represents all the subtitles.
Пример #1
0
        public object Clone()
        {
            SubtitleProperties propertiesClone = this.properties.Clone() as SubtitleProperties;
            SubtitleCollection collectionClone = this.collection.Clone(propertiesClone);

            return(new Subtitles(collectionClone, propertiesClone));
        }
Пример #2
0
	internal string Build (SubtitleCollection collection, SubtitleProperties subtitleProperties, FileProperties fileProperties) {
		this.subtitleProperties = subtitleProperties;
		StringBuilder output = new StringBuilder();
		if (format.HasHeaders)
			output.Append(format.HeadersToString(subtitleProperties, fileProperties));

		if (format.HasBodyBegin)
			output.Append(format.BodyBeginOut);

		string subtitleExpression = GetSubtitleExpression(format, subtitleProperties, fileProperties);
		Regex fieldExpression = new Regex(@"<<(?<Field>\w+)(,(?<Width>\d+))?>>");
		MatchEvaluator matchEvaluator = new MatchEvaluator(this.FieldEvaluator);

		foreach (Subtitle currentSubtitle in collection) {
			subtitle = currentSubtitle;
			string outputSubtitle = fieldExpression.Replace(subtitleExpression, matchEvaluator);
			output.Append(outputSubtitle);
			output.Append("\n");
			subtitleNumber++;
			previousSubtitle = subtitle;
		}

		if (format.HasBodyEnd)
			output.Append(format.BodyEndOut);

		subtitle = null;
		previousSubtitle = null;
		subtitleNumber = 1;

		ConvertNewlines(output, fileProperties);
		return output.ToString();
	}
Пример #3
0
	/* Public methods */

	public SubtitleCollection Clone (SubtitleProperties propertiesClone) {
		SubtitleCollection collectionClone = new SubtitleCollection();
		foreach (Subtitle subtitle in this.subtitles) {
			Subtitle subtitleClone = subtitle.Clone(propertiesClone);
			collectionClone.Add(subtitleClone);
		}
		return collectionClone;
	}
Пример #4
0
        /* Public methods */

        public SubtitleCollection Clone(SubtitleProperties propertiesClone)
        {
            SubtitleCollection collectionClone = new SubtitleCollection();

            foreach (Subtitle subtitle in this.subtitles)
            {
                Subtitle subtitleClone = subtitle.Clone(propertiesClone);
                collectionClone.Add(subtitleClone);
            }
            return(collectionClone);
        }
Пример #5
0
	/// <summary>Parses the specified text.</summary>
	/// <remarks>The created <see cref="SubtitleCollection" /> will have its <see cref="SubtitleProperties" /> property set to null.
	/// It is mandatory to use <see cref="SubtitleCollection.SetPropertiesForAll" /> after.</remarks>
	internal ParsingProperties Parse (string text, TimingMode timingMode, Encoding encoding, out SubtitleCollection collection) {

		collection = new SubtitleCollection();
		ParsingProperties properties = new ParsingProperties();
		this.text = text;
		properties.TimingMode = timingMode;

		/* Read the subtitles */
		ReadSubtitles(encoding, properties, collection);

		return properties;
	}
Пример #6
0
	private void ReadSubtitles (Encoding encoding, ParsingProperties properties, SubtitleCollection collection) {

		string[] lines = text.Split(new char[] {'\n'});
		for (int i = 0; i < lines.Length; i++) {
			SubtitleText stext = ParseSubtitleText(lines[i]);
			Style style = new Style();
			if(!stext.IsEmpty) {
				Subtitle subtitle = new Subtitle(null, stext, style);
				collection.Add(subtitle);
			}
		}

	}
Пример #7
0
	/// <summary>Parses the specified text, using the specified format.</summary>
	/// <remarks>The created <see cref="SubtitleCollection" /> will have its <see cref="SubtitleProperties" /> property set to null.
	/// It is mandatory to use <see cref="SubtitleCollection.SetPropertiesForAll" /> after.</remarks>
	internal ParsingProperties Parse (string text, SubtitleFormat format, float inputFrameRate,
			out SubtitleCollection collection, out IncompleteSubtitleCollection incompleteSubtitles){

		collection = new SubtitleCollection();
		incompleteSubtitles = new IncompleteSubtitleCollection();
		ParsingProperties properties = new ParsingProperties();
		properties.InputFrameRate = inputFrameRate;

		Regex subtitleRegex = null;
		int bodyIndex = 0;

		text = ClearComments(text, format);

		/* Read the headers if available */
		if (format.Mode == SubtitleMode.Both) {
			//Read headers to know if format is using Times or Frames
			bodyIndex = text.Length;
			int lastIndex = ReadHeaders(text, bodyIndex, format, properties);
			subtitleRegex = CreateSubtitleRegex(format, properties.TimingMode);

			/* Detect body index from matching the first subtitle or the end of headers */
			bodyIndex = FindBodyIndex(text, format, subtitleRegex);
			if (lastIndex > bodyIndex)
				bodyIndex = lastIndex;
		}
		else {
			//End of headers is detected by start of subtitles' body
			properties.TimingMode = format.ModeAsTimingMode;
			subtitleRegex = CreateSubtitleRegex(format);
			bodyIndex = FindBodyIndex(text, format, subtitleRegex);
			ReadHeaders(text, bodyIndex, format, properties);
		}

		/* Get properties from the whole input, if available */
		format.GlobalInputGetProperties(text, properties);

		int textLength = text.Length;

		/* Read the subtitles */
		bodyIndex = ReadSubtitles(text, bodyIndex, textLength, subtitleRegex, format,
			properties, collection, incompleteSubtitles);

    	/* Read the end text of the subtitles */
    	bodyIndex = ReadBodyEnd(text, bodyIndex, format, collection, incompleteSubtitles);

		/* Check if there's still text remaining */
    	if ((bodyIndex < textLength) && includeIncompleteSubtitles)
    		AddIncompleteSubtitle(incompleteSubtitles, text.Substring(bodyIndex), collection.Count);

    	return properties;
	}
Пример #8
0
	/* Internal members */

	/// <summary>Initializes a new instance of the <see cref="Subtitles" /> class.</summary>
	/// <param name="collection">A collection of subtitles.</param>
	/// <param name="properties">The subtitles' properties.</param>
	internal protected Subtitles (SubtitleCollection collection, SubtitleProperties properties) {
		this.collection = collection;
		this.properties = properties;
	}
Пример #9
0
        /* Internal members */

        /// <summary>Initializes a new instance of the <see cref="Subtitles" /> class.</summary>
        /// <param name="collection">A collection of subtitles.</param>
        /// <param name="properties">The subtitles' properties.</param>
        internal protected Subtitles(SubtitleCollection collection, SubtitleProperties properties)
        {
            this.collection = collection;
            this.properties = properties;
        }
Пример #10
0
    private int ReadBodyEnd (string text, int bodyIndex, SubtitleFormat format,
    		SubtitleCollection collection, IncompleteSubtitleCollection incompleteSubtitles) {

    	Regex bodyEnd = new Regex(format.BodyEndIn + @"\s*", RegexOptions.IgnoreCase);
    	Match bodyEndMatch = bodyEnd.Match(text, bodyIndex);
    	if (bodyEndMatch.Success) {
	   		AddIncompleteSubtitleIfExists(text, bodyEndMatch, bodyIndex, collection.Count, incompleteSubtitles);
    		bodyIndex = bodyEndMatch.Index + bodyEndMatch.Length;
    	}
    	return bodyIndex;
	}
Пример #11
0
	private int ReadSubtitles (string text, int bodyIndex, int textLength, Regex subtitleRegex, SubtitleFormat format,
		ParsingProperties properties, SubtitleCollection collection, IncompleteSubtitleCollection incompleteSubtitles) {

		Subtitle previousSubtitle = null;

		/* Read the subtitles. BodyIndex points to the start of the subtitles, skipping its possible beginning text*/
		while (bodyIndex < textLength) {
			Match match = subtitleRegex.Match(text, bodyIndex);
			if (match.Success) {
    			Subtitle subtitle = ParseSubtitle(match, format, properties, previousSubtitle);
    			collection.Add(subtitle);
				AddIncompleteSubtitleIfExists(text, match, bodyIndex, collection.Count, incompleteSubtitles);
	    		bodyIndex = match.Index + match.Length;
				previousSubtitle = subtitle;
   			}
   			else
    			break;
   		}
   		return bodyIndex;
   	}