From 3c2ef7cf1e9e25b89d9ebd05c568df9fc8b00f91 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Wed, 22 Dec 2021 23:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi.Core/BiliApi/BiliUtils/Constant.cs | 42 +++++++++++++------ .../BiliApi/BiliUtils/Quality.cs | 4 +- DownKyi.Core/DownKyi.Core.csproj | 1 + DownKyi/DownKyi.csproj | 3 -- DownKyi/Models/DownloadBaseItem.cs | 24 +++++------ .../Services/Download/AriaDownloadService.cs | 2 +- DownKyi/Services/IResolutionService.cs | 10 ----- DownKyi/Services/ResolutionService.cs | 26 ------------ DownKyi/Services/Utils.cs | 8 ++-- .../ViewModels/Settings/ViewVideoViewModel.cs | 40 ++++++++---------- .../ViewModels/ViewVideoDetailViewModel.cs | 10 ++--- .../DownloadManager/ViewDownloading.xaml | 2 +- DownKyi/Views/Settings/ViewVideo.xaml | 1 + 13 files changed, 76 insertions(+), 97 deletions(-) rename DownKyi/Models/Resolution.cs => DownKyi.Core/BiliApi/BiliUtils/Quality.cs (57%) delete mode 100644 DownKyi/Services/IResolutionService.cs delete mode 100644 DownKyi/Services/ResolutionService.cs diff --git a/DownKyi.Core/BiliApi/BiliUtils/Constant.cs b/DownKyi.Core/BiliApi/BiliUtils/Constant.cs index 157c706..5e82b9c 100644 --- a/DownKyi.Core/BiliApi/BiliUtils/Constant.cs +++ b/DownKyi.Core/BiliApi/BiliUtils/Constant.cs @@ -4,25 +4,43 @@ namespace DownKyi.Core.BiliApi.BiliUtils { public static class Constant { + private static readonly List resolutions = new List + { + new Quality { Name = "HDR 真彩", Id = 125 }, + new Quality { Name = "4K 超清", Id = 120 }, + new Quality { Name = "1080P 60帧", Id = 116 }, + new Quality { Name = "1080P 高码率", Id = 112 }, + new Quality { Name = "1080P 高清", Id = 80 }, + new Quality { Name = "720P 60帧", Id = 74 }, + new Quality { Name = "720P 高清", Id = 64 }, + new Quality { Name = "480P 清晰", Id = 32 }, + new Quality { Name = "360P 流畅", Id = 16 }, + }; + + private static readonly List qualities = new List + { + new Quality { Name = "64K", Id = 30216 }, + new Quality { Name = "132K", Id = 30232 }, + new Quality { Name = "192K", Id = 30280 }, + }; + /// - /// 音质id及含义 + /// 获取支持的视频画质 /// - public static Dictionary AudioQuality { get; } = new Dictionary() + /// + public static List GetResolutions() { - { 30216, "64K" }, - { 30232, "132K" }, - { 30280, "192K" } - }; + return resolutions; + } /// - /// 音质id及含义 + /// 获取支持的视频音质 /// - public static Dictionary AudioQualityId { get; } = new Dictionary() + /// + public static List GetAudioQualities() { - { "64K", 30216 }, - { "132K", 30232 }, - { "192K", 30280 } - }; + return qualities; + } } } diff --git a/DownKyi/Models/Resolution.cs b/DownKyi.Core/BiliApi/BiliUtils/Quality.cs similarity index 57% rename from DownKyi/Models/Resolution.cs rename to DownKyi.Core/BiliApi/BiliUtils/Quality.cs index 84ff490..6295881 100644 --- a/DownKyi/Models/Resolution.cs +++ b/DownKyi.Core/BiliApi/BiliUtils/Quality.cs @@ -1,6 +1,6 @@ -namespace DownKyi.Models +namespace DownKyi.Core.BiliApi.BiliUtils { - public class Resolution + public class Quality { public string Name { get; set; } public int Id { get; set; } diff --git a/DownKyi.Core/DownKyi.Core.csproj b/DownKyi.Core/DownKyi.Core.csproj index 131523f..e7d2790 100644 --- a/DownKyi.Core/DownKyi.Core.csproj +++ b/DownKyi.Core/DownKyi.Core.csproj @@ -129,6 +129,7 @@ + diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index e75cd65..f309c28 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -96,7 +96,6 @@ - @@ -110,8 +109,6 @@ - - diff --git a/DownKyi/Models/DownloadBaseItem.cs b/DownKyi/Models/DownloadBaseItem.cs index 6c6c102..52a84b0 100644 --- a/DownKyi/Models/DownloadBaseItem.cs +++ b/DownKyi/Models/DownloadBaseItem.cs @@ -1,4 +1,5 @@ -using Prism.Mvvm; +using DownKyi.Core.BiliApi.BiliUtils; +using Prism.Mvvm; using System; using System.Collections.Generic; using System.Windows.Media; @@ -77,15 +78,6 @@ namespace DownKyi.Models set => SetProperty(ref duration, value); } - // 音频编码 - public int AudioCodecId { get; set; } - private string audioCodecName; - public string AudioCodecName - { - get => audioCodecName; - set => SetProperty(ref audioCodecName, value); - } - // 视频编码 // "hev1.2.4.L156.90" // "avc1.640034" @@ -100,13 +92,21 @@ namespace DownKyi.Models } // 视频画质 - private Resolution resolution; - public Resolution Resolution + private Quality resolution; + public Quality Resolution { get => resolution; set => SetProperty(ref resolution, value); } + // 音频编码 + private Quality audioCodec; + public Quality AudioCodec + { + get => audioCodec; + set => SetProperty(ref audioCodec, value); + } + // 文件路径,不包含扩展名,所有内容均以此路径下载 public string FilePath { get; set; } diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index abcf28a..f538484 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/DownKyi/Services/Download/AriaDownloadService.cs @@ -59,7 +59,7 @@ namespace DownKyi.Services.Download PlayUrlDashVideo downloadAudio = null; foreach (PlayUrlDashVideo audio in downloading.PlayUrl.Dash.Audio) { - if (audio.Id == downloading.AudioCodecId) + if (audio.Id == downloading.AudioCodec.Id) { downloadAudio = audio; break; diff --git a/DownKyi/Services/IResolutionService.cs b/DownKyi/Services/IResolutionService.cs deleted file mode 100644 index d1c236a..0000000 --- a/DownKyi/Services/IResolutionService.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DownKyi.Models; -using System.Collections.Generic; - -namespace DownKyi.Services -{ - public interface IResolutionService - { - List GetResolution(); - } -} diff --git a/DownKyi/Services/ResolutionService.cs b/DownKyi/Services/ResolutionService.cs deleted file mode 100644 index a298ab1..0000000 --- a/DownKyi/Services/ResolutionService.cs +++ /dev/null @@ -1,26 +0,0 @@ -using DownKyi.Models; -using System.Collections.Generic; - -namespace DownKyi.Services -{ - public class ResolutionService : IResolutionService - { - public List GetResolution() - { - List resolutions = new List - { - new Resolution { Name = "HDR 真彩", Id = 125 }, - new Resolution { Name = "4K 超清", Id = 120 }, - new Resolution { Name = "1080P 60帧", Id = 116 }, - new Resolution { Name = "1080P 高码率", Id = 112 }, - new Resolution { Name = "1080P 高清", Id = 80 }, - new Resolution { Name = "720P 60帧", Id = 74 }, - new Resolution { Name = "720P 高清", Id = 64 }, - new Resolution { Name = "480P 清晰", Id = 32 }, - new Resolution { Name = "360P 流畅", Id = 16 } - }; - - return resolutions; - } - } -} diff --git a/DownKyi/Services/Utils.cs b/DownKyi/Services/Utils.cs index c16cf98..ed54eb9 100644 --- a/DownKyi/Services/Utils.cs +++ b/DownKyi/Services/Utils.cs @@ -1,4 +1,5 @@ -using DownKyi.Core.BiliApi.VideoStream.Models; +using DownKyi.Core.BiliApi.BiliUtils; +using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Settings; using DownKyi.Core.Settings.Models; using DownKyi.Core.Utils; @@ -101,9 +102,10 @@ namespace DownKyi.Services // 音质id大于设置画质时,跳过 if (audio.Id > defaultAudioQuality) { continue; } - if (Core.BiliApi.BiliUtils.Constant.AudioQuality.ContainsKey(audio.Id)) + Quality audioQuality = Constant.GetAudioQualities().FirstOrDefault(t => { return t.Id == audio.Id; }); + if (audioQuality != null) { - ListHelper.AddUnique(audioQualityFormatList, Core.BiliApi.BiliUtils.Constant.AudioQuality[audio.Id]); + ListHelper.AddUnique(audioQualityFormatList, audioQuality.Name); } } diff --git a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 6f30107..d100b8c 100644 --- a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -3,7 +3,6 @@ using DownKyi.Core.FileName; using DownKyi.Core.Settings; using DownKyi.Events; using DownKyi.Models; -using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; @@ -37,29 +36,29 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref selectedVideoCodec, value); } - private List videoQualityList; - public List VideoQualityList + private List videoQualityList; + public List VideoQualityList { get => videoQualityList; set => SetProperty(ref videoQualityList, value); } - private Resolution selectedVideoQuality; - public Resolution SelectedVideoQuality + private Quality selectedVideoQuality; + public Quality SelectedVideoQuality { get => selectedVideoQuality; set => SetProperty(ref selectedVideoQuality, value); } - private List audioQualityList; - public List AudioQualityList + private List audioQualityList; + public List AudioQualityList { get => audioQualityList; set => SetProperty(ref audioQualityList, value); } - private string selectedAudioQuality; - public string SelectedAudioQuality + private Quality selectedAudioQuality; + public Quality SelectedAudioQuality { get => selectedAudioQuality; set => SetProperty(ref selectedAudioQuality, value); @@ -123,15 +122,10 @@ namespace DownKyi.ViewModels.Settings }; // 优先下载画质 - VideoQualityList = new ResolutionService().GetResolution(); + VideoQualityList = Constant.GetResolutions(); // 优先下载音质 - AudioQualityList = new List - { - "64K", - "132K", - "192K", - }; + AudioQualityList = Constant.GetAudioQualities(); // 文件命名格式 SelectedFileName = new ObservableCollection(); @@ -168,7 +162,7 @@ namespace DownKyi.ViewModels.Settings // 优先下载音质 int audioQuality = SettingsManager.GetInstance().GetAudioQuality(); - SelectedAudioQuality = Constant.AudioQuality[audioQuality]; + SelectedAudioQuality = AudioQualityList.FirstOrDefault(t => { return t.Id == audioQuality; }); // 是否下载flv视频后转码为mp4 AllowStatus isTranscodingFlvToMp4 = SettingsManager.GetInstance().IsTranscodingFlvToMp4(); @@ -221,23 +215,25 @@ namespace DownKyi.ViewModels.Settings /// private void ExecuteVideoQualityCommand(object parameter) { - if (!(parameter is Resolution resolution)) { return; } + if (!(parameter is Quality resolution)) { return; } bool isSucceed = SettingsManager.GetInstance().SetQuality(resolution.Id); PublishTip(isSucceed); } // 优先下载音质事件 - private DelegateCommand audioQualityCommand; - public DelegateCommand AudioQualityCommand => audioQualityCommand ?? (audioQualityCommand = new DelegateCommand(ExecuteAudioQualityCommand)); + private DelegateCommand audioQualityCommand; + public DelegateCommand AudioQualityCommand => audioQualityCommand ?? (audioQualityCommand = new DelegateCommand(ExecuteAudioQualityCommand)); /// /// 优先下载音质事件 /// /// - private void ExecuteAudioQualityCommand(string parameter) + private void ExecuteAudioQualityCommand(object parameter) { - bool isSucceed = SettingsManager.GetInstance().SetAudioQuality(Constant.AudioQualityId[parameter]); + if (!(parameter is Quality quality)) { return; } + + bool isSucceed = SettingsManager.GetInstance().SetAudioQuality(quality.Id); PublishTip(isSucceed); } diff --git a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index 271b7ae..2f297e3 100644 --- a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -568,7 +568,7 @@ namespace DownKyi.ViewModels // 如果存在正在下载列表,则跳过,并提示 foreach (DownloadingItem item in App.DownloadingList) { - if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodecName == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec) + if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodec.Name == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec) { eventAggregator.GetEvent().Publish($"{page.Name}{DictionaryResource.GetString("TipAlreadyToAddDownloading")}"); continue; @@ -578,7 +578,7 @@ namespace DownKyi.ViewModels // 如果存在下载完成列表,弹出选择框是否再次下载 foreach (DownloadedItem item in App.DownloadedList) { - if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodecName == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec) + if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodec.Name == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec) { eventAggregator.GetEvent().Publish($"{page.Name}{DictionaryResource.GetString("TipAlreadyToAddDownloaded")}"); continue; @@ -670,15 +670,15 @@ namespace DownKyi.ViewModels MainTitle = VideoInfoView.Title, Name = page.Name, Duration = page.Duration, - AudioCodecId = Constant.AudioQualityId[page.AudioQualityFormat], - AudioCodecName = page.AudioQualityFormat, VideoCodecName = page.VideoQuality.SelectedVideoCodec, - Resolution = new Resolution { Name = page.VideoQuality.QualityFormat, Id = page.VideoQuality.Quality }, + Resolution = new Quality { Name = page.VideoQuality.QualityFormat, Id = page.VideoQuality.Quality }, + AudioCodec = Constant.GetAudioQualities().FirstOrDefault(t => { return t.Name == page.AudioQualityFormat; }), FilePath = filePath, PlayStreamType = playStreamType, DownloadStatus = DownloadStatus.NOT_STARTED, }; + // 需要下载的内容 downloading.NeedDownloadContent["downloadAudio"] = downloadAudio; downloading.NeedDownloadContent["downloadVideo"] = downloadVideo; diff --git a/DownKyi/Views/DownloadManager/ViewDownloading.xaml b/DownKyi/Views/DownloadManager/ViewDownloading.xaml index b766407..20e60b8 100644 --- a/DownKyi/Views/DownloadManager/ViewDownloading.xaml +++ b/DownKyi/Views/DownloadManager/ViewDownloading.xaml @@ -60,7 +60,7 @@ - + diff --git a/DownKyi/Views/Settings/ViewVideo.xaml b/DownKyi/Views/Settings/ViewVideo.xaml index 7a9bf48..bd6b8b8 100644 --- a/DownKyi/Views/Settings/ViewVideo.xaml +++ b/DownKyi/Views/Settings/ViewVideo.xaml @@ -65,6 +65,7 @@ Name="nameAudioQualityList" Width="120" VerticalContentAlignment="Center" + DisplayMemberPath="Name" ItemsSource="{Binding AudioQualityList}" SelectedItem="{Binding SelectedAudioQuality}">