private string GetFileContent(FileInfo fi, ref bool mediaFlag) { // 只读取 10KB 以下 __game_version_info__.gvi 文件内容 if (fi.Name.ToLower() == "__game_version_info__.gvi" && fi.Length <= 10240) { return(File.ReadAllText(fi.FullName)); } else if (this.scanMediaInfo && (!mediaFlag) && CommonString.MediaExts.Contains(fi.Extension.ToLower()) && (!fi.Name.ToLower().Contains(".sample."))) { if (mediaInfoInitFlag) { mediaInfo.Open(fi.FullName); string strTemp = mediaInfo.Inform(); mediaFlag = true; mediaInfo.Close(); return(strTemp); } else { return(mediaInfoInitErrMsg); } } else { return(String.Empty); } }
public MediaInfo(Models.FileName file) { InitializeComponent(); this.Text = file.Original; string result; if (IntPtr.Size == 4) { var MI = new MediaInfoLib.MediaInfo(); MI.Open(file.FullPath()); MI.Option("Complete"); result = MI.Inform(); MI.Close(); } else { var MI = new MediaInfoLib.MediaInfo64(); MI.Open(file.FullPath()); MI.Option("Complete"); result = MI.Inform(); MI.Close(); } var sp = result .TrimEnd(new char[] { '\r', '\n' }) .Split(new string[] { "\r\n" }, StringSplitOptions.None); TreeNode root = null; foreach (var s in sp) { if (root == null) { root = new TreeNode(s); treeViewInfo.Nodes.Add(root); } else { if (s == "") { root = null; } else { root.Nodes.Add(new TreeNode(Regex.Replace(s, "\\s{2,}", ""))); } } } treeViewInfo.ExpandAll(); }
public string of_GetTxtStr(string lsFile) { try { MediaInfoLib.MediaInfo m = new MediaInfoLib.MediaInfo(); int k = m.Open(lsFile); if (k != 1) { return("Not Media File!"); } return(m.Inform()); } catch (Exception ex) { return(ex.Message + ex.StackTrace); } }
private void showMediaInformation(string filePath) { richTextBox_ImageProperties.AppendLine(filePath); try { MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo(); if (mediaInfo.Open(filePath) == 1) { mediaInfo.Option("Complete", "1"); richTextBox_ImageProperties.AppendLine(CultureStrings.ColonMediaInformation); richTextBox_ImageProperties.AppendLine(mediaInfo.Inform()); } mediaInfo.Close(); } catch (System.Exception ex) { logException(ex); } }
public override TaskStatus Run() { Info("Generating MediaInfo informations..."); bool success = true; bool atLeastOneSucceed = false; var files = SelectFiles(); if (files.Length > 0) { var mediaInfoPath = Path.Combine(Workflow.WorkflowTempFolder, string.Format("MediaInfo_{0:yyyy-MM-dd-HH-mm-ss-fff}.xml", DateTime.Now)); var xdoc = new XDocument(new XElement("Files")); foreach (FileInf file in files) { try { if (xdoc.Root != null) { XElement xfile = new XElement("File", new XAttribute("path", file.Path), new XAttribute("name", file.FileName)); MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo(); mediaInfo.Open(file.Path); mediaInfo.Option("Complete", "1"); string info = mediaInfo.Inform(); string[] infos = info.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); XElement xgeneral = null; XElement xaudio = null; XElement xvideo = null; // Build xgeneral foreach (var line in infos) { if (line == "General") { xgeneral = new XElement("General"); continue; } if (line == "Audio" || line == "Video") { break; } string[] tag = line.Split(':'); xgeneral.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } // Build xvideo var xvideoFound = false; foreach (var line in infos) { if (line == "Video") { xvideoFound = true; xvideo = new XElement("Video"); continue; } if (line == "Audio") { break; } if (xvideoFound) { string[] tag = line.Split(':'); xvideo.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } } // Build xaudio var xaudioFound = false; foreach (var line in infos) { if (line == "Audio") { xaudioFound = true; xaudio = new XElement("Audio"); continue; } if (xaudioFound) { string[] tag = line.Split(':'); xaudio.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } } if (xgeneral != null) { xfile.Add(xgeneral); } if (xvideo != null) { xfile.Add(xvideo); } if (xaudio != null) { xfile.Add(xaudio); } xdoc.Root.Add(xfile); } InfoFormat("MediaInfo of the file {0} generated.", file.Path); if (!atLeastOneSucceed) { atLeastOneSucceed = true; } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while generating the mediaInfo of the file {0}", e, file.Path); success = false; } } xdoc.Save(mediaInfoPath); Files.Add(new FileInf(mediaInfoPath, Id)); } var status = Status.Success; if (!success && atLeastOneSucceed) { status = Status.Warning; } else if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status, false)); }
public static XDocument Inform(FileInf[] files) { var xdoc = new XDocument(new XElement("Files")); foreach (FileInf file in files) { try { if (xdoc.Root != null) { XElement xfile = new XElement("File", new XAttribute("path", file.Path), new XAttribute("name", file.FileName)); MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo(); mediaInfo.Open(file.Path); mediaInfo.Option("Complete", "1"); string info = mediaInfo.Inform(); string[] infos = info.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); XElement xgeneral = null; XElement xaudio = null; XElement xvideo = null; // Build xgeneral foreach (var line in infos) { if (line == "General") { xgeneral = new XElement("General"); continue; } if (line == "Audio" || line == "Video") { break; } string[] tag = line.Split(':'); xgeneral.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } // Build xvideo var xvideoFound = false; foreach (var line in infos) { if (line == "Video") { xvideoFound = true; xvideo = new XElement("Video"); continue; } if (xvideoFound) { if (line == "Audio") { break; } string[] tag = line.Split(':'); xvideo.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } } // Build xaudio var xaudioFound = false; foreach (var line in infos) { if (line == "Audio") { xaudioFound = true; xaudio = new XElement("Audio"); continue; } if (xaudioFound) { if (line == "Video") { break; } string[] tag = line.Split(':'); xaudio.Add(new XElement("Tag", new XAttribute("name", tag[0].Trim()), new XAttribute("value", tag[1].Trim()))); } } if (xgeneral != null) { xfile.Add(xgeneral); } if (xvideo != null) { xfile.Add(xvideo); } if (xaudio != null) { xfile.Add(xaudio); } xdoc.Root.Add(xfile); } Logger.InfoFormat("MediaInfo of the file {0} generated.", file.Path); if (!_atLeastOneSucceed) { _atLeastOneSucceed = true; } } catch (ThreadAbortException) { throw; } catch (Exception e) { Logger.ErrorFormat("An error occured while generating the mediaInfo of the file {0}", e, file.Path); _success = false; } } return(xdoc); }
private static void DisplayMediaInfo() { String ToDisplay; MediaInfoLib.MediaInfo MI = new MediaInfoLib.MediaInfo(); ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0"); if (ToDisplay.Length == 0) { Console.Write("MediaInfo.Dll: this version of the DLL is not compatible"); return; } //Information about MediaInfo ToDisplay += "\r\n\r\nInfo_Parameters\r\n"; ToDisplay += MI.Option("Info_Parameters"); ToDisplay += "\r\n\r\nInfo_Capacities\r\n"; ToDisplay += MI.Option("Info_Capacities"); ToDisplay += "\r\n\r\nInfo_Codecs\r\n"; ToDisplay += MI.Option("Info_Codecs"); //An example of how to use the library ToDisplay += "\r\n\r\nOpen\r\n"; ToDisplay += "\r\n\r\nClose\r\n=========================="; ToDisplay += "\r\n\r\nClose\r\n=========================="; MI.Open("d:\temp\test.mp4"); ToDisplay += "\r\n\r\nInform with Complete=false\r\n"; MI.Option("Complete"); ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nInform with Complete=true\r\n"; MI.Option("Complete", "1"); ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nCustom Inform\r\n"; MI.Option("Inform", "General;File size is %FileSize% bytes"); ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n"; ToDisplay += MI.Get(0, 0, "FileSize"); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n"; ToDisplay += MI.Get(0, 0, 46); ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n"; ToDisplay += MI.Count_Get(MediaInfoLib.StreamKind.Audio); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n"; ToDisplay += MI.Get(MediaInfoLib.StreamKind.General, 0, "AudioCount"); ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n"; ToDisplay += MI.Get(MediaInfoLib.StreamKind.Audio, 0, "StreamCount"); ToDisplay += "\r\n\r\nClose\r\n"; MI.Close(); ToDisplay += "\r\n\r\nClose\r\n=========================="; //Example with a stream ToDisplay += "\r\n" + ReadMediaInfo() + "\r\n"; //Displaying the text Console.Write(ToDisplay); }