Пример #1
0
        /// <summary>
        /// Gets a value indicating wether this FileSystemInfo object is located on a optical drive.
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static bool IsOpticalPath(this FileSystemInfo self)
        {
            DriveInfo driveInfo = self.GetDriveInfo();

            return(driveInfo != null && driveInfo.IsOptical());
        }
Пример #2
0
    public MediaInfoWrapper(string strFile) {
        if (strFile == null)
            return;

        bool isTV = Util.Utils.IsLiveTv(strFile);
        bool isRadio = Util.Utils.IsLiveRadio(strFile);
        bool isDVD = Util.Utils.IsDVD(strFile);
        bool isVideo = Util.Utils.IsVideo(strFile);
        bool isAVStream = Util.Utils.IsAVStream(strFile); //rtsp users for live TV and recordings.

        if (isTV || isRadio || isAVStream) {
            return;
        }

        try {
            _mI = new MediaInfo();
            _mI.Open(strFile);

            FileInfo fileInfo = strFile.PathToFileInfo();
            DriveInfo driveInfo = fileInfo.GetDriveInfo();

            if (strFile.ToLower().EndsWith(".ifo") && driveInfo != null && driveInfo.IsOptical())  {
                // mediainfo is not able to obtain duration of IFO files
                // so we use this to loop through all corresponding VOBs and add up the duration
                // we do not do this for optical drives because there are issues with some discs
                // taking more than 2 minutes(copy protection?)
                _duration = 0;
                string filePrefix = Path.GetFileName(strFile);
                filePrefix = filePrefix.Substring(0, filePrefix.LastIndexOf('_'));
                MediaInfo mi = new MediaInfo();
                foreach (string file in Directory.GetFiles(Path.GetDirectoryName(strFile), filePrefix + "*.VOB")) {
                    mi.Open(file);
                    int durationPart = 0;
                    int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out durationPart);
                    _duration += durationPart;
                }
            }
            else if (strFile.ToLowerInvariant().EndsWith(".bdmv") || strFile.ToLowerInvariant().EndsWith(".m2ts")) {
                bool result = GetLengthFromPlaylist(strFile);
                if (!result) {
                    //_duration = (int) currentPlaylistFile.TotalLength;
                    int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out _duration);
                }
            }
            else {
                int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out _duration);
            }

            NumberFormatInfo providerNumber = new NumberFormatInfo();
            providerNumber.NumberDecimalSeparator = ".";

            double.TryParse(_mI.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, providerNumber, out _framerate);
            _videoCodec = _mI.Get(StreamKind.Video, 0, "Codec").ToLower();
            _scanType = _mI.Get(StreamKind.Video, 0, "ScanType").ToLower();
            int.TryParse(_mI.Get(StreamKind.Video, 0, "Width"), out _width);
            int.TryParse(_mI.Get(StreamKind.Video, 0, "Height"), out _height);
            int.TryParse(_mI.Get(StreamKind.Video, 0, "BitRate"), out _videoBitRate);
            int.TryParse(_mI.Get(StreamKind.Video, 0, "MultiView_Count"), out _multiViewCount);
            int.TryParse(_mI.Get(StreamKind.General, 0, "TextCount"), out _numSubtitles);

            int intValue;
            int iAudioStreams = _mI.Count_Get(StreamKind.Audio);
            for (int i = 0; i < iAudioStreams; i++) {
                string sChannels = Regex.Split(_mI.Get(StreamKind.Audio, i, "Channel(s)"), @"\D+").Max();

                if (int.TryParse(sChannels, out intValue) && intValue > _audioChannels) {
                    _audioChannels = intValue;
                    int.TryParse(_mI.Get(StreamKind.Audio, i, "SamplingRate"), out _audioSampleRate);
                    int.TryParse(_mI.Get(StreamKind.Audio, i, "BitRate"), out _audioBitRate);
                    _audioCodec = _mI.Get(StreamKind.Audio, i, "Codec/String").ToLower();
                    _audioFormatProfile = _mI.Get(StreamKind.Audio, i, "Format_Profile").ToLower();
                }
            }

            string aspectStr = _mI.Get(StreamKind.Video, 0, "AspectRatio/String");
            if (aspectStr == "4/3" || aspectStr == "4:3")
                _aspectRatio = "fullscreen";
            else
                _aspectRatio = "widescreen";

            _isInterlaced = (_scanType.IndexOf("interlaced") > -1);

            if (_height >= 720) {
                _isHDTV = true;
            }
            else {
                _isSDTV = true;
            }

            if ((_width == 1280 || _height == 720) && !_isInterlaced) {
                _is720P = true;
            }

            if ((_width == 1920 || _height == 1080) && !_isInterlaced) {
                _is1080P = true;
            }

            if ((_width == 1920 || _height == 1080) && _isInterlaced) {
                _is1080I = true;
            }

            if ((_width == 640 || _height == 480) && !_isInterlaced) {
                _is480P = true;
            }

            if ((_width == 640 || _height == 480) && _isInterlaced) {
                _is480I = true;
            }

            if ((_width == 720 || _width == 704 || _height == 576) && !_isInterlaced) {
                _is576P = true;
            }

            if ((_width == 720 || _width == 704 || _height == 576) && _isInterlaced) {
                _is576I = true;
            }

            if (_width == 3840 || _height == 2160) {
                _is2160P = true;
            }

            if (_width == 7680 || _height == 4320) {
                _is4320P = true;
            }

            _isDIVX = (_videoCodec.IndexOf("dx50") > -1) | (_videoCodec.IndexOf("div3") > -1); // DivX 5 and DivX 3
            _isXVID = (_videoCodec.IndexOf("xvid") > -1);
            _isH264 = (_videoCodec.IndexOf("avc") > -1 || _videoCodec.IndexOf("h264") > -1);
            _isMP1V = (_videoCodec.IndexOf("mpeg-1v") > -1);
            _isMP2V = (_videoCodec.IndexOf("mpeg-2v") > -1);
            _isMP4V = (_videoCodec.IndexOf("fmp4") > -1); // add more
            _isWMV = (_videoCodec.IndexOf("wmv") > -1); // wmv3 = WMV9
            // missing cvid etc
            _isAC3 = (System.Text.RegularExpressions.Regex.IsMatch(_audioCodec, "ac-?3"));
            _isMP3 = (_audioCodec.IndexOf("mpeg-1 audio layer 3") > -1) || (_audioCodec.IndexOf("mpeg-2 audio layer 3") > -1);
            _isMP2A = (_audioCodec.IndexOf("mpeg-1 audio layer 2") > -1);
            _isDTS = (_audioCodec.IndexOf("dts") > -1);
            _isOGG = (_audioCodec.IndexOf("ogg") > -1);
            _isAAC = (_audioCodec.IndexOf("aac") > -1);
            _isWMA = (_audioCodec.IndexOf("wma") > -1); // e.g. wma3
            _isPCM = (_audioCodec.IndexOf("pcm") > -1);
            _isTrueHD = (_audioCodec.Contains("truehd") || _audioFormatProfile.Contains("truehd"));
            _isDTSHD = (_audioCodec.Contains("dts") && (_audioFormatProfile.Contains("hra") || _audioFormatProfile.Contains("ma")));

            _is3D = (_multiViewCount > 1);

            if (checkHasExternalSubtitles(strFile)) {
                _hasSubtitles = true;
            }
            else if (_numSubtitles > 0) {
                _hasSubtitles = true;
            }
            else {
                _hasSubtitles = false;
            }

            _fileSize = fileInfo.Length;

            logger.Debug("MediaInfoWrapper: InspectingMedia: {0}", strFile);
            logger.Debug("MediaInfoWrapper: FrameRate: {0}", _framerate);
            logger.Debug("MediaInfoWrapper: VideoBitRate: {0}", _videoBitRate);
            logger.Debug("MediaInfoWrapper: VideoCodec: {0}", _videoCodec);
            if (_isDIVX)
                logger.Debug("MediaInfoWrapper: IsDIVX: {0}", _isDIVX);
            if (_isXVID)
                logger.Debug("MediaInfoWrapper: IsXVID: {0}", _isXVID);
            if (_isH264)
                logger.Debug("MediaInfoWrapper: IsH264: {0}", _isH264);
            if (_isMP1V)
                logger.Debug("MediaInfoWrapper: IsMP1V: {0}", _isMP1V);
            if (_isMP2V)
                logger.Debug("MediaInfoWrapper: IsMP2V: {0}", _isMP2V);
            if (_isMP4V)
                logger.Debug("MediaInfoWrapper: IsMP4V: {0}", _isMP4V);
            if (_isWMV)
                logger.Debug("MediaInfoWrapper: IsWMV: {0}", _isWMV);

            logger.Debug("MediaInfoWrapper: HasSubtitles: {0}", _hasSubtitles);
            logger.Debug("MediaInfoWrapper: NumSubtitles: {0}", _numSubtitles);
            logger.Debug("MediaInfoWrapper: Is3D: {0}", _is3D);
            logger.Debug("MediaInfoWrapper: MultiViewCount: {0}", _multiViewCount);
            logger.Debug("MediaInfoWrapper: ScanType: {0}", _scanType);
            logger.Debug("MediaInfoWrapper: IsInterlaced: {0}", _isInterlaced);
            logger.Debug("MediaInfoWrapper: Width: {0}", _width);
            logger.Debug("MediaInfoWrapper: Height: {0}", _height);
            logger.Debug("MediaInfoWrapper: Audiochannels: {0}", _audioChannels);
            logger.Debug("MediaInfoWrapper: AudioBitRate: {0}", _audioBitRate);
            logger.Debug("MediaInfoWrapper: AudioSampleRate: {0}", _audioSampleRate);
            logger.Debug("MediaInfoWrapper: AspectRatio: {0}", _aspectRatio);
            logger.Debug("MediaInfoWrapper: AudioCodec: {0}", _audioCodec);
            if (_isAC3)
                logger.Debug("MediaInfoWrapper: IsAC3: {0}", _isAC3);
            if (_isMP3)
                logger.Debug("MediaInfoWrapper: IsMP3: {0}", _isMP3);
            if (_isMP2A)
                logger.Debug("MediaInfoWrapper: IsMP2A: {0}", _isMP2A);
            if (_isDTS)
                logger.Debug("MediaInfoWrapper: IsDTS: {0}", _isDTS);
            if (_isTrueHD)
                logger.Debug("MediaInfoWrapper: IsTrueHD: {0}", _isTrueHD);
            if (_isDTSHD)
                logger.Debug("MediaInfoWrapper: IsDTSHD: {0}", _isDTSHD);
            if (_isOGG)
                logger.Debug("MediaInfoWrapper: IsOGG: {0}", _isOGG);
            if (_isAAC)
                logger.Debug("MediaInfoWrapper: IsAAC: {0}", _isAAC);
            if (_isWMA)
                logger.Debug("MediaInfoWrapper: IsWMA: {0}", _isWMA);
            if (_isPCM)
                logger.Debug("MediaInfoWrapper: IsPCM: {0}", _isPCM);

            logger.Debug("MediaInfoWrapper: FileSize: {0}", _fileSize);
        }
        catch (Exception ex) {
            logger.Error("MediaInfo processing failed ('MediaInfo.dll' may be missing): {0}", ex.Message);
        }
        finally {
            if (_mI != null) {
                _mI.Close();
            }
        }
    }
Пример #3
0
        public static bool IsOpticalDrive(string path)
        {
            DriveInfo driveInfo = DeviceManager.GetDriveInfo(path);

            return(driveInfo != null && driveInfo.IsOptical());
        }