Beispiel #1
0
        public void Prepare(string path, ContextObject context)
        {
            _context = context;

            try
            {
                _mediaInfo = new MediaInfo.MediaInfo(Path.Combine(
                                                         Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                         Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
                _mediaInfo.Option("Cover_Data", "base64");

                _mediaInfo.Open(path);
            }
            catch (Exception)
            {
                _mediaInfo?.Dispose();
                _mediaInfo = null;
            }

            context.TitlebarOverlap = true;

            if (_mediaInfo == null ||
                !string.IsNullOrWhiteSpace(_mediaInfo.Get(StreamKind.General, 0, "VideoCount"))) // video
            {
                int.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Width"), out var width);
                int.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Height"), out var height);
                double.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
                // Correct rotation: on some machine the value "90" becomes "90000" by some reason
                if (rotation > 360)
                {
                    rotation /= 1e3;
                }

                var windowSize = new Size
                {
                    Width  = Math.Max(100, width == 0 ? 1366 : width),
                    Height = Math.Max(100, height == 0 ? 768 : height)
                };

                if (rotation % 180 != 0)
                {
                    windowSize = new Size(windowSize.Height, windowSize.Width);
                }

                context.SetPreferredSizeFit(windowSize, 0.8);

                context.TitlebarAutoHide       = true;
                context.Theme                  = Themes.Dark;
                context.TitlebarBlurVisibility = true;
            }
            else // audio
            {
                context.PreferredSize = new Size(500, 300);

                context.CanResize                = false;
                context.TitlebarAutoHide         = false;
                context.TitlebarBlurVisibility   = false;
                context.TitlebarColourVisibility = false;
            }
        }
Beispiel #2
0
        private static bool HasMatroskaChapter(TaskDetail task)
        {
            FileInfo inputFile = new FileInfo(task.InputFile);

            if (inputFile.Extension.ToLower() != ".mkv")
            {
                Logger.Warn($"{task.InputFile}不是Matroska文件。");
                return(false);
            }

            MediaInfo.MediaInfo MI = new MediaInfo.MediaInfo();
            MI.Open(inputFile.FullName);
            MI.Option("Complete");
            int.TryParse(MI.Get(StreamKind.General, 0, "MenuCount"), out var MenuCount);

            if (MenuCount == 0)
            {
                Logger.Warn($"{task.InputFile}内不含有章节。");
                MI?.Close();
                return(false);
            }

            MI?.Close();
            return(true);
        }
Beispiel #3
0
        public static Dictionary <String, String> Info(String uri)
        {
            Dictionary <String, String> info = new Dictionary <String, String>();

            String fileName = Path.GetFileName(uri);

            /// Get Media Info
            MediaInfo.MediaInfo MI = new MediaInfo.MediaInfo();
            MI.Open(uri);
            String artist     = MI.Get(StreamKind.General, 0, "Performer");
            String trackName  = MI.Get(StreamKind.General, 0, "Title");
            String duration   = MI.Get(StreamKind.Audio, 0, "Duration");
            String fileLength = MI.Get(0, 0, "FileSize");
            String bitrate    = MI.Get(StreamKind.Audio, 0, "BitRate");

            info.Add("FileName", fileName);
            info.Add("Artist", artist);
            info.Add("Title", trackName);
            info.Add("Duration", duration);
            info.Add("FileLength", fileLength);
            info.Add("Bitrate", bitrate);

            MI.Close();

            return(info);
        }
Beispiel #4
0
 static Plugin()
 {
     _mediaInfo = new MediaInfo.MediaInfo(Path.Combine(
                                              Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                              Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
     _mediaInfo.Option("Cover_Data", "base64");
 }
Beispiel #5
0
        public void Cleanup()
        {
            _vp?.Dispose();
            _vp = null;

            _mediaInfo?.Dispose();
            _mediaInfo = null;

            _context = null;
        }
        public DateTime GetOriginalCreationDateTime(string filePath)
        {
            DateTime creationDateTime;

            using (var mediaInfo = new MediaInfo.MediaInfo())
            {
                mediaInfo.Open(filePath);
                var rawValue   = mediaInfo.Get(StreamKind.Video, 0, "Encoded_Date");
                var dateString = rawValue.Replace("UTC", string.Empty);
                creationDateTime = DateTime.TryParse(dateString, null, DateTimeStyles.AssumeUniversal, out DateTime dateTime) ? dateTime : DateTime.Now;
            }

            return(creationDateTime);
        }
 public static string Scan(string MediaPath, MediaInfoScanType ScanType = MediaInfoScanType.Full)
 {
     try
     {
         //MediaInfoWrapper mediaInfoWrapper = new MediaInfoWrapper(MediaPath);
         using (var mediaInfo = new MediaInfo.MediaInfo(DllPath)) //MediaInfo Dll
         {
             mediaInfo.Open(MediaPath);
             if (ScanType == MediaInfoScanType.Full)
             {
                 mediaInfo.Option("Complete");
             }
             return(mediaInfo.Inform());
         }
     }
     catch (Exception ex)
     {
         return("");
     }
 }
        private void ExtractInfo(string filePath, NumberFormatInfo providerNumber)
#endif
        {
#if (NET40 || NET45)
            using (var mediaInfo = new MediaInfo(pathToDll))
#else
            using (var mediaInfo = new MediaInfo())
#endif
            {
                if (mediaInfo.Handle == IntPtr.Zero)
                {
                    MediaInfoNotloaded = true;
                    _logger.LogWarning("MediaInfo library was not loaded!");
                    return;
                }
                else
                {
                    Version = mediaInfo.Option("Info_Version");
                    _logger.LogDebug($"MediaInfo library was loaded. Handle={mediaInfo.Handle} Version is {Version}");
                }

                var filePricessingHandle = mediaInfo.Open(filePath);
                if (filePricessingHandle == IntPtr.Zero)
                {
                    MediaInfoNotloaded = true;
                    _logger.LogWarning($"MediaInfo library has not been opened media {filePath}");
                    return;
                }
                else
                {
                    _logger.LogDebug($"MediaInfo library successfully opened {filePath}. Handle={filePricessingHandle}");
                }

                var streamNumber = 0;

                Tags = new AudioTagBuilder(mediaInfo, 0).Build();

                // Setup videos
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Video); ++i)
                {
                    VideoStreams.Add(new VideoStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                if (Duration == 0)
                {
                    double.TryParse(
                        mediaInfo.Get(StreamKind.Video, 0, (int)NativeMethods.Video.Video_Duration),
                        NumberStyles.AllowDecimalPoint,
                        providerNumber,
                        out var duration);
                    Duration = (int)duration;
                }

                // Fix 3D for some containers
                if (VideoStreams.Count == 1 && Tags.GeneralTags.TryGetValue((NativeMethods.General) 1000, out var isStereo))
                {
                    var video = VideoStreams.First();
                    if (Tags.GeneralTags.TryGetValue((NativeMethods.General) 1001, out var stereoMode))
                    {
                        video.Stereoscopic = (StereoMode)stereoMode;
                    }
                    else
                    {
                        video.Stereoscopic = (bool)isStereo ? StereoMode.Stereo : StereoMode.Mono;
                    }
                }

                // Setup audios
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Audio); ++i)
                {
                    AudioStreams.Add(new AudioStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                if (Duration == 0)
                {
                    double.TryParse(
                        mediaInfo.Get(StreamKind.Audio, 0, (int)NativeMethods.Audio.Audio_Duration),
                        NumberStyles.AllowDecimalPoint,
                        providerNumber,
                        out var duration);
                    Duration = (int)duration;
                }

                // Setup subtitles
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Text); ++i)
                {
                    Subtitles.Add(new SubtitleStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                // Setup chapters
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Other); ++i)
                {
                    Chapters.Add(new ChapterStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                // Setup menus
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Menu); ++i)
                {
                    MenuStreams.Add(new MenuStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                MediaInfoNotloaded = VideoStreams.Count == 0 && AudioStreams.Count == 0 && Subtitles.Count == 0;

                // Produce capability properties
                if (MediaInfoNotloaded)
                {
                    SetPropertiesDefault();
                }
                else
                {
                    SetupProperties(mediaInfo);
                }
            }
        }
Beispiel #9
0
        private void ExtractInfo(string filePath, string pathToDll, NumberFormatInfo providerNumber)
        {
            using (var mediaInfo = new MediaInfo(pathToDll))
            {
                Version = mediaInfo.Option("Info_Version");
                mediaInfo.Open(filePath);

                var streamNumber = 0;

                Tags = TagHelper.GetAllTags <AudioTags>(mediaInfo, StreamKind.General, 0);

                // Setup videos
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Video); ++i)
                {
                    VideoStreams.Add(new VideoStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                if (Duration == 0)
                {
                    double duration;
                    double.TryParse(
                        mediaInfo.Get(StreamKind.Video, 0, "Duration"),
                        NumberStyles.AllowDecimalPoint,
                        providerNumber,
                        out duration);
                    Duration = (int)duration;
                }

                // Setup audios
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Audio); ++i)
                {
                    AudioStreams.Add(new AudioStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                // Setup subtitles
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Text); ++i)
                {
                    Subtitles.Add(new SubtitleStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                // Setup chapters
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Other); ++i)
                {
                    Chapters.Add(new ChapterStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                // Setup menus
                for (var i = 0; i < mediaInfo.CountGet(StreamKind.Menu); ++i)
                {
                    MenuStreams.Add(new MenuStreamBuilder(mediaInfo, streamNumber++, i).Build());
                }

                MediaInfoNotloaded = VideoStreams.Count == 0 && AudioStreams.Count == 0 && Subtitles.Count == 0;

                // Produce copability properties
                if (MediaInfoNotloaded)
                {
                    SetPropertiesDefault();
                }
                else
                {
                    SetupProperties(mediaInfo);
                }
            }
        }
Beispiel #10
0
        public int Priority => - 3; // make it lower than TextViewer

        static Plugin()
        {
            _mediaInfo = new MediaInfo.MediaInfo(Assembly.GetExecutingAssembly().Location);
            _mediaInfo.Option("Cover_Data", "base64");
        }
        private void PrepareMediaInfo(bool appendInfo)
        {
            if (this.IsMediaInfoAvailable)
            {
                return;
            }

            if (System.IO.File.Exists(this.File) == false)
            {
                return;
            }

            using (var objMediaInfo = new MediaInfo())
            {
                objMediaInfo.Open(this.File);

                try
                {
                    this.MediaInfoText = objMediaInfo.Inform().Trim();

                    var generalStream = new Streams.GeneralStream();
                    var allStreams    = new List <Streams.IStreamBase>();

                    IEnumerable <string> streams = null;
                    string[]             lines   = null;

                    streams = this.MediaInfoText.Split(Environment.NewLine + Environment.NewLine);

                    var streamIndex = -1;

                    foreach (var stream in streams)
                    {
                        Streams.StreamBase currentStream = null;
                        lines = stream.Split(Environment.NewLine);
                        var firstLine = lines[0];

                        if (!string.IsNullOrEmpty(firstLine))
                        {
                            if (firstLine.Contains("General"))
                            {
                                currentStream = generalStream = new Streams.GeneralStream();
                                //MediaInfo cannot read Avisynth files, so add format manually
                                if (Extension == ".avs")
                                {
                                    currentStream.Properties.Add("Format", "Avisynth Script");
                                }
                            }
                            else if (firstLine.Contains("Audio"))
                            {
                                currentStream = new Streams.AudioStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                            else if (firstLine.Contains("Video"))
                            {
                                currentStream = new Streams.VideoStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                            else if (firstLine.Contains("Text"))
                            {
                                currentStream = new Streams.TextStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                            else if (firstLine.Contains("Image"))
                            {
                                currentStream = new Streams.ImageStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                            else if (firstLine.Contains("Menu"))
                            {
                                currentStream = new Streams.MenuStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                            else if (firstLine.Contains("Chapters"))
                            {
                                currentStream = new Streams.ChaptersStream();
                                allStreams.Add(currentStream);
                                currentStream.StreamIndex = ++streamIndex;
                            }
                        }

                        if (currentStream != null)
                        {
                            //get properties
                            foreach (var line in lines)
                            {
                                var property = line.Split(" : ");
                                if (property.Length > 1)
                                {
                                    var propertyName  = property[0].Trim();
                                    var propertyValue = property[1].Trim();
                                    if (!currentStream.Properties.ContainsKey(propertyName))
                                    {
                                        currentStream.Properties.Add(propertyName, propertyValue);
                                    }
                                }
                            }
                        }
                    }

                    foreach (var stream in allStreams)
                    {
                        stream.SourceFile = this;
                    }

                    //fix stream order using ID property ------------------------------------

                    var flag = true;
                    Streams.IStreamBase tempStream;

                    //bubble-sort the streams using the ID number

                    for (var pass = 1; (pass <= allStreams.Count) && flag; pass++) // N passes
                    {
                        flag = false;

                        for (var comp = 0; comp <= allStreams.Count - 2; comp++) // N-1 comparisons
                        {
                            if (allStreams[comp].Id != -1 & allStreams[comp + 1].Id != -1)
                            {
                                if (allStreams[comp].Id > allStreams[comp + 1].Id)
                                {
                                    tempStream           = allStreams[comp];
                                    allStreams[comp]     = allStreams[comp + 1];
                                    allStreams[comp + 1] = tempStream;
                                    flag = true;
                                }
                            }
                        }
                    }

                    foreach (var stream in allStreams)
                    {
                        stream.StreamIndex = AllStreams.IndexOf(stream);
                    }

                    SetStreamTypeIndices(allStreams);

                    //--finished fixing stream order ---------------------------------------

                    this.IsMediaInfoAvailable = true;
                    this.MediaInfoHtml        = GetInfoHtml(generalStream, allStreams);

                    if (appendInfo)
                    {
                        AddProperties(generalStream, allStreams, true);
                    }
                }
                finally
                {
                    objMediaInfo.Close();
                }
            }
        }