using System; using System.Collections.Generic; using System.Linq; namespace EmbyToolbox.Models; /// Результат детального ffprobe. public sealed class MediaAnalysisResult { public string? ContainerFormat { get; init; } public string? FormatName { get; init; } public long? FormatBitRateBps { get; init; } public double? DurationSeconds { get; init; } public IReadOnlyList VideoStreams { get; init; } = Array.Empty(); public IReadOnlyList AudioStreams { get; init; } = Array.Empty(); public IReadOnlyList SubtitleStreams { get; init; } = Array.Empty(); public IReadOnlyList DataStreams { get; init; } = Array.Empty(); public IReadOnlyList AllStreams { get; init; } = Array.Empty(); public long? SourceVideoBitrateBps { get; init; } /// Основной видеопоток: самый крупный по площади кадра (не первый подряд в JSON — иначе cover/mjpeg может оказаться «основным»). public MediaStreamInfo? PrimaryVideo => VideoStreams .OrderByDescending(static v => ((long)(v.Width ?? 0)) * (v.Height ?? 0)) .ThenByDescending(static v => v.IsDefault ? 1 : 0) .FirstOrDefault(); /// format.duration, иначе максимум duration среди streams (ffprobe). public double? GetEffectiveDurationSeconds() { if (DurationSeconds is { } f && f > 0) { return f; } double? best = null; foreach (var s in AllStreams) { if (s.DurationSeconds is { } d && d > 0) { best = best is { } b ? Math.Max(b, d) : d; } } return best; } }