Пример #1
0
        private Ratio CalculateFramerate()
        {
            Maybe <string> rawTrackTextMaybe = from track in _videoTrack.Value
                                               select track.Framerate;

            Maybe <Ratio> fpsFromParenthesis = from framerateText in rawTrackTextMaybe
                                               let startParenths = framerateText.IndexOf("(")
                                                                   let endParenths = framerateText.IndexOf(")")
                                                                                     where startParenths != -1 && endParenths != -1
                                                                                     let fpsSubstring = framerateText.Substring(startParenths + 1, endParenths - startParenths - 1)
                                                                                                        let splitOnSlash = fpsSubstring.Split('/')
                                                                                                                           where splitOnSlash.Length == 2
                                                                                                                           let numerator = NumericUtils.TryParseInt(splitOnSlash[0])
                                                                                                                                           let denominator = NumericUtils.TryParseInt(splitOnSlash[1])
                                                                                                                                                             where numerator != null && denominator != null
                                                                                                                                                             select new Ratio(numerator.Value, denominator.Value);

            Maybe <Ratio> fpsFromDirectParse = from framerateText in rawTrackTextMaybe
                                               let indexOfFpsMarker = framerateText.IndexOf("fps", StringComparison.OrdinalIgnoreCase)
                                                                      where indexOfFpsMarker != -1
                                                                      let fpsAsDecimal = framerateText.Substring(0, indexOfFpsMarker - 2)
                                                                                         let fpsAsDouble = NumericUtils.TryParseDouble(fpsAsDecimal)
                                                                                                           where fpsAsDouble != null
                                                                                                           select NumericUtils.ConvertDoubleToFPS(fpsAsDouble.Value);

            return(fpsFromParenthesis.Or(fpsFromDirectParse).OrElse(new Ratio()));
        }