diff --git a/DownKyi.Core/DownKyi.Core.csproj b/DownKyi.Core/DownKyi.Core.csproj index 76d1fe3..615b25e 100644 --- a/DownKyi.Core/DownKyi.Core.csproj +++ b/DownKyi.Core/DownKyi.Core.csproj @@ -291,6 +291,7 @@ + diff --git a/DownKyi.Core/FileName/FileName.cs b/DownKyi.Core/FileName/FileName.cs index 2e8684d..356a9e0 100644 --- a/DownKyi.Core/FileName/FileName.cs +++ b/DownKyi.Core/FileName/FileName.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Text.RegularExpressions; namespace DownKyi.Core.FileName @@ -6,7 +7,7 @@ namespace DownKyi.Core.FileName public class FileName { private readonly List nameParts; - private int order = -1; + private string order = "ORDER"; private string section = "SECTION"; private string mainTitle = "MAIN_TITLE"; private string pageTitle = "PAGE_TITLE"; @@ -36,7 +37,15 @@ namespace DownKyi.Core.FileName public FileName SetOrder(int order) { - this.order = order; + this.order = order.ToString(); + return this; + } + + public FileName SetOrder(int order, int count) + { + int length = Math.Abs(count).ToString().Length; + this.order = order.ToString("D" + length); + return this; } @@ -127,14 +136,7 @@ namespace DownKyi.Core.FileName switch (part) { case FileNamePart.ORDER: - if (order != -1) - { - path += order; - } - else - { - path += "ORDER"; - } + path += order; break; case FileNamePart.SECTION: path += section; diff --git a/DownKyi.Core/Settings/Models/VideoSettings.cs b/DownKyi.Core/Settings/Models/VideoSettings.cs index c444a42..0cf431e 100644 --- a/DownKyi.Core/Settings/Models/VideoSettings.cs +++ b/DownKyi.Core/Settings/Models/VideoSettings.cs @@ -18,5 +18,6 @@ namespace DownKyi.Core.Settings.Models public VideoContentSettings VideoContent { get; set; } = null; // 下载内容 public List FileNameParts { get; set; } = null; // 文件命名格式 public string FileNamePartTimeFormat { get; set; } = null; // 文件命名中的时间格式 + public OrderFormat OrderFormat { get; set; } = OrderFormat.NOT_SET; // 文件命名中的序号格式 } } diff --git a/DownKyi.Core/Settings/OrderFormat.cs b/DownKyi.Core/Settings/OrderFormat.cs new file mode 100644 index 0000000..f496835 --- /dev/null +++ b/DownKyi.Core/Settings/OrderFormat.cs @@ -0,0 +1,9 @@ +namespace DownKyi.Core.Settings +{ + public enum OrderFormat + { + NOT_SET = 0, + NATURAL, // 自然数 + LEADING_ZEROS, // 前导零填充 + } +} diff --git a/DownKyi.Core/Settings/SettingsManager.Video.cs b/DownKyi.Core/Settings/SettingsManager.Video.cs index 8caa05e..7a88cc4 100644 --- a/DownKyi.Core/Settings/SettingsManager.Video.cs +++ b/DownKyi.Core/Settings/SettingsManager.Video.cs @@ -51,6 +51,9 @@ namespace DownKyi.Core.Settings // 文件命名中的时间格式 private readonly string fileNamePartTimeFormat = "yyyy-MM-dd"; + // 文件命名中的序号格式 + private readonly OrderFormat orderFormat = OrderFormat.NATURAL; + /// /// 获取优先下载的视频编码 /// @@ -321,5 +324,32 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取文件命名中的序号格式 + /// + /// + public OrderFormat GetOrderFormat() + { + appSettings = GetSettings(); + if (appSettings.Video.OrderFormat == OrderFormat.NOT_SET) + { + // 第一次获取,先设置默认值 + SetOrderFormat(orderFormat); + return orderFormat; + } + return appSettings.Video.OrderFormat; + } + + /// + /// 设置文件命名中的序号格式 + /// + /// + /// + public bool SetOrderFormat(OrderFormat orderFormat) + { + appSettings.Video.OrderFormat = orderFormat; + return SetSettings(); + } + } } diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index cc4e6b2..21760fc 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -113,6 +113,7 @@ + diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index e468434..91d20c1 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -221,6 +221,9 @@ UP主昵称 恢复默认 时间格式: + 序号格式: + 自然数 + 前导零填充 弹幕 按类型屏蔽 diff --git a/DownKyi/Models/OrderFormatDisplay.cs b/DownKyi/Models/OrderFormatDisplay.cs new file mode 100644 index 0000000..5e2a1a3 --- /dev/null +++ b/DownKyi/Models/OrderFormatDisplay.cs @@ -0,0 +1,10 @@ +using DownKyi.Core.Settings; + +namespace DownKyi.Models +{ + public class OrderFormatDisplay + { + public string Name { get; set; } + public OrderFormat OrderFormat { get; set; } + } +} diff --git a/DownKyi/Services/Download/AddToDownloadService.cs b/DownKyi/Services/Download/AddToDownloadService.cs index 605ec55..c90519d 100644 --- a/DownKyi/Services/Download/AddToDownloadService.cs +++ b/DownKyi/Services/Download/AddToDownloadService.cs @@ -304,8 +304,7 @@ namespace DownKyi.Services.Download // 文件路径 List fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); - FileName fileName = FileName.Builder(fileNameParts) - .SetOrder(page.Order) + FileName fileName = FileName.Builder(fileNameParts) .SetSection(Format.FormatFileName(sectionName)) .SetMainTitle(Format.FormatFileName(videoInfoView.Title)) .SetPageTitle(Format.FormatFileName(page.Name)) @@ -319,6 +318,20 @@ namespace DownKyi.Services.Download .SetCid(page.Cid) .SetUpMid(page.Owner.Mid) .SetUpName(Format.FormatFileName(page.Owner.Name)); + + // 序号设置 + OrderFormat orderFormat = SettingsManager.GetInstance().GetOrderFormat(); + switch (orderFormat) + { + case OrderFormat.NATURAL: + fileName.SetOrder(page.Order); + break; + case OrderFormat.LEADING_ZEROS: + fileName.SetOrder(page.Order, section.VideoPages.Count); + break; + } + + // 合成绝对路径 string filePath = Path.Combine(directory, fileName.RelativePath()); // 视频类别 diff --git a/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs b/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs index 0d195af..eee40ca 100644 --- a/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs @@ -84,10 +84,10 @@ namespace DownKyi.ViewModels.Settings // 解析范围 ParseScopes = new List() { - new ParseScopeDisplay{ Name =DictionaryResource.GetString("ParseNone"),ParseScope=ParseScope.NONE}, - new ParseScopeDisplay{ Name =DictionaryResource.GetString("ParseSelectedItem"),ParseScope=ParseScope.SELECTED_ITEM}, - new ParseScopeDisplay{ Name =DictionaryResource.GetString("ParseCurrentSection"),ParseScope=ParseScope.CURRENT_SECTION}, - new ParseScopeDisplay{ Name =DictionaryResource.GetString("ParseAll"),ParseScope=ParseScope.ALL} + new ParseScopeDisplay{ Name = DictionaryResource.GetString("ParseNone"), ParseScope = ParseScope.NONE }, + new ParseScopeDisplay{ Name = DictionaryResource.GetString("ParseSelectedItem"), ParseScope = ParseScope.SELECTED_ITEM }, + new ParseScopeDisplay{ Name = DictionaryResource.GetString("ParseCurrentSection"), ParseScope = ParseScope.CURRENT_SECTION }, + new ParseScopeDisplay{ Name = DictionaryResource.GetString("ParseAll"), ParseScope = ParseScope.ALL } }; #endregion diff --git a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 5fffe18..a7ffd52 100644 --- a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -3,6 +3,7 @@ using DownKyi.Core.FileName; using DownKyi.Core.Settings; using DownKyi.Core.Settings.Models; using DownKyi.Events; +using DownKyi.Models; using DownKyi.Utils; using Prism.Commands; using Prism.Events; @@ -163,6 +164,20 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref selectedFileNamePartTimeFormat, value); } + private List orderFormatList; + public List OrderFormatList + { + get => orderFormatList; + set => SetProperty(ref orderFormatList, value); + } + + private OrderFormatDisplay orderFormatDisplay; + public OrderFormatDisplay OrderFormatDisplay + { + get => orderFormatDisplay; + set => SetProperty(ref orderFormatDisplay, value); + } + #endregion public ViewVideoViewModel(IEventAggregator eventAggregator) : base(eventAggregator) @@ -216,6 +231,13 @@ namespace DownKyi.ViewModels.Settings "yyyy.MM.dd", }; + // 文件命名中的序号格式 + OrderFormatList = new List + { + new OrderFormatDisplay{ Name = DictionaryResource.GetString("OrderFormatNatural"), OrderFormat = OrderFormat.NATURAL }, + new OrderFormatDisplay{ Name = DictionaryResource.GetString("OrderFormatLeadingZeros"), OrderFormat = OrderFormat.LEADING_ZEROS }, + }; + #endregion } @@ -283,6 +305,10 @@ namespace DownKyi.ViewModels.Settings // 文件命名中的时间格式 SelectedFileNamePartTimeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); + // 文件命名中的序号格式 + OrderFormat orderFormat = SettingsManager.GetInstance().GetOrderFormat(); + OrderFormatDisplay = OrderFormatList.FirstOrDefault(t => { return t.OrderFormat == orderFormat; }); + isOnNavigatedTo = false; } @@ -625,6 +651,22 @@ namespace DownKyi.ViewModels.Settings PublishTip(isSucceed); } + // 文件命名中的序号格式事件 + private DelegateCommand orderFormatCommand; + public DelegateCommand OrderFormatCommand => orderFormatCommand ?? (orderFormatCommand = new DelegateCommand(ExecuteOrderFormatCommandCommand)); + + /// + /// 文件命名中的序号格式事件 + /// + /// + private void ExecuteOrderFormatCommandCommand(object parameter) + { + if (!(parameter is OrderFormatDisplay orderFormatDisplay)) { return; } + + bool isSucceed = SettingsManager.GetInstance().SetOrderFormat(orderFormatDisplay.OrderFormat); + PublishTip(isSucceed); + } + #endregion /// diff --git a/DownKyi/Views/Settings/ViewVideo.xaml b/DownKyi/Views/Settings/ViewVideo.xaml index 050c6a2..4511b48 100644 --- a/DownKyi/Views/Settings/ViewVideo.xaml +++ b/DownKyi/Views/Settings/ViewVideo.xaml @@ -282,43 +282,78 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +