diff --git a/src/DownKyi.Core/Settings/Models/NetworkSettings.cs b/src/DownKyi.Core/Settings/Models/NetworkSettings.cs index 1e98cebc..bf26ede3 100644 --- a/src/DownKyi.Core/Settings/Models/NetworkSettings.cs +++ b/src/DownKyi.Core/Settings/Models/NetworkSettings.cs @@ -9,6 +9,8 @@ public class NetworkSettings { public AllowStatus IsLiftingOfRegion { get; set; } = AllowStatus.NONE; + public AllowStatus UseSSL { get; set; } = AllowStatus.NONE; + public Downloader Downloader { get; set; } = Downloader.NOT_SET; public int MaxCurrentDownloads { get; set; } = -1; diff --git a/src/DownKyi.Core/Settings/SettingsManager.Network.cs b/src/DownKyi.Core/Settings/SettingsManager.Network.cs index 302846db..8ffb9e76 100644 --- a/src/DownKyi.Core/Settings/SettingsManager.Network.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Network.cs @@ -7,6 +7,9 @@ public partial class SettingsManager // 是否开启解除地区限制 private readonly AllowStatus isLiftingOfRegion = AllowStatus.YES; + // 启用https + private readonly AllowStatus useSSL = AllowStatus.YES; + // 下载器 private readonly Downloader downloader = Downloader.ARIA; @@ -71,6 +74,33 @@ public bool IsLiftingOfRegion(AllowStatus isLiftingOfRegion) return SetSettings(); } + /// + /// 获取是否启用https + /// + /// + public AllowStatus UseSSL() + { + appSettings = GetSettings(); + if (appSettings.Network.UseSSL == AllowStatus.NONE) + { + // 第一次获取,先设置默认值 + UseSSL(useSSL); + return useSSL; + } + return appSettings.Network.UseSSL; + } + + /// + /// 设置是否启用https + /// + /// + /// + public bool UseSSL(AllowStatus useSSL) + { + appSettings.Network.UseSSL = useSSL; + return SetSettings(); + } + /// /// 获取下载器 /// diff --git a/src/DownKyi/Languages/Default.xaml b/src/DownKyi/Languages/Default.xaml index f5527a39..4cedf8c4 100644 --- a/src/DownKyi/Languages/Default.xaml +++ b/src/DownKyi/Languages/Default.xaml @@ -183,8 +183,9 @@ 解析后自动下载已解析视频 网络 + 启用https(若下载器提示SSL错误,则关闭此项) 选择下载器(重启生效): - 内建下载器 + 内建下载器(测试) Aria2下载器 Aria服务器端口: Aria日志等级: diff --git a/src/DownKyi/Services/Download/AriaDownloadService.cs b/src/DownKyi/Services/Download/AriaDownloadService.cs index 2ffe7df9..34ef0637 100644 --- a/src/DownKyi/Services/Download/AriaDownloadService.cs +++ b/src/DownKyi/Services/Download/AriaDownloadService.cs @@ -113,6 +113,31 @@ private string DownloadVideo(DownloadingItem downloading, PlayUrlDashVideo downl downloading.Downloading.Gid = null; } + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + if (useSSL == AllowStatus.YES) + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("http://")) + { + urls[i] = url.Replace("http://", "https://"); + } + } + } + else + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("https://")) + { + urls[i] = url.Replace("https://", "http://"); + } + } + } + // 开始下载 DownloadResult downloadStatus = DownloadByAria(downloading, urls, path, fileName); switch (downloadStatus) diff --git a/src/DownKyi/Services/Download/BuiltinDownloadService.cs b/src/DownKyi/Services/Download/BuiltinDownloadService.cs index 7c20f1bc..4a4ca791 100644 --- a/src/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/src/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -108,6 +108,31 @@ private string DownloadVideo(DownloadingItem downloading, PlayUrlDashVideo downl downloading.Downloading.Gid = null; } + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + if (useSSL == AllowStatus.YES) + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("http://")) + { + urls[i] = url.Replace("http://", "https://"); + } + } + } + else + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("https://")) + { + urls[i] = url.Replace("https://", "http://"); + } + } + } + // 开始下载 var downloadStatus = DownloadByBuiltin(downloading, urls, path, fileName); if (downloadStatus) diff --git a/src/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs b/src/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs index 0aa3468d..a46ce58c 100644 --- a/src/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs +++ b/src/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs @@ -20,6 +20,13 @@ public class ViewNetworkViewModel : BaseViewModel #region 页面属性申明 + private bool useSSL; + public bool UseSSL + { + get => useSSL; + set => SetProperty(ref useSSL, value); + } + private bool builtin; public bool Builtin { @@ -236,6 +243,10 @@ public override void OnNavigatedTo(NavigationContext navigationContext) isOnNavigatedTo = true; + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + UseSSL = useSSL == AllowStatus.YES; + // 选择下载器 var downloader = SettingsManager.GetInstance().GetDownloader(); switch (downloader) @@ -304,6 +315,21 @@ public override void OnNavigatedTo(NavigationContext navigationContext) #region 命令申明 + // 是否启用https事件 + private DelegateCommand useSSLCommand; + public DelegateCommand UseSSLCommand => useSSLCommand ?? (useSSLCommand = new DelegateCommand(ExecuteUseSSLCommand)); + + /// + /// 是否启用https事件 + /// + private void ExecuteUseSSLCommand() + { + AllowStatus useSSL = UseSSL ? AllowStatus.YES : AllowStatus.NO; + + bool isSucceed = SettingsManager.GetInstance().UseSSL(useSSL); + PublishTip(isSucceed); + } + // 下载器选择事件 private DelegateCommand selectDownloaderCommand; public DelegateCommand SelectDownloaderCommand => selectDownloaderCommand ?? (selectDownloaderCommand = new DelegateCommand(ExecuteSelectDownloaderCommand)); diff --git a/src/DownKyi/Views/Settings/ViewNetwork.xaml b/src/DownKyi/Views/Settings/ViewNetwork.xaml index 4430c61e..23a3e49e 100644 --- a/src/DownKyi/Views/Settings/ViewNetwork.xaml +++ b/src/DownKyi/Views/Settings/ViewNetwork.xaml @@ -16,6 +16,18 @@ Text="{DynamicResource Network}" /> + +