diff --git a/DownKyi.Core/FileName/HyphenSeparated.cs b/DownKyi.Core/FileName/HyphenSeparated.cs index e935d64..0bb3083 100644 --- a/DownKyi.Core/FileName/HyphenSeparated.cs +++ b/DownKyi.Core/FileName/HyphenSeparated.cs @@ -3,13 +3,14 @@ namespace DownKyi.Core.FileName { /// - /// 文件名的分隔符 + /// 文件名字段 /// public static class HyphenSeparated { + // 文件名的分隔符 public static Dictionary Hyphen = new Dictionary() { - { 101, "/" }, + { 100, "/" }, { 101, "_" }, { 102, "-" }, { 103, "+" }, @@ -25,5 +26,6 @@ namespace DownKyi.Core.FileName { 113, "}" }, { 114, " " }, }; + } } diff --git a/DownKyi.Core/Settings/Models/VideoSettings.cs b/DownKyi.Core/Settings/Models/VideoSettings.cs index bc0aa61..d5fe834 100644 --- a/DownKyi.Core/Settings/Models/VideoSettings.cs +++ b/DownKyi.Core/Settings/Models/VideoSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using DownKyi.Core.FileName; +using System.Collections.Generic; namespace DownKyi.Core.Settings.Models { @@ -7,12 +8,13 @@ namespace DownKyi.Core.Settings.Models /// public class VideoSettings { - public VideoCodecs VideoCodecs { get; set; } - public int Quality { get; set; } - public int AudioQuality { get; set; } - public AllowStatus IsTranscodingFlvToMp4 { get; set; } - public string SaveVideoRootPath { get; set; } - public List HistoryVideoRootPaths { get; set; } - public AllowStatus IsUseSaveVideoRootPath { get; set; } + public VideoCodecs VideoCodecs { get; set; } // AVC or HEVC + public int Quality { get; set; } // 画质 + public int AudioQuality { get; set; } // 音质 + public AllowStatus IsTranscodingFlvToMp4 { get; set; } // 是否将flv转为mp4 + public string SaveVideoRootPath { get; set; } // 视频保存路径 + public List HistoryVideoRootPaths { get; set; } // 历史视频保存路径 + public AllowStatus IsUseSaveVideoRootPath { get; set; } // 是否使用默认视频保存路径 + public List FileNameParts { get; set; } // 文件命名格式 } } diff --git a/DownKyi.Core/Settings/SettingsManager.Video.cs b/DownKyi.Core/Settings/SettingsManager.Video.cs index f2f9eaf..039f7a8 100644 --- a/DownKyi.Core/Settings/SettingsManager.Video.cs +++ b/DownKyi.Core/Settings/SettingsManager.Video.cs @@ -1,4 +1,5 @@ -using System; +using DownKyi.Core.FileName; +using System; using System.Collections.Generic; using System.IO; @@ -27,6 +28,20 @@ namespace DownKyi.Core.Settings // 是否使用默认下载目录,如果是,则每次点击下载选中项时不再询问下载目录 private readonly AllowStatus isUseSaveVideoRootPath = AllowStatus.NO; + // 文件命名格式 + private readonly List fileNameParts = new List + { + FileNamePart.MAIN_TITLE, + FileNamePart.SLASH, + FileNamePart.ORDER, + FileNamePart.HYPHEN, + FileNamePart.PAGE_TITLE, + FileNamePart.HYPHEN, + FileNamePart.VIDEO_QUALITY, + FileNamePart.HYPHEN, + FileNamePart.VIDEO_CODEC, + }; + /// /// 获取优先下载的视频编码 /// @@ -216,5 +231,32 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取文件命名格式 + /// + /// + public List GetFileNameParts() + { + appSettings = GetSettings(); + if (appSettings.Video.FileNameParts == null) + { + // 第一次获取,先设置默认值 + SetFileNameParts(fileNameParts); + return fileNameParts; + } + return appSettings.Video.FileNameParts; + } + + /// + /// 设置文件命名格式 + /// + /// + /// + public bool SetFileNameParts(List fileNameParts) + { + appSettings.Video.FileNameParts = fileNameParts; + return SetSettings(); + } + } } diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index e14c4f8..7eadf65 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -92,6 +92,7 @@ + diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index ab0dcf4..45d6b33 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -113,16 +113,22 @@ 视频 优先下载的视频编码: 优先下载的视频画质: - 启用视频编号 - 勾选后,将为下载完成的视频的文件名添加上序号 下载FLV视频后转码为mp4 使用默认下载目录 默认下载目录: 默认将文件下载到该文件夹中 更改目录 - 为不同视频分别创建文件夹 - 在下载视频的同时下载弹幕 - 在下载视频的同时下载封面 + 文件命名格式 + 文件名: + 可选字段: + 序号 + 视频标题 + 分P标题 + 视频分区 + 音质 + 画质 + 视频编码 + 空格 弹幕 按类型屏蔽 diff --git a/DownKyi/Models/DisplayFileNamePart.cs b/DownKyi/Models/DisplayFileNamePart.cs new file mode 100644 index 0000000..4d8ab20 --- /dev/null +++ b/DownKyi/Models/DisplayFileNamePart.cs @@ -0,0 +1,17 @@ +using DownKyi.Core.FileName; +using Prism.Mvvm; + +namespace DownKyi.Models +{ + public class DisplayFileNamePart : BindableBase + { + public FileNamePart Id { get; set; } + + private string title; + public string Title + { + get => title; + set => SetProperty(ref title, value); + } + } +} diff --git a/DownKyi/Themes/Styles/StyleListBox.xaml b/DownKyi/Themes/Styles/StyleListBox.xaml index 0cd9181..5edeebd 100644 --- a/DownKyi/Themes/Styles/StyleListBox.xaml +++ b/DownKyi/Themes/Styles/StyleListBox.xaml @@ -1,5 +1,6 @@  + + + + + + + + + + + \ No newline at end of file diff --git a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 556567c..b5cf47d 100644 --- a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -1,4 +1,5 @@ -using DownKyi.Core.Settings; +using DownKyi.Core.FileName; +using DownKyi.Core.Settings; using DownKyi.Events; using DownKyi.Models; using DownKyi.Services; @@ -6,7 +7,9 @@ using DownKyi.Utils; using Prism.Commands; using Prism.Events; using Prism.Regions; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; namespace DownKyi.ViewModels.Settings @@ -47,13 +50,6 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref selectedVideoQuality, value); } - private bool isAddVideoOrder; - public bool IsAddVideoOrder - { - get => isAddVideoOrder; - set => SetProperty(ref isAddVideoOrder, value); - } - private bool isTranscodingFlvToMp4; public bool IsTranscodingFlvToMp4 { @@ -75,29 +71,23 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref saveVideoDirectory, value); } - private bool isCreateFolderForMedia; - public bool IsCreateFolderForMedia + private ObservableCollection selectedFileName; + public ObservableCollection SelectedFileName { - get => isCreateFolderForMedia; - set => SetProperty(ref isCreateFolderForMedia, value); + get => selectedFileName; + set => SetProperty(ref selectedFileName, value); } - private bool isDownloadDanmaku; - public bool IsDownloadDanmaku + private ObservableCollection optionalFields; + public ObservableCollection OptionalFields { - get => isDownloadDanmaku; - set => SetProperty(ref isDownloadDanmaku, value); - } - - private bool isDownloadCover; - public bool IsDownloadCover - { - get => isDownloadCover; - set => SetProperty(ref isDownloadCover, value); + get => optionalFields; + set => SetProperty(ref optionalFields, value); } #endregion + public ViewVideoViewModel(IEventAggregator eventAggregator) : base(eventAggregator) { @@ -113,6 +103,15 @@ namespace DownKyi.ViewModels.Settings // 优先下载画质 VideoQualityList = new ResolutionService().GetResolution(); + // 文件命名格式 + SelectedFileName = new ObservableCollection(); + OptionalFields = new ObservableCollection(); + foreach (FileNamePart item in Enum.GetValues(typeof(FileNamePart))) + { + string display = DisplayFileNamePart(item); + OptionalFields.Add(new DisplayFileNamePart { Id = item, Title = display }); + } + #endregion } @@ -135,10 +134,6 @@ namespace DownKyi.ViewModels.Settings int quality = SettingsManager.GetInstance().GetQuality(); SelectedVideoQuality = VideoQualityList.FirstOrDefault(t => { return t.Id == quality; }); - //// 是否在下载的视频前增加序号 - //AllowStatus isAddOrder = SettingsManager.GetInstance().IsAddOrder(); - //IsAddVideoOrder = isAddOrder == AllowStatus.YES; - // 是否下载flv视频后转码为mp4 AllowStatus isTranscodingFlvToMp4 = SettingsManager.GetInstance().IsTranscodingFlvToMp4(); IsTranscodingFlvToMp4 = isTranscodingFlvToMp4 == AllowStatus.YES; @@ -150,17 +145,14 @@ namespace DownKyi.ViewModels.Settings // 默认下载目录 SaveVideoDirectory = SettingsManager.GetInstance().GetSaveVideoRootPath(); - //// 是否为不同视频分别创建文件夹 - //AllowStatus isCreateFolderForMedia = SettingsManager.GetInstance().IsCreateFolderForMedia(); - //IsCreateFolderForMedia = isCreateFolderForMedia == AllowStatus.YES; - - //// 是否在下载视频的同时下载弹幕 - //AllowStatus isDownloadDanmaku = SettingsManager.GetInstance().IsDownloadDanmaku(); - //IsDownloadDanmaku = isDownloadDanmaku == AllowStatus.YES; - - //// 是否在下载视频的同时下载封面 - //AllowStatus isDownloadCover = SettingsManager.GetInstance().IsDownloadCover(); - //IsDownloadCover = isDownloadCover == AllowStatus.YES; + // 文件命名格式 + List fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); + SelectedFileName.Clear(); + foreach (FileNamePart item in fileNameParts) + { + string display = DisplayFileNamePart(item); + SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display }); + } isOnNavigatedTo = false; } @@ -199,21 +191,6 @@ namespace DownKyi.ViewModels.Settings PublishTip(isSucceed); } - //// 是否在下载的视频前增加序号事件 - //private DelegateCommand IisAddVideoOrderCommand; - //public DelegateCommand IsAddVideoOrderCommand => IisAddVideoOrderCommand ?? (IisAddVideoOrderCommand = new DelegateCommand(ExecuteIsAddVideoOrderCommand)); - - ///// - ///// 是否在下载的视频前增加序号事件 - ///// - //private void ExecuteIsAddVideoOrderCommand() - //{ - // AllowStatus isAddOrder = IsAddVideoOrder ? AllowStatus.YES : AllowStatus.NO; - - // bool isSucceed = SettingsManager.GetInstance().IsAddOrder(isAddOrder); - // PublishTip(isSucceed); - //} - // 是否下载flv视频后转码为mp4事件 private DelegateCommand isTranscodingFlvToMp4Command; public DelegateCommand IsTranscodingFlvToMp4Command => isTranscodingFlvToMp4Command ?? (isTranscodingFlvToMp4Command = new DelegateCommand(ExecuteIsTranscodingFlvToMp4Command)); @@ -265,50 +242,55 @@ namespace DownKyi.ViewModels.Settings } } - //// 是否为不同视频分别创建文件夹事件 - //private DelegateCommand isCreateFolderForMediaCommand; - //public DelegateCommand IsCreateFolderForMediaCommand => isCreateFolderForMediaCommand ?? (isCreateFolderForMediaCommand = new DelegateCommand(ExecuteIsCreateFolderForMediaCommand)); - - ///// - ///// 是否为不同视频分别创建文件夹事件 - ///// - //private void ExecuteIsCreateFolderForMediaCommand() - //{ - // AllowStatus isCreateFolderForMedia = IsCreateFolderForMedia ? AllowStatus.YES : AllowStatus.NO; - - // bool isSucceed = SettingsManager.GetInstance().IsCreateFolderForMedia(isCreateFolderForMedia); - // PublishTip(isSucceed); - //} - - //// 是否在下载视频的同时下载弹幕事件 - //private DelegateCommand isDownloadDanmakuCommand; - //public DelegateCommand IsDownloadDanmakuCommand => isDownloadDanmakuCommand ?? (isDownloadDanmakuCommand = new DelegateCommand(ExecuteIsDownloadDanmakuCommand)); - - ///// - ///// 是否在下载视频的同时下载弹幕事件 - ///// - //private void ExecuteIsDownloadDanmakuCommand() - //{ - // AllowStatus isDownloadDanmaku = IsDownloadDanmaku ? AllowStatus.YES : AllowStatus.NO; - - // bool isSucceed = SettingsManager.GetInstance().IsDownloadDanmaku(isDownloadDanmaku); - // PublishTip(isSucceed); - //} - - //// 是否在下载视频的同时下载封面事件 - //private DelegateCommand isDownloadCoverCommand; - //public DelegateCommand IsDownloadCoverCommand => isDownloadCoverCommand ?? (isDownloadCoverCommand = new DelegateCommand(ExecuteIsDownloadCoverCommand)); - - ///// - ///// 是否在下载视频的同时下载封面事件 - ///// - //private void ExecuteIsDownloadCoverCommand() - //{ - // AllowStatus isDownloadCover = IsDownloadCover ? AllowStatus.YES : AllowStatus.NO; - - // bool isSucceed = SettingsManager.GetInstance().IsDownloadCover(isDownloadCover); - // PublishTip(isSucceed); - //} + // 选中文件名字段点击事件 + private DelegateCommand selectedFileNameCommand; + public DelegateCommand SelectedFileNameCommand => selectedFileNameCommand ?? (selectedFileNameCommand = new DelegateCommand(ExecuteSelectedFileNameCommand)); + + /// + /// 选中文件名字段点击事件 + /// + /// + private void ExecuteSelectedFileNameCommand(object parameter) + { + bool isSucceed = SelectedFileName.Remove((DisplayFileNamePart)parameter); + if (!isSucceed) + { + PublishTip(isSucceed); + return; + } + + List fileName = new List(); + foreach (DisplayFileNamePart item in SelectedFileName) + { + fileName.Add(item.Id); + } + + isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); + PublishTip(isSucceed); + } + + // 可选文件名字段点击事件 + private DelegateCommand optionalFieldsCommand; + public DelegateCommand OptionalFieldsCommand => optionalFieldsCommand ?? (optionalFieldsCommand = new DelegateCommand(ExecuteOptionalFieldsCommand)); + + /// + /// 可选文件名字段点击事件 + /// + /// + private void ExecuteOptionalFieldsCommand(object parameter) + { + SelectedFileName.Add((DisplayFileNamePart)parameter); + + List fileName = new List(); + foreach (DisplayFileNamePart item in SelectedFileName) + { + fileName.Add(item.Id); + } + + bool isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); + PublishTip(isSucceed); + } + #endregion @@ -379,5 +361,51 @@ namespace DownKyi.ViewModels.Settings } } + /// + /// 文件名字段显示 + /// + /// + /// + private string DisplayFileNamePart(FileNamePart item) + { + string display = string.Empty; + switch (item) + { + case FileNamePart.ORDER: + display = DictionaryResource.GetString("DisplayOrder"); + break; + case FileNamePart.MAIN_TITLE: + display = DictionaryResource.GetString("DisplayMainTitle"); + break; + case FileNamePart.PAGE_TITLE: + display = DictionaryResource.GetString("DisplayPageTitle"); + break; + case FileNamePart.VIDEO_ZONE: + display = DictionaryResource.GetString("DisplayVideoZone"); + break; + case FileNamePart.AUDIO_QUALITY: + display = DictionaryResource.GetString("DisplayAudioQuality"); + break; + case FileNamePart.VIDEO_QUALITY: + display = DictionaryResource.GetString("DisplayVideoQuality"); + break; + case FileNamePart.VIDEO_CODEC: + display = DictionaryResource.GetString("DisplayVideoCodec"); + break; + } + + if (((int)item) >= 100) + { + display = HyphenSeparated.Hyphen[(int)item]; + } + + if (display == " ") + { + display = DictionaryResource.GetString("DisplaySpace"); + } + + return display; + } + } } diff --git a/DownKyi/Views/Settings/ViewVideo.xaml b/DownKyi/Views/Settings/ViewVideo.xaml index 4910986..49d2a53 100644 --- a/DownKyi/Views/Settings/ViewVideo.xaml +++ b/DownKyi/Views/Settings/ViewVideo.xaml @@ -129,6 +129,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +