Ejemplo n.º 1
0
        private bool ParseHeaderSubViewer2(Match match, ParsingProperties properties)
        {
            Headers headers   = properties.Headers;
            string  result    = String.Empty;
            int     intResult = 0;

            if (!ParseHeaderSubViewer1(match, properties, headers))
            {
                if (ParseGroup(match, "Comment", ref result))
                {
                    headers.Comment = result;
                }
                else if (ParseGroup(match, "FontName", ref result))
                {
                    headers.SubViewer2FontName = result;
                }
                else if (ParseGroup(match, "FontColor", ref result))
                {
                    headers.SubViewer2FontColor = result;
                }
                else if (ParseGroup(match, "FontStyle", ref result))
                {
                    headers.SubViewer2FontStyle = result;
                }
                else if (ParseGroup(match, "FontSize", ref intResult))
                {
                    headers.SubViewer2FontSize = intResult;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <returns>The index where subtitles start.</returns>
        private int ReadHeaders(string text, int bodyIndex, SubtitleFormat format, ParsingProperties properties)
        {
            if (!(format.HasHeaders && (bodyIndex > 0)))
            {
                return(0);
            }

            ParseHeaderDelegate headerParser = GetHeaderParser(format.Type);

            int    lastIndex  = 0; //the last index with header text
            string headerText = text.Substring(0, bodyIndex);

            foreach (string headerExpression in format.Headers)
            {
                Regex expression = new Regex(headerExpression, RegexOptions.IgnoreCase);
                Match match      = expression.Match(headerText, 0, bodyIndex);
                if (match.Success)
                {
                    /* Update the last index based on the header match */
                    int matchLastIndex = match.Index + match.Length;
                    if (matchLastIndex > lastIndex)
                    {
                        lastIndex = matchLastIndex;
                    }

                    headerParser(match, properties);
                }
            }
            return(lastIndex);
        }
Ejemplo n.º 3
0
        private bool ParseHeaderSubStationAlphaAAS(Match match, ParsingProperties properties)
        {
            Headers headers   = properties.Headers;
            string  result    = String.Empty;
            int     intResult = 0;

            if (ParseGroup(match, "Title", ref result))
            {
                headers.Title = result;
            }
            else if (ParseGroup(match, "OriginalScript", ref result))
            {
                headers.SubStationAlphaOriginalScript = result;
            }
            else if (ParseGroup(match, "OriginalTranslation", ref result))
            {
                headers.SubStationAlphaOriginalTranslation = result;
            }
            else if (ParseGroup(match, "OriginalEditing", ref result))
            {
                headers.SubStationAlphaOriginalEditing = result;
            }
            else if (ParseGroup(match, "OriginalTiming", ref result))
            {
                headers.SubStationAlphaOriginalTiming = result;
            }
            else if (ParseGroup(match, "OriginalScriptChecking", ref result))
            {
                headers.SubStationAlphaOriginalScriptChecking = result;
            }
            else if (ParseGroup(match, "ScriptUpdatedBy", ref result))
            {
                headers.SubStationAlphaScriptUpdatedBy = result;
            }
            else if (ParseGroup(match, "Collisions", ref result))
            {
                headers.SubStationAlphaCollisions = result;
            }
            else if (ParseGroup(match, "PlayResX", ref intResult))
            {
                headers.SubStationAlphaPlayResX = intResult;
            }
            else if (ParseGroup(match, "PlayResY", ref intResult))
            {
                headers.SubStationAlphaPlayResY = intResult;
            }
            else if (ParseGroup(match, "PlayDepth", ref intResult))
            {
                headers.SubStationAlphaPlayDepth = intResult;
            }
            else if (ParseGroup(match, "Timer", ref result))
            {
                headers.SubStationAlphaTimer = result;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        private bool ParseHeaderKaraokeLyricsVKT(Match match, ParsingProperties properties)
        {
            Headers headers = properties.Headers;
            string  result  = String.Empty;

            if (ParseGroup(match, "FrameRate", ref result))
            {
                headers.FrameRate = result;
            }
            else if (ParseGroup(match, "Author", ref result))
            {
                headers.Author = result;
            }
            else if (ParseGroup(match, "Source", ref result))
            {
                headers.Source = result;
            }
            else if (ParseGroup(match, "Date", ref result))
            {
                headers.Date = result;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private void ParseStartTime(Match match, Times times, Times previousTimes, ParsingProperties properties)
        {
            bool     isTimeDefined = false;
            TimeSpan startTime     = new TimeSpan(0);

            int   result      = 0;
            float floatResult = 0;

            if (ParseGroup(match, "StartHours", ref result))
            {
                startTime    += TimeSpan.FromHours(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartMinutes", ref result))
            {
                startTime    += TimeSpan.FromMinutes(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartSeconds", ref result))
            {
                startTime    += TimeSpan.FromSeconds(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartDeciseconds", ref result))
            {
                startTime    += TimeSpan.FromMilliseconds(result * 100);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartCentiseconds", ref result))
            {
                startTime    += TimeSpan.FromMilliseconds(result * 10);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartMilliseconds", ref result))
            {
                startTime    += TimeSpan.FromMilliseconds(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "StartMillisecondsAsFrames", ref result))
            {
                startTime    += TimingUtil.FramesToTime(result, properties.InputFrameRate);
                isTimeDefined = true;
            }

            if (ParseGroup(match, "StartElapsedTime", ref floatResult))
            {
                if (previousTimes != null)
                {
                    startTime += previousTimes.PreciseEnd;
                }

                startTime    += TimeSpan.FromSeconds(floatResult);
                isTimeDefined = true;
            }
            if (isTimeDefined)
            {
                times.PreciseStart = startTime;
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private void ParseEndTime(Match match, Times times, Times previousTimes, ParsingProperties properties)
        {
            bool     isTimeDefined = false;
            TimeSpan endTime       = new TimeSpan(0);

            int   result      = 0;
            float floatResult = 0;

            if (ParseGroup(match, "EndHours", ref result))
            {
                endTime      += TimeSpan.FromHours(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndMinutes", ref result))
            {
                endTime      += TimeSpan.FromMinutes(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndSeconds", ref result))
            {
                endTime      += TimeSpan.FromSeconds(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndDeciseconds", ref result))
            {
                endTime      += TimeSpan.FromMilliseconds(result * 100);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndCentiseconds", ref result))
            {
                endTime      += TimeSpan.FromMilliseconds(result * 10);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndMilliseconds", ref result))
            {
                endTime      += TimeSpan.FromMilliseconds(result);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndMillisecondsAsFrames", ref result))
            {
                endTime      += TimingUtil.FramesToTime(result, properties.InputFrameRate);
                isTimeDefined = true;
            }
            if (ParseGroup(match, "EndElapsedTime", ref floatResult))
            {
                endTime      += times.PreciseStart + TimeSpan.FromSeconds(floatResult);
                isTimeDefined = true;
            }
            if (isTimeDefined)
            {
                times.PreciseEnd = endTime;
            }
        }
Ejemplo n.º 8
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;
	}
Ejemplo n.º 9
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);
			}
		}

	}
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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;
	}
Ejemplo n.º 12
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);
         }
     }
 }
Ejemplo n.º 13
0
        private bool ParseHeaderMPSub(Match match, ParsingProperties properties)
        {
            Headers headers     = properties.Headers;
            string  result      = String.Empty;
            float   floatResult = 0;

            if (ParseGroup(match, "Title", ref result))
            {
                headers.Title = result;
            }
            else if (ParseGroup(match, "File", ref result))
            {
                headers.MPSubFileProperties = result;
            }
            else if (ParseGroup(match, "Author", ref result))
            {
                headers.Author = result;
            }
            else if (ParseGroup(match, "MediaType", ref result))
            {
                headers.MPSubMediaType = result;
            }
            else if (ParseGroup(match, "Note", ref result))
            {
                headers.Comment = result;
            }
            //Used to detect if a subtitles' timing mode is Times in the case of a format that supports both
            else if (ParseGroup(match, "TimingModeTimes", ref result))
            {
                properties.TimingMode = TimingMode.Times;
            }
            //Used to detect if a subtitles' timing mode is Frames in the case of a format that supports both
            else if (ParseGroup(match, "TimingModeFrames", ref floatResult))
            {
                properties.TimingMode     = TimingMode.Frames;
                properties.InputFrameRate = floatResult;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 14
0
        private Subtitle ParseSubtitle(Match match, SubtitleFormat format, ParsingProperties properties, Subtitle previousSubtitle)
        {
            SubtitleText text  = ParseSubtitleText(match, format);
            Style        style = ParseStyle(match, format);

            Subtitle subtitle = new Subtitle(null, text, style);

            if (properties.TimingMode == TimingMode.Frames)
            {
                Frames previousFrames = (previousSubtitle == null ? null : previousSubtitle.Frames);
                ParseFrames(match, subtitle.Frames, previousFrames);
            }
            else
            {
                Times previousTimes = (previousSubtitle == null ? null : previousSubtitle.Times);
                ParseTimes(match, subtitle.Times, previousTimes, properties);
            }

            format.SubtitleInputPostProcess(subtitle);
            return(subtitle);
        }
Ejemplo n.º 15
0
        private bool ParseHeaderKaraokeLyricsLRC(Match match, ParsingProperties properties)
        {
            Headers headers = properties.Headers;
            string  result  = String.Empty;

            if (ParseGroup(match, "Title", ref result))
            {
                headers.Title = result;
            }
            else if (ParseGroup(match, "Author", ref result))
            {
                headers.Author = result;
            }
            else if (ParseGroup(match, "Artist", ref result))
            {
                headers.Artist = result;
            }
            else if (ParseGroup(match, "Album", ref result))
            {
                headers.Album = result;
            }
            else if (ParseGroup(match, "Maker", ref result))
            {
                headers.FileCreator = result;
            }
            else if (ParseGroup(match, "Version", ref result))
            {
                headers.Version = result;
            }
            else if (ParseGroup(match, "Program", ref result))
            {
                headers.Program = result;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 16
0
        private bool ParseHeaderSubViewer1(Match match, ParsingProperties properties, Headers headers)
        {
            string result    = String.Empty;
            int    intResult = 0;

            if (ParseGroup(match, "Title", ref result))
            {
                headers.Title = result;
            }
            else if (ParseGroup(match, "Author", ref result))
            {
                headers.Author = result;
            }
            else if (ParseGroup(match, "Source", ref result))
            {
                headers.Source = result;
            }
            else if (ParseGroup(match, "Program", ref result))
            {
                headers.Program = result;
            }
            else if (ParseGroup(match, "FilePath", ref result))
            {
                headers.FilePath = result;
            }
            else if (ParseGroup(match, "Delay", ref intResult))
            {
                headers.Delay = intResult;
            }
            else if (ParseGroup(match, "CdTrack", ref intResult))
            {
                headers.CDTrack = intResult;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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;
   	}
Ejemplo n.º 19
0
	private void ParseEndTime (Match match, Times times, Times previousTimes, ParsingProperties properties) {
		bool isTimeDefined = false;
		TimeSpan endTime = new TimeSpan(0);

		int result = 0;
		float floatResult = 0;
		if (ParseGroup(match, "EndHours", ref result)) {
			endTime += TimeSpan.FromHours(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndMinutes", ref result)) {
			endTime += TimeSpan.FromMinutes(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndSeconds", ref result)) {
			endTime += TimeSpan.FromSeconds(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndDeciseconds", ref result)) {
			endTime += TimeSpan.FromMilliseconds(result * 100);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndCentiseconds", ref result)) {
			endTime += TimeSpan.FromMilliseconds(result * 10);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndMilliseconds", ref result)) {
			endTime += TimeSpan.FromMilliseconds(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndMillisecondsAsFrames", ref result)) {
			endTime += TimingUtil.FramesToTime(result, properties.InputFrameRate);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "EndElapsedTime", ref floatResult)) {
			endTime += times.PreciseStart + TimeSpan.FromSeconds(floatResult);
			isTimeDefined = true;
		}
		if (isTimeDefined)
			times.PreciseEnd = endTime;
	}
Ejemplo n.º 20
0
	private bool ParseHeaderKaraokeLyricsLRC (Match match, ParsingProperties properties) {
		Headers headers = properties.Headers;
		string result = String.Empty;

		if (ParseGroup(match, "Title", ref result))
			headers.Title = result;
		else if (ParseGroup(match, "Author", ref result))
			headers.MovieAuthor = result;
		else if (ParseGroup(match, "Artist", ref result))
			headers.Artist = result;
		else if (ParseGroup(match, "Album", ref result))
			headers.Album = result;
		else if (ParseGroup(match, "Maker", ref result))
			headers.Author = result;
		else if (ParseGroup(match, "Version", ref result))
			headers.Version = result;
		else if (ParseGroup(match, "Program", ref result))
			headers.Program = result;
		else {
			return false;
		}
		return true;
	}
Ejemplo n.º 21
0
	private bool ParseHeaderMPSub (Match match, ParsingProperties properties) {
		Headers headers = properties.Headers;
		string result = String.Empty;
		float floatResult = 0;

		if (ParseGroup(match, "Title", ref result))
			headers.Title = result;
		else if (ParseGroup(match, "File", ref result))
			headers.FileProperties = result;
		else if (ParseGroup(match, "Author", ref result))
			headers.Author = result;
		else if (ParseGroup(match, "MediaType", ref result))
			headers.MediaType = result;
		else if (ParseGroup(match, "Note", ref result))
			headers.Comment = result;
		//Used to detect if a subtitles' timing mode is Times in the case of a format that supports both
		else if (ParseGroup(match, "TimingModeTimes", ref result))
			properties.TimingMode = TimingMode.Times;
		//Used to detect if a subtitles' timing mode is Frames in the case of a format that supports both
		else if (ParseGroup(match, "TimingModeFrames", ref floatResult)) {
			properties.TimingMode = TimingMode.Frames;
			properties.InputFrameRate = floatResult;
		}
		else {
			return false;
		}
		return true;
	}
Ejemplo n.º 22
0
	/// <summary>Initializes a new instance of the <see cref="SubtitleProperties" />
	/// class, with defaults for all properties.</summary>
	internal SubtitleProperties (ParsingProperties properties) {
		headers = properties.Headers;
		originalFrameRate = properties.InputFrameRate;
	}
Ejemplo n.º 23
0
	private void ParseStartTime (Match match, Times times, Times previousTimes, ParsingProperties properties) {
		bool isTimeDefined = false;
		TimeSpan startTime = new TimeSpan(0);

		int result = 0;
		float floatResult = 0;
		if (ParseGroup(match, "StartHours", ref result)) {
			startTime += TimeSpan.FromHours(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartMinutes", ref result)) {
			startTime += TimeSpan.FromMinutes(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartSeconds", ref result)) {
			startTime += TimeSpan.FromSeconds(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartDeciseconds", ref result)) {
			startTime += TimeSpan.FromMilliseconds(result * 100);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartCentiseconds", ref result)) {
			startTime += TimeSpan.FromMilliseconds(result * 10);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartMilliseconds", ref result)) {
			startTime += TimeSpan.FromMilliseconds(result);
			isTimeDefined = true;
		}
		if (ParseGroup(match, "StartMillisecondsAsFrames", ref result)) {
			startTime += TimingUtil.FramesToTime(result, properties.InputFrameRate);
			isTimeDefined = true;
		}

		if (ParseGroup(match, "StartElapsedTime", ref floatResult)) {
			if (previousTimes != null)
				startTime += previousTimes.PreciseEnd;

			startTime += TimeSpan.FromSeconds(floatResult);
			isTimeDefined = true;
		}
		if (isTimeDefined)
			times.PreciseStart = startTime;
	}
Ejemplo n.º 24
0
	private bool ParseHeaderSubViewer1 (Match match, ParsingProperties properties, Headers headers) {
		string result = String.Empty;

		if (ParseGroup(match, "Title", ref result))
			headers.Title = result;
		else if (ParseGroup(match, "Author", ref result))
			headers.Author = result;
		else if (ParseGroup(match, "Source", ref result))
			headers.VideoSource = result;
		else if (ParseGroup(match, "Program", ref result))
			headers.Program = result;
		else if (ParseGroup(match, "FilePath", ref result))
			headers.SubtitlesSource = result;
		else if (ParseGroup(match, "Delay", ref result))
			headers.DelayAsText = result;
		else if (ParseGroup(match, "CdTrack", ref result))
			headers.CDTrackAsText = result;
		else {
			return false;
		}
		return true;
	}
Ejemplo n.º 25
0
	private bool ParseHeaderKaraokeLyricsVKT (Match match, ParsingProperties properties) {
		Headers headers = properties.Headers;
		string result = String.Empty;

		if (ParseGroup(match, "FrameRate", ref result))
			headers.FrameRate = result;
		else if (ParseGroup(match, "Author", ref result))
			headers.Author = result;
		else if (ParseGroup(match, "Source", ref result))
			headers.VideoSource = result;
		else if (ParseGroup(match, "Date", ref result))
			headers.Date = result;
		else {
			return false;
		}
		return true;
	}
Ejemplo n.º 26
0
	private Subtitle ParseSubtitle (Match match, SubtitleFormat format, ParsingProperties properties, Subtitle previousSubtitle){
		SubtitleText text = ParseSubtitleText(match, format);
		Style style = ParseStyle(match, format);

		Subtitle subtitle = new Subtitle(null, text, style);

		if (properties.TimingMode == TimingMode.Frames) {
			Frames previousFrames = (previousSubtitle == null ? null : previousSubtitle.Frames);
			ParseFrames(match, subtitle.Frames, previousFrames);
		}
		else {
			Times previousTimes = (previousSubtitle == null ? null : previousSubtitle.Times);
			ParseTimes(match, subtitle.Times, previousTimes, properties);
		}

		format.SubtitleInputPostProcess(subtitle);
		return subtitle;
	}
Ejemplo n.º 27
0
	private bool ParseHeaderSubViewer1 (Match match, ParsingProperties properties) {
		return ParseHeaderSubViewer1(match, properties, properties.Headers);
	}
Ejemplo n.º 28
0
 private void ParseTimes(Match match, Times times, Times previousTimes, ParsingProperties properties)
 {
     ParseStartTime(match, times, previousTimes, properties);
     ParseEndTime(match, times, previousTimes, properties);
 }
Ejemplo n.º 29
0
 private bool ParseHeaderSubViewer1(Match match, ParsingProperties properties)
 {
     return(ParseHeaderSubViewer1(match, properties, properties.Headers));
 }
Ejemplo n.º 30
0
	private bool ParseHeaderSubViewer2 (Match match, ParsingProperties properties) {
		Headers headers = properties.Headers;
		string result = String.Empty;

		if (!ParseHeaderSubViewer1(match, properties, headers)) {
			if (ParseGroup(match, "Comment", ref result))
				headers.Comment = result;
			else if (ParseGroup(match, "FontName", ref result))
				headers.FontName = result;
			else if (ParseGroup(match, "FontColor", ref result))
				headers.FontColor = result;
			else if (ParseGroup(match, "FontStyle", ref result))
				headers.FontStyle = result;
			else if (ParseGroup(match, "FontSize", ref result))
				headers.FontSizeAsText = result;
			else
				return false;
		}
		return true;
	}
Ejemplo n.º 31
0
	private bool ParseHeaderSubStationAlphaAAS (Match match, ParsingProperties properties) {
		Headers headers = properties.Headers;
		string result = String.Empty;
		int intResult = 0;

		if (ParseGroup(match, "Title", ref result))
			headers.Title = result;
		else if (ParseGroup(match, "OriginalScript", ref result))
			headers.OriginalScript = result;
		else if (ParseGroup(match, "OriginalTranslation", ref result))
			headers.OriginalTranslation = result;
		else if (ParseGroup(match, "OriginalEditing", ref result))
			headers.OriginalEditing = result;
		else if (ParseGroup(match, "OriginalTiming", ref result))
			headers.OriginalTiming = result;
		else if (ParseGroup(match, "OriginalScriptChecking", ref result))
			headers.OriginalScriptChecking = result;
		else if (ParseGroup(match, "ScriptUpdatedBy", ref result))
			headers.ScriptUpdatedBy = result;
		else if (ParseGroup(match, "Collisions", ref result))
			headers.Collisions = result;
		else if (ParseGroup(match, "PlayResX", ref intResult))
			headers.PlayResX = intResult;
		else if (ParseGroup(match, "PlayResY", ref intResult))
			headers.PlayResY = intResult;
		else if (ParseGroup(match, "PlayDepth", ref intResult))
			headers.PlayDepth = intResult;
		else if (ParseGroup(match, "Timer", ref result))
			headers.Timer = result;
		else {
			return false;
		}
		return true;
	}
	internal override void GlobalInputGetProperties (string text, ParsingProperties properties) {
		bool isFrameRatePAL = inputRegexPAL.Match(text).Success;
		float frameRate = (isFrameRatePAL ? 25 : 29.97F);
		properties.InputFrameRate = frameRate;
	}
Ejemplo n.º 33
0
	private void ParseTimes (Match match, Times times, Times previousTimes, ParsingProperties properties) {
		ParseStartTime(match, times, previousTimes, properties);
		ParseEndTime(match, times, previousTimes, properties);
	}
Ejemplo n.º 34
0
	internal virtual void GlobalInputGetProperties (string text, ParsingProperties properties) {
		return;
	}
Ejemplo n.º 35
0
	/// <returns>The index where subtitles start.</returns>
	private int ReadHeaders (string text, int bodyIndex, SubtitleFormat format, ParsingProperties properties) {
		if (!(format.HasHeaders && (bodyIndex > 0)))
			return 0;

		ParseHeaderDelegate headerParser = GetHeaderParser(format.Type);

		int lastIndex = 0; //the last index with header text
		string headerText = text.Substring(0, bodyIndex);
		foreach (string headerExpression in format.Headers) {
			Regex expression = new Regex(headerExpression, RegexOptions.IgnoreCase);
			Match match = expression.Match(headerText, 0, bodyIndex);
			if (match.Success) {
				/* Update the last index based on the header match */
				int matchLastIndex = match.Index + match.Length;
				if (matchLastIndex > lastIndex)
					lastIndex = matchLastIndex;

				headerParser(match, properties);
			}
		}
		return lastIndex;
	}