示例#1
0
文件: Info.cs 项目: asfdfdfd/AniDB
        private static void CreateChaptersMIL(XmlDocument xmlDoc, XmlNode chaptersNode, IMediaInfo mediaInfo)
        {
            Func <string, string, XmlNode> createNode = (name, value) => {
                var n = xmlDoc.CreateElement(name);
                if (value != null)
                {
                    n.AppendChild(xmlDoc.CreateTextNode(value));
                }
                return(n);
            };

            XmlNode     editionEntryNode, chapterAtomNode, chapterDisplayNode;
            eStreamType streamKind = eStreamType.Menu;
            int         streamCount, entryCount;

            streamCount = mediaInfo.Count_Get(streamKind);

            for (int i = 0; i < streamCount; i++)
            {
                entryCount       = mediaInfo.Count_Get(streamKind, i);
                editionEntryNode = chaptersNode.AppendChild(xmlDoc.CreateElement("EditionEntry"));

                int indexStart, indexEnd;
                if (int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_Begin"), out indexStart) && int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_End"), out indexEnd))
                {
                    chapterAtomNode = editionEntryNode.AppendChild(xmlDoc.CreateElement("ChapterAtom"));
                    for (; indexStart < indexEnd; indexStart++)
                    {
                        Func <string, ulong> conv = (str) => {
                            var timeParts = str.Split(new char[] { ':', '.' }).Select(s => ulong.Parse(s.Trim())).ToArray();
                            return((((timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]) * 1000 + timeParts[3]) * 1000000);
                        };

                        var   timeStamps     = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Name).Split('-');
                        ulong timestampStart = conv(timeStamps[0].Trim());
                        ulong timestampEnd;
                        if (timeStamps.Length > 1)
                        {
                            timestampEnd = conv(timeStamps[1].Trim());
                        }


                        chapterAtomNode.AppendChild(createNode("ChapterTimeStart", timestampStart.ToString()));
                        chapterDisplayNode = chapterAtomNode.AppendChild(xmlDoc.CreateElement("ChapterDisplay"));

                        string languageTitle, language, title;
                        languageTitle = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Text);
                        language      = languageTitle.Contains(':') ? languageTitle.Substring(0, languageTitle.IndexOf(':')) : null;
                        title         = languageTitle.Substring(language == null ? 0 : language.Length + 1);
                        chapterDisplayNode.AppendChild(createNode("ChapterString", title));
                        if (language != null)
                        {
                            chapterDisplayNode.AppendChild(createNode("ChapterLanguage", language.Equals("en") ? "eng" : language));
                        }
                    }
                }
            }
        }
示例#2
0
文件: Info.cs 项目: asfdfdfd/AniDB
        private static void CreateChaptersNode(XmlDocument xmlDoc, XmlNode n, IMediaInfo mediaInfo)
        {
            Func <string, ulong> conv = (str) => {
                var timeParts = str.Split(new char[] { ':', '.' }).Select(s => ulong.Parse(s.Trim())).ToArray();
                return((((timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]) * 1000 + timeParts[3]) * 1000000);
            };

            int         streamCount, entryCount;
            eStreamType streamKind = eStreamType.Menu;
            XmlNode     entryNode, subNode;
            string      languageTitle, language, title;

            streamCount = mediaInfo.Count_Get(streamKind);
            for (int i = 0; i < streamCount; i++)
            {
                entryCount = mediaInfo.Count_Get(streamKind, i);
                int indexStart, indexEnd;
                if (int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_Begin"), out indexStart) && int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_End"), out indexEnd))
                {
                    for (; indexStart < indexEnd; indexStart++)
                    {
                        entryNode = n.AppendChild(xmlDoc.CreateElement("Entry"));

                        var timeStamp = conv(mediaInfo.Get(streamKind, i, indexStart, eInfoType.Name).Split('-')[0].Trim());
                        subNode = entryNode.AppendChild(xmlDoc.CreateElement("Pos"));
                        subNode.Attributes.Append(xmlDoc.CreateAttribute("start")).Value = (timeStamp / 1000).ToString("0.###");

                        languageTitle = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Text);
                        language      = languageTitle.Contains(':') ? languageTitle.Substring(0, languageTitle.IndexOf(':')) : null;
                        title         = languageTitle.Substring(language == null ? 0 : language.Length + 1);

                        subNode = entryNode.AppendChild(xmlDoc.CreateElement("Title"));
                        subNode.AppendChild(xmlDoc.CreateTextNode(title));
                        if (language != null)
                        {
                            subNode.Attributes.Append(xmlDoc.CreateAttribute("lang")).Value = language;
                        }
                    }
                }
            }
        }
示例#3
0
文件: Info.cs 项目: asfdfdfd/AniDB
        public static XmlDocument CreateMediaInfoXMLLog(string filePath, IEnumerable <IBlockConsumer> blockConsumers)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode     node, subNode;

            IMediaInfo mediaInfo = CreateMediaInfoInstance();

            mediaInfo.Open(filePath);

            node    = xmlDoc.AppendChild(xmlDoc.CreateElement("File"));
            subNode = node.AppendChild(xmlDoc.CreateElement("Hashes"));
            AppendLeaf(xmlDoc, subNode, "Size", (new FileInfo(filePath)).Length.ToString(), null);
            if (blockConsumers != null)
            {
                foreach (HashCalculator hashExecute in blockConsumers.Where(blockConsumer => { return(blockConsumer is HashCalculator); }))
                {
                    AppendLeaf(xmlDoc, subNode, hashExecute.Name, BaseConverter.ToString(hashExecute.HashObj.Hash), null);

                    if (hashExecute.HashObj is Ed2k)
                    {
                        Ed2k ed2k = (Ed2k)hashExecute.HashObj;
                        if (!ed2k.BlueIsRed)
                        {
                            AppendLeaf(xmlDoc, subNode, "Ed2k_Alt", BaseConverter.ToString(ed2k.BlueHash), null);
                        }
                    }
                }
            }

            int    streamCount, entryCount;
            string name, text, measure;

            foreach (eStreamType streamKind in Enum.GetValues(typeof(eStreamType)))
            {
                streamCount = mediaInfo.Count_Get(streamKind);

                for (int i = 0; i < streamCount; i++)
                {
                    entryCount = mediaInfo.Count_Get(streamKind, i);
                    subNode    = node.AppendChild(xmlDoc.CreateElement(streamKind.ToString()));

                    for (int j = 0; j < entryCount; j++)
                    {
                        name = mediaInfo.Get(streamKind, i, j, eInfoType.Name).Replace("/", "-").Replace("(", "").Replace(")", "");
                        if (name.Equals("Chapters_Pos_End") || name.Equals("Chapters_Pos_Begin") || name.Contains("-String"))
                        {
                            continue;
                        }
                        if (name.Equals("Bits-Pixel*Frame"))
                        {
                            name = "BitsPerPixel";
                        }

                        text    = mediaInfo.Get(streamKind, i, j, eInfoType.Text);
                        measure = mediaInfo.Get(streamKind, i, j, eInfoType.Measure).Trim();

                        if (name.IndexOfAny(new char[] { ')', ':' }) < 0 && !String.IsNullOrEmpty(text))
                        {
                            AppendLeaf(xmlDoc, subNode, name, text, String.IsNullOrEmpty(measure) ? null : new string[, ] {
                                { "Unit", measure }
                            });
                        }
                        else
                        {
                            //Debug.Print(name + " " + text + " " + measure);
                        }
                    }
                    if (streamKind == eStreamType.Menu)
                    {
                        int     indexStart;
                        int     indexEnd;
                        XmlNode chapterNode;

                        if (int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_Begin"), out indexStart) && int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_End"), out indexEnd))
                        {
                            chapterNode = subNode.AppendChild(xmlDoc.CreateElement("Chapters"));
                            for (; indexStart < indexEnd; indexStart++)
                            {
                                AppendLeaf(xmlDoc, chapterNode, "Chapter", mediaInfo.Get(streamKind, i, indexStart, eInfoType.Text), new string[, ] {
                                    { "TimeStamp", mediaInfo.Get(streamKind, i, indexStart, eInfoType.Name) }
                                });
                            }
                        }
                    }
                }
            }

            mediaInfo.Close();

            return(xmlDoc);
        }
示例#4
0
        public MediaInfoProvider(string filePath)
        {
            infos = new InfoCollection();

            Func <string, string, string> nonEmpty = (a, b) => string.IsNullOrEmpty(a) ? b : a;

            MIL = IntPtr.Size == 8 ? (IMediaInfo) new MediaInfo_x64() : (IMediaInfo) new MediaInfo_x86();
            MIL.Option("Internet", "No");
            //if(!MIL.Option("Info_Version").Equals("MediaInfoLib - v0.7.42")) throw new Exception("Mediainfo library version mismatch. Needed: v0.7.42, Used: " + MIL.Option("Info_Version"));

            MIL.Open(filePath);

            Add(EntryKey.Size, Get("FileSize"), "byte");
            Add(EntryKey.Duration, Get("Duration", str => (double.Parse(str, CultureInfo.InvariantCulture) / 1000d).ToString("0.000", CultureInfo.InvariantCulture)), "s");
            Add(EntryKey.FileExtension, Get("FileExtension") != null ? Get("FileExtension").ToLower() : null, null);
            Add(EntryKey.WritingApp, Get("Encoded_Application"), null);
            Add(EntryKey.MuxingApp, Get("Encoded_Library"), null);

            double     dummy;
            StreamType st;
            int        streamCount;

            int[] indeces = new int[3];
            Converter <eStreamType, StreamType> streamConverter = a => a == eStreamType.Video ? StreamType.Video : (a == eStreamType.Audio ? StreamType.Audio : (a == eStreamType.Text ? StreamType.Text : (StreamType)(-1)));

            foreach (eStreamType streamKind in Enum.GetValues(typeof(eStreamType)))
            {
                streamCount = MIL.Count_Get(streamKind);
                st          = streamConverter(streamKind);
                if ((int)st == -1)
                {
                    continue;
                }
                for (int i = 0; i < streamCount; i++)
                {
                    Add(st, i, EntryKey.Size, Get(streamKind, i, "StreamSize"), "byte");
                    Add(st, i, EntryKey.Title, Get(streamKind, i, "Title"), null);
                    Add(st, i, EntryKey.Id, Get(streamKind, i, "UniqueID"), null);
                    Add(st, i, EntryKey.Language, Get(streamKind, i, "Language"), null);
                    Add(st, i, EntryKey.Duration, Get(streamKind, i, "Duration", str => (double.Parse(str.Split('/')[0], CultureInfo.InvariantCulture) / 1000).ToString("0.000", CultureInfo.InvariantCulture)), "s");
                    Add(st, i, EntryKey.Bitrate, () => Get(streamKind, i, "BitRate").Split('/').First(e => double.TryParse(e, out dummy)), null);
                    Add(st, i, EntryKey.CodecId, ((Get(streamKind, i, "Format") + " -- " + nonEmpty(Get(streamKind, i, "Format_Version"), Get(streamKind, i, "CodecID"))).Trim() + " -- " + Get(streamKind, i, "Format_Profile").Split('/')[0]).Trim(), null);
                    Add(st, i, EntryKey.CodecIdAlt, Get(streamKind, i, "CodecID"), null);
                    Add(st, i, EntryKey.EncodeSettings, Get(streamKind, i, "Encoded_Library_Settings"), null);
                    Add(st, i, EntryKey.EncodeLibrary, Get(streamKind, i, "Encoded_Library"), null);
                    Add(st, i, EntryKey.BitrateMode, Get(streamKind, i, "BitRate_Mode"), null);

                    switch (streamKind)
                    {
                    case eStreamType.Video:
                        Add(st, i, EntryKey.FrameRate, Get(streamKind, i, "FrameRate").Split('/')[0].Trim(), null);
                        Add(st, i, EntryKey.MaxFrameRate, Get(streamKind, i, "FrameRate_Maximum"), null);
                        Add(st, i, EntryKey.MinFrameRate, Get(streamKind, i, "FrameRate_Minimum"), null);
                        Add(st, i, EntryKey.VFR, Get(streamKind, i, "FrameRate_Mode").Contains("VFR") ? Get(streamKind, i, "FrameRate") : null, null);
                        Add(st, i, EntryKey.FrameCount, Get(streamKind, i, "FrameCount"), null);
                        Add(st, i, EntryKey.Width, () => Get(streamKind, i, "Width").Split('/')[0], null);
                        Add(st, i, EntryKey.ColorBitDepth, Get(streamKind, i, "BitDepth"), null);
                        Add(st, i, EntryKey.Height, () => Get(streamKind, i, "Height").Split('/')[0], null);
                        Add(st, i, EntryKey.DAR, Get(streamKind, i, "DisplayAspectRatio"), null);
                        Add(st, i, EntryKey.PAR, () => double.Parse(Get(streamKind, i, "PixelAspectRatio")) != 1 ? Get(streamKind, i, "PixelAspectRatio") : null, null);
                        indeces[0]++;
                        break;

                    case eStreamType.Audio:
                        Add(st, i, EntryKey.SamplingRate, Get(streamKind, i, "SamplingRate").Split('/')[0], null);
                        Add(st, i, EntryKey.SampleCount, Get(streamKind, i, "SamplingCount").Split('/')[0], null);
                        Add(st, i, EntryKey.ChannelCount, Get(streamKind, i, "Channel(s)").Split('/')[0], null);
                        indeces[1]++;
                        break;

                    case eStreamType.Text:
                        indeces[2]++;
                        break;
                    }
                }
            }

            string milInfo = Get("Format/Extensions") != null?Get("Format/Extensions").ToLower() : "";

            //string fileExt = System.IO.Path.GetExtension(filePath).ToLower();
            if (milInfo.Contains("asf") && milInfo.Contains("wmv") && milInfo.Contains("wma"))
            {
                if (indeces[0] == 0 && indeces[1] != 0 && indeces[2] == 0)
                {
                    Add(EntryKey.Extension, "wma", null);
                }
                else
                {
                    Add(EntryKey.Extension, "wmv", null);
                }
            }
            else if (milInfo.Contains("ts") && milInfo.Contains("m2t"))
            {
                if (System.IO.Path.GetExtension(filePath).Equals(".ts"))
                {
                    Add(EntryKey.Extension, "ts", null);                                                                     //Blame worf
                }
            }
            else if (milInfo.Contains("mpeg") && milInfo.Contains("mpg"))
            {
                if (indeces[0] == 0 || indeces[1] == 0 && indeces[1] != 0)
                {
                    Add(EntryKey.Extension, "sub", null);
                }
                else
                {
                    Add(EntryKey.Extension, "mpg", null);
                }
            }
            else if ((milInfo.Contains("mp1") && milInfo.Contains("mp2") && milInfo.Contains("mp3")) || milInfo.Contains("wav"))
            {
                switch (Get(eStreamType.Audio, 0, "Format_Profile"))
                {
                case "Layer 1": Add(EntryKey.Extension, "mp1", null); break;

                case "Layer 2": Add(EntryKey.Extension, "mp2", null); break;

                case "Layer 3": Add(EntryKey.Extension, "mp3", null); break;
                }
            }
            else if (milInfo.Contains("mp4") && milInfo.Contains("m4a") && milInfo.Contains("m4v"))
            {
                /*if(indeces[2] != 0 || (indeces[0] != 0 && indeces[1] != 0)) {
                 *      Add(EntryKey.Extension, "mp4", null);
                 * } else if(indeces[0] != 0 && indeces[1] == 0) {
                 *      Add(EntryKey.Extension, "m4v", null);
                 * } else if(indeces[0] == 0 && indeces[1] != 0) {
                 *      Add(EntryKey.Extension, "m4a", null);
                 * }*/
                if (indeces[0] == 0 && indeces[2] == 0 && indeces[1] != 0)
                {
                    Add(EntryKey.Extension, "m4a", null);
                }
                else if (indeces[0] != 0 && indeces[1] == 0 && indeces[2] == 0)
                {
                    Add(EntryKey.Extension, "m4v", null);
                }
                else
                {
                    Add(EntryKey.Extension, "mp4", null);
                }
            }
            else if (milInfo.Contains("dts"))
            {
                milInfo = Get(eStreamType.General, 0, "Audio_Codec_List").ToLower();
                if (milInfo.Contains("dts-hd"))
                {
                    Add(EntryKey.Extension, "dtshd", null);
                }
                else if (milInfo.Contains("truehd"))
                {
                    Add(EntryKey.Extension, "thd", null);
                }
                else
                {
                    Add(EntryKey.Extension, "dts", null);
                }
            }

            if (this[StreamType.General, 0, EntryKey.Extension] == null)
            {
                if (milInfo.Contains("rm") || milInfo.Contains("rmvb"))
                {
                    Add(EntryKey.Extension, "rm", null);
                }
                if (milInfo.Contains("asf") || milInfo.Contains("wmv") /*|| milInfo.Contains("wma")*/)
                {
                    Add(EntryKey.Extension, "wmv", null);
                }
                if (milInfo.Contains("mov") || milInfo.Contains("qt"))
                {
                    Add(EntryKey.Extension, "mov", null);
                }
            }


            if (this[StreamType.General, 0, EntryKey.Extension] == null)
            {
                Add(EntryKey.Extension, milInfo.Split(' ')[0], null);
            }
        }