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); }
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); }
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(); } } }