diff --git a/src/DownKyi.Core/DownKyi.Core.csproj b/src/DownKyi.Core/DownKyi.Core.csproj index fb65dfc..b1c17ae 100644 --- a/src/DownKyi.Core/DownKyi.Core.csproj +++ b/src/DownKyi.Core/DownKyi.Core.csproj @@ -271,6 +271,7 @@ + diff --git a/src/DownKyi.Core/FFmpeg/FFmpegHelper.cs b/src/DownKyi.Core/FFmpeg/FFmpegHelper.cs index 31ae4d3..9b87784 100644 --- a/src/DownKyi.Core/FFmpeg/FFmpegHelper.cs +++ b/src/DownKyi.Core/FFmpeg/FFmpegHelper.cs @@ -24,7 +24,7 @@ namespace DownKyi.Core.FFmpeg } if (video2 == null || !File.Exists(video2)) { - param = $"-y -i \"{video1}\" -acodec copy -f aac \"{destVideo}\""; + param = $"-y -i \"{video1}\" -acodec copy \"{destVideo}\""; } if (!File.Exists(video1) && !File.Exists(video2)) { return false; } diff --git a/src/DownKyi.Core/Settings/Models/BasicSettings.cs b/src/DownKyi.Core/Settings/Models/BasicSettings.cs index ece4d9c..43eea04 100644 --- a/src/DownKyi.Core/Settings/Models/BasicSettings.cs +++ b/src/DownKyi.Core/Settings/Models/BasicSettings.cs @@ -9,6 +9,7 @@ public AllowStatus IsListenClipboard { get; set; } = AllowStatus.NONE; public AllowStatus IsAutoParseVideo { get; set; } = AllowStatus.NONE; public ParseScope ParseScope { get; set; } = ParseScope.NOT_SET; + public AllowStatus IsAutoDownloadAll { get; set; } = AllowStatus.NONE; public DownloadFinishedSort DownloadFinishedSort { get; set; } = DownloadFinishedSort.NOT_SET; } } diff --git a/src/DownKyi.Core/Settings/Models/VideoContentSettings.cs b/src/DownKyi.Core/Settings/Models/VideoContentSettings.cs new file mode 100644 index 0000000..ddc26a1 --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/VideoContentSettings.cs @@ -0,0 +1,11 @@ +namespace DownKyi.Core.Settings.Models +{ + public class VideoContentSettings + { + public bool DownloadAudio { get; set; } = true; + public bool DownloadVideo { get; set; } = true; + public bool DownloadDanmaku { get; set; } = true; + public bool DownloadSubtitle { get; set; } = true; + public bool DownloadCover { get; set; } = true; + } +} diff --git a/src/DownKyi.Core/Settings/Models/VideoSettings.cs b/src/DownKyi.Core/Settings/Models/VideoSettings.cs index fc9c56b..c444a42 100644 --- a/src/DownKyi.Core/Settings/Models/VideoSettings.cs +++ b/src/DownKyi.Core/Settings/Models/VideoSettings.cs @@ -15,6 +15,7 @@ namespace DownKyi.Core.Settings.Models public string SaveVideoRootPath { get; set; } = null; // 视频保存路径 public List HistoryVideoRootPaths { get; set; } = null; // 历史视频保存路径 public AllowStatus IsUseSaveVideoRootPath { get; set; } = AllowStatus.NONE; // 是否使用默认视频保存路径 + public VideoContentSettings VideoContent { get; set; } = null; // 下载内容 public List FileNameParts { get; set; } = null; // 文件命名格式 public string FileNamePartTimeFormat { get; set; } = null; // 文件命名中的时间格式 } diff --git a/src/DownKyi.Core/Settings/SettingsManager.Basic.cs b/src/DownKyi.Core/Settings/SettingsManager.Basic.cs index 10cf7ab..ccf618f 100644 --- a/src/DownKyi.Core/Settings/SettingsManager.Basic.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Basic.cs @@ -14,6 +14,9 @@ // 默认的视频解析项 private readonly ParseScope parseScope = ParseScope.NONE; + // 解析后自动下载解析视频 + private readonly AllowStatus isAutoDownloadAll = AllowStatus.NO; + // 下载完成列表排序 private readonly DownloadFinishedSort finishedSort = DownloadFinishedSort.DOWNLOAD; @@ -125,6 +128,33 @@ return SetSettings(); } + /// + /// 解析后是否自动下载解析视频 + /// + /// + public AllowStatus IsAutoDownloadAll() + { + appSettings = GetSettings(); + if (appSettings.Basic.IsAutoDownloadAll == AllowStatus.NONE) + { + // 第一次获取,先设置默认值 + IsAutoDownloadAll(isAutoDownloadAll); + return isAutoDownloadAll; + } + return appSettings.Basic.IsAutoDownloadAll; + } + + /// + /// 解析后是否自动下载解析视频 + /// + /// + /// + public bool IsAutoDownloadAll(AllowStatus isAutoDownloadAll) + { + appSettings.Basic.IsAutoDownloadAll = isAutoDownloadAll; + return SetSettings(); + } + /// /// 获取下载完成列表排序 /// diff --git a/src/DownKyi.Core/Settings/SettingsManager.Video.cs b/src/DownKyi.Core/Settings/SettingsManager.Video.cs index f83b98c..8caa05e 100644 --- a/src/DownKyi.Core/Settings/SettingsManager.Video.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Video.cs @@ -1,4 +1,5 @@ using DownKyi.Core.FileName; +using DownKyi.Core.Settings.Models; using System; using System.Collections.Generic; using System.IO; @@ -28,6 +29,9 @@ namespace DownKyi.Core.Settings // 是否使用默认下载目录,如果是,则每次点击下载选中项时不再询问下载目录 private readonly AllowStatus isUseSaveVideoRootPath = AllowStatus.NO; + // 下载内容 + private readonly VideoContentSettings videoContent = new VideoContentSettings(); + // 文件命名格式 private readonly List fileNameParts = new List { @@ -236,6 +240,33 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取下载内容 + /// + /// + public VideoContentSettings GetVideoContent() + { + appSettings = GetSettings(); + if (appSettings.Video.VideoContent == null) + { + // 第一次获取,先设置默认值 + SetVideoContent(videoContent); + return videoContent; + } + return appSettings.Video.VideoContent; + } + + /// + /// 设置下载内容 + /// + /// + /// + public bool SetVideoContent(VideoContentSettings videoContent) + { + appSettings.Video.VideoContent = videoContent; + return SetSettings(); + } + /// /// 获取文件命名格式 /// diff --git a/src/DownKyi.Core/Settings/SettingsManager.cs b/src/DownKyi.Core/Settings/SettingsManager.cs index d44485c..f6d19b0 100644 --- a/src/DownKyi.Core/Settings/SettingsManager.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.cs @@ -57,9 +57,11 @@ namespace DownKyi.Core.Settings { try { - StreamReader streamReader = File.OpenText(settingsName); + FileStream fileStream = new FileStream(settingsName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.UTF8); string jsonWordTemplate = streamReader.ReadToEnd(); streamReader.Close(); + fileStream.Close(); #if DEBUG #else diff --git a/src/DownKyi/Languages/Default.xaml b/src/DownKyi/Languages/Default.xaml index c8425a5..e468434 100644 --- a/src/DownKyi/Languages/Default.xaml +++ b/src/DownKyi/Languages/Default.xaml @@ -180,6 +180,7 @@ 监听剪贴板 视频自动解析 视频解析范围: + 解析后自动下载已解析视频 网络 Aria服务器端口: @@ -298,6 +299,7 @@ 浏览 盘剩余空间: 下载内容: + 下载内容 所有 音频 视频 diff --git a/src/DownKyi/Services/BangumiInfoService.cs b/src/DownKyi/Services/BangumiInfoService.cs index cc1a5ff..69f1c6d 100644 --- a/src/DownKyi/Services/BangumiInfoService.cs +++ b/src/DownKyi/Services/BangumiInfoService.cs @@ -138,11 +138,9 @@ namespace DownKyi.Services /// 获取视频章节与剧集 /// /// - public List GetVideoSections() + public List GetVideoSections(bool noUgc = false) { if (bangumiSeason == null) { return null; } - if (bangumiSeason.Section == null) { return null; } - if (bangumiSeason.Section.Count == 0) { return null; } List videoSections = new List { @@ -155,6 +153,15 @@ namespace DownKyi.Services } }; + // 不需要其他季或花絮内容 + if (noUgc) + { + return videoSections; + } + + if (bangumiSeason.Section == null) { return null; } + if (bangumiSeason.Section.Count == 0) { return null; } + foreach (BangumiSection section in bangumiSeason.Section) { List pages = new List(); diff --git a/src/DownKyi/Services/CheeseInfoService.cs b/src/DownKyi/Services/CheeseInfoService.cs index 7f9fab7..62b5520 100644 --- a/src/DownKyi/Services/CheeseInfoService.cs +++ b/src/DownKyi/Services/CheeseInfoService.cs @@ -106,7 +106,7 @@ namespace DownKyi.Services /// 获取视频章节与剧集 /// /// - public List GetVideoSections() + public List GetVideoSections(bool noUgc = false) { return null; } diff --git a/src/DownKyi/Services/Download/AddToDownloadService.cs b/src/DownKyi/Services/Download/AddToDownloadService.cs index 09d89d6..242bcea 100644 --- a/src/DownKyi/Services/Download/AddToDownloadService.cs +++ b/src/DownKyi/Services/Download/AddToDownloadService.cs @@ -103,7 +103,7 @@ namespace DownKyi.Services.Download return; } - videoSections = videoInfoService.GetVideoSections(); + videoSections = videoInfoService.GetVideoSections(true); if (videoSections == null) { LogManager.Debug(Tag, "videoSections is not exist."); @@ -196,7 +196,7 @@ namespace DownKyi.Services.Download return directory; } - public int AddToDownload(IEventAggregator eventAggregator, string directory) + public int AddToDownload(IEventAggregator eventAggregator, string directory, bool isAll = false) { if (directory == null || directory == string.Empty) { return -1; } if (videoSections == null) { return -1; } @@ -212,7 +212,7 @@ namespace DownKyi.Services.Download foreach (VideoPage page in section.VideoPages) { // 只下载选中项,跳过未选中项 - if (!page.IsSelected) { continue; } + if (!isAll && !page.IsSelected) { continue; } // 没有解析的也跳过 if (page.PlayUrl == null) { continue; } diff --git a/src/DownKyi/Services/IInfoService.cs b/src/DownKyi/Services/IInfoService.cs index a882569..43bd09b 100644 --- a/src/DownKyi/Services/IInfoService.cs +++ b/src/DownKyi/Services/IInfoService.cs @@ -7,7 +7,7 @@ namespace DownKyi.Services { VideoInfoView GetVideoView(); - List GetVideoSections(); + List GetVideoSections(bool noUgc); List GetVideoPages(); diff --git a/src/DownKyi/Services/VideoInfoService.cs b/src/DownKyi/Services/VideoInfoService.cs index 9c34ca4..ed9738b 100644 --- a/src/DownKyi/Services/VideoInfoService.cs +++ b/src/DownKyi/Services/VideoInfoService.cs @@ -114,15 +114,30 @@ namespace DownKyi.Services /// 获取视频章节与剧集 /// /// - public List GetVideoSections() + public List GetVideoSections(bool noUgc = false) { if (videoView == null) { return null; } + + List videoSections = new List(); + + // 不需要ugc内容 + if (noUgc) + { + videoSections.Add(new VideoSection + { + Id = 0, + Title = "default", + IsSelected = true, + VideoPages = GetVideoPages() + }); + + return videoSections; + } + if (videoView.UgcSeason == null) { return null; } if (videoView.UgcSeason.Sections == null) { return null; } if (videoView.UgcSeason.Sections.Count == 0) { return null; } - List videoSections = new List(); - foreach (UgcSection section in videoView.UgcSeason.Sections) { List pages = new List(); diff --git a/src/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs b/src/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs index c62b6aa..d806a42 100644 --- a/src/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs +++ b/src/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs @@ -1,4 +1,5 @@ using DownKyi.Core.Settings; +using DownKyi.Core.Settings.Models; using DownKyi.Core.Utils; using DownKyi.Events; using DownKyi.Images; @@ -136,14 +137,23 @@ namespace DownKyi.ViewModels.Dialogs FolderIcon = NormalIcon.Instance().Folder; FolderIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); - DownloadAll = true; - DownloadAudio = true; - DownloadVideo = true; - DownloadDanmaku = true; - DownloadSubtitle = true; - DownloadCover = true; + // 下载内容 + VideoContentSettings videoContent = SettingsManager.GetInstance().GetVideoContent(); - #endregion + DownloadAudio = videoContent.DownloadAudio; + DownloadVideo = videoContent.DownloadVideo; + DownloadDanmaku = videoContent.DownloadDanmaku; + DownloadSubtitle = videoContent.DownloadSubtitle; + DownloadCover = videoContent.DownloadCover; + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + else + { + DownloadAll = false; + } // 历史下载目录 DirectoryList = SettingsManager.GetInstance().GetHistoryVideoRootPaths(); @@ -156,6 +166,9 @@ namespace DownKyi.ViewModels.Dialogs // 是否使用默认下载目录 IsDefaultDownloadDirectory = SettingsManager.GetInstance().IsUseSaveVideoRootPath() == AllowStatus.YES; + + #endregion + } #region 命令申明 @@ -213,6 +226,8 @@ namespace DownKyi.ViewModels.Dialogs DownloadSubtitle = false; DownloadCover = false; } + + SetVideoContent(); } // 音频选择事件 @@ -227,13 +242,14 @@ namespace DownKyi.ViewModels.Dialogs if (!DownloadAudio) { DownloadAll = false; - return; } if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) { DownloadAll = true; } + + SetVideoContent(); } // 视频选择事件 @@ -248,13 +264,14 @@ namespace DownKyi.ViewModels.Dialogs if (!DownloadVideo) { DownloadAll = false; - return; } if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) { DownloadAll = true; } + + SetVideoContent(); } // 弹幕选择事件 @@ -269,13 +286,14 @@ namespace DownKyi.ViewModels.Dialogs if (!DownloadDanmaku) { DownloadAll = false; - return; } if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) { DownloadAll = true; } + + SetVideoContent(); } // 字幕选择事件 @@ -290,13 +308,14 @@ namespace DownKyi.ViewModels.Dialogs if (!DownloadSubtitle) { DownloadAll = false; - return; } if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) { DownloadAll = true; } + + SetVideoContent(); } // 封面选择事件 @@ -311,13 +330,14 @@ namespace DownKyi.ViewModels.Dialogs if (!DownloadCover) { DownloadAll = false; - return; } if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) { DownloadAll = true; } + + SetVideoContent(); } // 确认下载事件 @@ -370,6 +390,23 @@ namespace DownKyi.ViewModels.Dialogs #endregion + /// + /// 保存下载视频内容到设置 + /// + private void SetVideoContent() + { + VideoContentSettings videoContent = new VideoContentSettings + { + DownloadAudio = DownloadAudio, + DownloadVideo = DownloadVideo, + DownloadDanmaku = DownloadDanmaku, + DownloadSubtitle = DownloadSubtitle, + DownloadCover = DownloadCover + }; + + SettingsManager.GetInstance().SetVideoContent(videoContent); + } + /// /// 设置下载路径 /// diff --git a/src/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs b/src/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs index 032e02e..0d195af 100644 --- a/src/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs +++ b/src/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs @@ -67,6 +67,13 @@ namespace DownKyi.ViewModels.Settings set { SetProperty(ref selectedParseScope, value); } } + private bool autoDownloadAll; + public bool AutoDownloadAll + { + get => autoDownloadAll; + set => SetProperty(ref autoDownloadAll, value); + } + #endregion public ViewBasicViewModel(IEventAggregator eventAggregator) : base(eventAggregator) @@ -113,6 +120,10 @@ namespace DownKyi.ViewModels.Settings ParseScope parseScope = SettingsManager.GetInstance().GetParseScope(); SelectedParseScope = ParseScopes.FirstOrDefault(t => { return t.ParseScope == parseScope; }); + // 解析后是否自动下载解析视频 + AllowStatus isAutoDownloadAll = SettingsManager.GetInstance().IsAutoDownloadAll(); + AutoDownloadAll = isAutoDownloadAll == AllowStatus.YES; + isOnNavigatedTo = false; } @@ -193,6 +204,21 @@ namespace DownKyi.ViewModels.Settings PublishTip(isSucceed); } + // 解析后是否自动下载解析视频 + private DelegateCommand autoDownloadAllCommand; + public DelegateCommand AutoDownloadAllCommand => autoDownloadAllCommand ?? (autoDownloadAllCommand = new DelegateCommand(ExecuteAutoDownloadAllCommand)); + + /// + /// 解析后是否自动下载解析视频 + /// + private void ExecuteAutoDownloadAllCommand() + { + AllowStatus isAutoDownloadAll = AutoDownloadAll ? AllowStatus.YES : AllowStatus.NO; + + bool isSucceed = SettingsManager.GetInstance().IsAutoDownloadAll(isAutoDownloadAll); + PublishTip(isSucceed); + } + #endregion /// diff --git a/src/DownKyi/ViewModels/Settings/ViewDanmakuViewModel.cs b/src/DownKyi/ViewModels/Settings/ViewDanmakuViewModel.cs index c9fda5b..cdc557b 100644 --- a/src/DownKyi/ViewModels/Settings/ViewDanmakuViewModel.cs +++ b/src/DownKyi/ViewModels/Settings/ViewDanmakuViewModel.cs @@ -144,7 +144,7 @@ namespace DownKyi.ViewModels.Settings // 弹幕字体 string danmakuFont = SettingsManager.GetInstance().GetDanmakuFontName(); - if (Fonts.Contains(danmakuFont)) + if (danmakuFont != null && Fonts.Contains(danmakuFont)) { // 只有系统中存在当前设置的字体,才能显示 SelectedFont = danmakuFont; diff --git a/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 1a78dca..30c556a 100644 --- a/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -1,6 +1,7 @@ using DownKyi.Core.BiliApi.BiliUtils; using DownKyi.Core.FileName; using DownKyi.Core.Settings; +using DownKyi.Core.Settings.Models; using DownKyi.Events; using DownKyi.Utils; using Prism.Commands; @@ -84,6 +85,48 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref saveVideoDirectory, value); } + private bool downloadAll; + public bool DownloadAll + { + get { return downloadAll; } + set { SetProperty(ref downloadAll, value); } + } + + private bool downloadAudio; + public bool DownloadAudio + { + get { return downloadAudio; } + set { SetProperty(ref downloadAudio, value); } + } + + private bool downloadVideo; + public bool DownloadVideo + { + get { return downloadVideo; } + set { SetProperty(ref downloadVideo, value); } + } + + private bool downloadDanmaku; + public bool DownloadDanmaku + { + get { return downloadDanmaku; } + set { SetProperty(ref downloadDanmaku, value); } + } + + private bool downloadSubtitle; + public bool DownloadSubtitle + { + get { return downloadSubtitle; } + set { SetProperty(ref downloadSubtitle, value); } + } + + private bool downloadCover; + public bool DownloadCover + { + get { return downloadCover; } + set { SetProperty(ref downloadCover, value); } + } + private ObservableCollection selectedFileName; public ObservableCollection SelectedFileName { @@ -195,6 +238,24 @@ namespace DownKyi.ViewModels.Settings // 默认下载目录 SaveVideoDirectory = SettingsManager.GetInstance().GetSaveVideoRootPath(); + // 下载内容 + VideoContentSettings videoContent = SettingsManager.GetInstance().GetVideoContent(); + + DownloadAudio = videoContent.DownloadAudio; + DownloadVideo = videoContent.DownloadVideo; + DownloadDanmaku = videoContent.DownloadDanmaku; + DownloadSubtitle = videoContent.DownloadSubtitle; + DownloadCover = videoContent.DownloadCover; + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + else + { + DownloadAll = false; + } + // 文件命名格式 List fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); SelectedFileName.Clear(); @@ -311,6 +372,145 @@ namespace DownKyi.ViewModels.Settings } } + // 所有内容选择事件 + private DelegateCommand downloadAllCommand; + public DelegateCommand DownloadAllCommand => downloadAllCommand ?? (downloadAllCommand = new DelegateCommand(ExecuteDownloadAllCommand)); + + /// + /// 所有内容选择事件 + /// + private void ExecuteDownloadAllCommand() + { + if (DownloadAll) + { + DownloadAudio = true; + DownloadVideo = true; + DownloadDanmaku = true; + DownloadSubtitle = true; + DownloadCover = true; + } + else + { + DownloadAudio = false; + DownloadVideo = false; + DownloadDanmaku = false; + DownloadSubtitle = false; + DownloadCover = false; + } + + SetVideoContent(); + } + + // 音频选择事件 + private DelegateCommand downloadAudioCommand; + public DelegateCommand DownloadAudioCommand => downloadAudioCommand ?? (downloadAudioCommand = new DelegateCommand(ExecuteDownloadAudioCommand)); + + /// + /// 音频选择事件 + /// + private void ExecuteDownloadAudioCommand() + { + if (!DownloadAudio) + { + DownloadAll = false; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + + SetVideoContent(); + } + + // 视频选择事件 + private DelegateCommand downloadVideoCommand; + public DelegateCommand DownloadVideoCommand => downloadVideoCommand ?? (downloadVideoCommand = new DelegateCommand(ExecuteDownloadVideoCommand)); + + /// + /// 视频选择事件 + /// + private void ExecuteDownloadVideoCommand() + { + if (!DownloadVideo) + { + DownloadAll = false; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + + SetVideoContent(); + } + + // 弹幕选择事件 + private DelegateCommand downloadDanmakuCommand; + public DelegateCommand DownloadDanmakuCommand => downloadDanmakuCommand ?? (downloadDanmakuCommand = new DelegateCommand(ExecuteDownloadDanmakuCommand)); + + /// + /// 弹幕选择事件 + /// + private void ExecuteDownloadDanmakuCommand() + { + if (!DownloadDanmaku) + { + DownloadAll = false; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + + SetVideoContent(); + } + + // 字幕选择事件 + private DelegateCommand downloadSubtitleCommand; + public DelegateCommand DownloadSubtitleCommand => downloadSubtitleCommand ?? (downloadSubtitleCommand = new DelegateCommand(ExecuteDownloadSubtitleCommand)); + + /// + /// 字幕选择事件 + /// + private void ExecuteDownloadSubtitleCommand() + { + if (!DownloadSubtitle) + { + DownloadAll = false; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + + SetVideoContent(); + } + + // 封面选择事件 + private DelegateCommand downloadCoverCommand; + public DelegateCommand DownloadCoverCommand => downloadCoverCommand ?? (downloadCoverCommand = new DelegateCommand(ExecuteDownloadCoverCommand)); + + /// + /// 封面选择事件 + /// + private void ExecuteDownloadCoverCommand() + { + if (!DownloadCover) + { + DownloadAll = false; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + + SetVideoContent(); + } + // 选中文件名字段点击事件 private DelegateCommand selectedFileNameCommand; public DelegateCommand SelectedFileNameCommand => selectedFileNameCommand ?? (selectedFileNameCommand = new DelegateCommand(ExecuteSelectedFileNameCommand)); @@ -460,21 +660,21 @@ namespace DownKyi.ViewModels.Settings } /// - /// 发送需要显示的tip + /// 保存下载视频内容到设置 /// - /// - private void PublishTip(bool isSucceed) + private void SetVideoContent() { - if (isOnNavigatedTo) { return; } - - if (isSucceed) - { - eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipSettingUpdated")); - } - else + VideoContentSettings videoContent = new VideoContentSettings { - eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipSettingFailed")); - } + DownloadAudio = DownloadAudio, + DownloadVideo = DownloadVideo, + DownloadDanmaku = DownloadDanmaku, + DownloadSubtitle = DownloadSubtitle, + DownloadCover = DownloadCover + }; + + bool isSucceed = SettingsManager.GetInstance().SetVideoContent(videoContent); + PublishTip(isSucceed); } /// @@ -544,5 +744,23 @@ namespace DownKyi.ViewModels.Settings return display; } + /// + /// 发送需要显示的tip + /// + /// + private void PublishTip(bool isSucceed) + { + if (isOnNavigatedTo) { return; } + + if (isSucceed) + { + eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipSettingUpdated")); + } + else + { + eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipSettingFailed")); + } + } + } } diff --git a/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index 10b69c8..f544be0 100644 --- a/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -480,6 +480,13 @@ namespace DownKyi.ViewModels } LoadingVisibility = Visibility.Collapsed; + + // 解析后是否自动下载解析视频 + AllowStatus isAutoDownloadAll = SettingsManager.GetInstance().IsAutoDownloadAll(); + if (parseScope != ParseScope.NONE && isAutoDownloadAll == AllowStatus.YES) + { + AddToDownload(true); + } } /// @@ -498,56 +505,57 @@ namespace DownKyi.ViewModels /// /// 添加到下载列表事件 /// - private async void ExecuteAddToDownloadCommand() - { - AddToDownloadService addToDownloadService = null; - // 视频 - if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input)) - { - addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO); - } - // 番剧(电影、电视剧) - else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input)) - { - addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI); - } - // 课程 - else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) - { - addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE); - } - else - { - return; - } - - // 选择文件夹 - string directory = addToDownloadService.SetDirectory(dialogService); - - // 视频计数 - int i = 0; - await Task.Run(() => - { - // 传递video对象 - addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList()); - // 下载 - i = addToDownloadService.AddToDownload(eventAggregator, directory); - }); - - if (directory == null) - { - return; - } - - // 通知用户添加到下载列表的结果 - if (i <= 0) - { - eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipAddDownloadingZero")); - } - else - { - eventAggregator.GetEvent().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}"); - } + private void ExecuteAddToDownloadCommand() + { + AddToDownload(false); + //AddToDownloadService addToDownloadService = null; + //// 视频 + //if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input)) + //{ + // addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO); + //} + //// 番剧(电影、电视剧) + //else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input)) + //{ + // addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI); + //} + //// 课程 + //else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) + //{ + // addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE); + //} + //else + //{ + // return; + //} + + //// 选择文件夹 + //string directory = addToDownloadService.SetDirectory(dialogService); + + //// 视频计数 + //int i = 0; + //await Task.Run(() => + //{ + // // 传递video对象 + // addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList()); + // // 下载 + // i = addToDownloadService.AddToDownload(eventAggregator, directory); + //}); + + //if (directory == null) + //{ + // return; + //} + + //// 通知用户添加到下载列表的结果 + //if (i <= 0) + //{ + // eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipAddDownloadingZero")); + //} + //else + //{ + // eventAggregator.GetEvent().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}"); + //} } /// @@ -627,7 +635,7 @@ namespace DownKyi.ViewModels NoDataVisibility = Visibility.Collapsed; } - List videoSections = videoInfoService.GetVideoSections(); + List videoSections = videoInfoService.GetVideoSections(false); if (videoSections == null) { LogManager.Debug(Tag, "videoSections is not exist."); @@ -663,6 +671,62 @@ namespace DownKyi.ViewModels videoInfoService.GetVideoStream(videoPage); } + + /// + /// 添加到下载列表事件 + /// + private async void AddToDownload(bool isAll) + { + AddToDownloadService addToDownloadService = null; + // 视频 + if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input)) + { + addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO); + } + // 番剧(电影、电视剧) + else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input)) + { + addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI); + } + // 课程 + else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) + { + addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE); + } + else + { + return; + } + + // 选择文件夹 + string directory = addToDownloadService.SetDirectory(dialogService); + + // 视频计数 + int i = 0; + await Task.Run(() => + { + // 传递video对象 + addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList()); + // 下载 + i = addToDownloadService.AddToDownload(eventAggregator, directory, isAll); + }); + + if (directory == null) + { + return; + } + + // 通知用户添加到下载列表的结果 + if (i <= 0) + { + eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipAddDownloadingZero")); + } + else + { + eventAggregator.GetEvent().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}"); + } + } + #endregion /// diff --git a/src/DownKyi/Views/Settings/ViewBasic.xaml b/src/DownKyi/Views/Settings/ViewBasic.xaml index c1eda32..f6f6d57 100644 --- a/src/DownKyi/Views/Settings/ViewBasic.xaml +++ b/src/DownKyi/Views/Settings/ViewBasic.xaml @@ -63,7 +63,6 @@ Background="{DynamicResource BrushBorder}" /> + + diff --git a/src/DownKyi/Views/Settings/ViewDanmaku.xaml b/src/DownKyi/Views/Settings/ViewDanmaku.xaml index be6edf1..623cc54 100644 --- a/src/DownKyi/Views/Settings/ViewDanmaku.xaml +++ b/src/DownKyi/Views/Settings/ViewDanmaku.xaml @@ -19,8 +19,14 @@ + HorizontalAlignment="Left"> + + + + + + + + + + + + + + + + + + +