public static Model.Entities.MediaInfo GetMediaInfo(InternalMediaInfoResult data) { var internalStreams = data.streams ?? new MediaStreamInfo[] { }; var info = new Model.Entities.MediaInfo(); info.MediaStreams = internalStreams.Select(s => GetMediaStream(s, data.format)) .Where(i => i != null) .ToList(); if (data.format != null) { info.Format = data.format.format_name; } return info; }
/// <summary> /// Adds the chapters. /// </summary> /// <param name="result">The result.</param> /// <param name="standardError">The standard error.</param> private void AddChapters(InternalMediaInfoResult result, string standardError) { var lines = standardError.Split('\n').Select(l => l.TrimStart()); var chapters = new List<ChapterInfo>(); ChapterInfo lastChapter = null; foreach (var line in lines) { if (line.StartsWith("Chapter", StringComparison.OrdinalIgnoreCase)) { // Example: // Chapter #0.2: start 400.534, end 4565.435 const string srch = "start "; var start = line.IndexOf(srch, StringComparison.OrdinalIgnoreCase); if (start == -1) { continue; } var subString = line.Substring(start + srch.Length); subString = subString.Substring(0, subString.IndexOf(',')); double seconds; if (double.TryParse(subString, NumberStyles.Any, UsCulture, out seconds)) { lastChapter = new ChapterInfo { StartPositionTicks = TimeSpan.FromSeconds(seconds).Ticks }; chapters.Add(lastChapter); } } else if (line.StartsWith("title", StringComparison.OrdinalIgnoreCase)) { if (lastChapter != null && string.IsNullOrEmpty(lastChapter.Name)) { var index = line.IndexOf(':'); if (index != -1) { lastChapter.Name = line.Substring(index + 1).Trim().TrimEnd('\r'); } } } } result.Chapters = chapters; }