|
| 1 | +using Swordfish.NET.Collections; |
| 2 | +using Swordfish.NET.Collections.Auxiliary; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.ComponentModel; |
| 6 | +using System.Linq; |
| 7 | + |
| 8 | +namespace yt_dlp_gui.Models { |
| 9 | + public class VMain :INotifyPropertyChanged { |
| 10 | + public event PropertyChangedEventHandler? PropertyChanged; |
| 11 | + public List<Config> Configs { get; set; } = new List<Config>(); |
| 12 | + public Config SelectedConfig { get; set; } = new Config(); |
| 13 | + |
| 14 | + } |
| 15 | + public class VTask :INotifyPropertyChanged { |
| 16 | + public event PropertyChangedEventHandler? PropertyChanged; |
| 17 | + public VTaskVideo Video { get; set; } = new VTaskVideo(); |
| 18 | + public VTask() { |
| 19 | + |
| 20 | + } |
| 21 | + } |
| 22 | + public class VTaskVideo :INotifyPropertyChanged { |
| 23 | + public event PropertyChangedEventHandler? PropertyChanged; |
| 24 | + public Video? Source { get; set; } = new(); |
| 25 | + // Formats =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 26 | + public IEnumerable<Format> Formats => getFormats(Source?.formats); |
| 27 | + public IEnumerable<Format> FormatsVideo => Formats.Where(x => x.type == FormatType.package || x.type == FormatType.video).OrderBy(x => x, ComparerVideo.Comparer); |
| 28 | + public IEnumerable<Format> FormatsAudio => Formats.Where(x => x.type == FormatType.package || x.type == FormatType.audio).OrderBy(x => x, ComparerAudio.Comparer); |
| 29 | + public IEnumerable<Format> RequestedFormats => getFormats(Source?.requested_formats); |
| 30 | + private IEnumerable<Format> getFormats(IEnumerable<Format>? source) { |
| 31 | + return source?.Select(row => { |
| 32 | + if (row.vcodec != "none" && row.acodec != "none") { |
| 33 | + row.type = FormatType.package; |
| 34 | + if (row.height.HasValue && row.width.HasValue) { |
| 35 | + row.resolution = $"{row.width.Value}x{row.height.Value}"; |
| 36 | + } |
| 37 | + } else if (row.vcodec != "none") { |
| 38 | + row.type = FormatType.video; |
| 39 | + if (row.height.HasValue && row.width.HasValue) { |
| 40 | + row.resolution = $"{row.width.Value}x{row.height.Value}"; |
| 41 | + } |
| 42 | + } else if (row.acodec != "none") { |
| 43 | + row.type = FormatType.audio; |
| 44 | + } else { |
| 45 | + row.type = FormatType.other; |
| 46 | + } |
| 47 | + //Video Codec |
| 48 | + if (row.vcodec.StartsWith("vp9", StringComparison.InvariantCultureIgnoreCase)) { |
| 49 | + row.vcodec = "VP9"; |
| 50 | + } else if (row.vcodec.StartsWith("av01", StringComparison.InvariantCultureIgnoreCase)) { |
| 51 | + row.vcodec = "AV1"; |
| 52 | + } else if (row.vcodec.StartsWith("avc", StringComparison.InvariantCultureIgnoreCase)) { |
| 53 | + row.vcodec = "H.264"; |
| 54 | + } |
| 55 | + //Audio Codec |
| 56 | + if (row.acodec.StartsWith("mp4a", StringComparison.InvariantCultureIgnoreCase)) { |
| 57 | + row.acodec = "AAC"; |
| 58 | + } else if (row.acodec.StartsWith("opus", StringComparison.InvariantCultureIgnoreCase)) { |
| 59 | + row.acodec = "OPUS"; |
| 60 | + } |
| 61 | + return row; |
| 62 | + }).ToList() ?? new List<Format>(); |
| 63 | + } |
| 64 | + |
| 65 | + // Chapters =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 66 | + public IEnumerable<Chapters> Chapters => |
| 67 | + (Source?.chapters?.Any() ?? false |
| 68 | + ? new[] { |
| 69 | + new Chapters() { title = App.Lang.Main.ChaptersAll, type = ChaptersType.None }, |
| 70 | + new Chapters() { title = App.Lang.Main.ChaptersSplite, type = ChaptersType.Split }, |
| 71 | + }.Concat(Source.chapters) |
| 72 | + : new[] { |
| 73 | + new Chapters() { title = App.Lang.Main.ChaptersNone, type = ChaptersType.None }, |
| 74 | + }).ToList(); |
| 75 | + } |
| 76 | +} |
0 commit comments