Exemple #1
0
        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));
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static async Task <long> GetLongValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
        {
            string textValue = await mediaInfo.Get(streamKind, 0, parameter);

            long longValue;

            long.TryParse(textValue, NumberStyles.Integer, CultureInfo, out longValue);
            return(longValue);
        }
Exemple #3
0
        public static async Task <double> GetDoubleValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
        {
            string textValue = await mediaInfo.Get(streamKind, 0, parameter);

            double doubleValue;

            double.TryParse(textValue, NumberStyles.Float, CultureInfo, out doubleValue);
            return(doubleValue);
        }
Exemple #4
0
        public static async Task <long> GetDurationValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
        {
            string textValue = await mediaInfo.Get(streamKind, 0, parameter);

            TimeSpan timeSpanValue;

            TimeSpan.TryParse(textValue, CultureInfo, out timeSpanValue);
            return((long)timeSpanValue.TotalMilliseconds);
        }
Exemple #5
0
        public static async Task <int> GetIntegerValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
        {
            string textValue = await mediaInfo.Get(streamKind, 0, parameter);

            int integerValue;

            int.TryParse(textValue, NumberStyles.Integer, CultureInfo, out integerValue);
            return(integerValue);
        }
Exemple #6
0
        public static async Task <DateTime> GetDateValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
        {
            string textValue = await mediaInfo.Get(streamKind, 0, parameter);

            textValue = textValue.Replace("UTC ", string.Empty);
            DateTime dateValue;

            DateTime.TryParse(textValue, CultureInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out dateValue);
            return(dateValue);
        }
Exemple #7
0
        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;
                        }
                    }
                }
            }
        }
Exemple #8
0
        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);
        }
Exemple #9
0
 public static async Task <string> GetStringValue(this IMediaInfo mediaInfo, StreamKind streamKind, string parameter)
 {
     return((await mediaInfo.Get(streamKind, 0, parameter)).Trim());
 }