diff --git a/DownKyi.Core/Settings/Models/VideoSettings.cs b/DownKyi.Core/Settings/Models/VideoSettings.cs index d5fe834..63d3f82 100644 --- a/DownKyi.Core/Settings/Models/VideoSettings.cs +++ b/DownKyi.Core/Settings/Models/VideoSettings.cs @@ -16,5 +16,6 @@ namespace DownKyi.Core.Settings.Models public List HistoryVideoRootPaths { get; set; } // 历史视频保存路径 public AllowStatus IsUseSaveVideoRootPath { get; set; } // 是否使用默认视频保存路径 public List FileNameParts { get; set; } // 文件命名格式 + public string FileNamePartTimeFormat { get; set; } // 文件命名中的时间格式 } } diff --git a/DownKyi.Core/Settings/SettingsManager.Video.cs b/DownKyi.Core/Settings/SettingsManager.Video.cs index aa50f59..c5b9af3 100644 --- a/DownKyi.Core/Settings/SettingsManager.Video.cs +++ b/DownKyi.Core/Settings/SettingsManager.Video.cs @@ -44,6 +44,9 @@ namespace DownKyi.Core.Settings FileNamePart.VIDEO_CODEC, }; + // 文件命名中的时间格式 + private readonly string fileNamePartTimeFormat = "yyyy-MM-dd"; + /// /// 获取优先下载的视频编码 /// @@ -260,5 +263,32 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取文件命名中的时间格式 + /// + /// + public string GetFileNamePartTimeFormat() + { + appSettings = GetSettings(); + if (appSettings.Video.FileNamePartTimeFormat == null || appSettings.Video.FileNamePartTimeFormat == string.Empty) + { + // 第一次获取,先设置默认值 + SetFileNamePartTimeFormat(fileNamePartTimeFormat); + return fileNamePartTimeFormat; + } + return appSettings.Video.FileNamePartTimeFormat; + } + + /// + /// 设置文件命名中的时间格式 + /// + /// + /// + public bool SetFileNamePartTimeFormat(string fileNamePartTimeFormat) + { + appSettings.Video.FileNamePartTimeFormat = fileNamePartTimeFormat; + return SetSettings(); + } + } } diff --git a/DownKyi/Services/BangumiInfoService.cs b/DownKyi/Services/BangumiInfoService.cs index a11443f..869c9fe 100644 --- a/DownKyi/Services/BangumiInfoService.cs +++ b/DownKyi/Services/BangumiInfoService.cs @@ -3,6 +3,7 @@ using DownKyi.Core.BiliApi.Bangumi.Models; using DownKyi.Core.BiliApi.BiliUtils; using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.BiliApi.VideoStream.Models; +using DownKyi.Core.Settings; using DownKyi.Core.Storage; using DownKyi.Core.Utils; using DownKyi.Utils; @@ -120,10 +121,12 @@ namespace DownKyi.Services }; } + // 文件命名中的时间格式 + string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); // 视频发布时间 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime dateTime = startTime.AddSeconds(episode.PubTime); - page.PublishTime = dateTime.ToString("yyyy-MM-dd"); + page.PublishTime = dateTime.ToString(timeFormat); pages.Add(page); } diff --git a/DownKyi/Services/CheeseInfoService.cs b/DownKyi/Services/CheeseInfoService.cs index a49e925..7f9fab7 100644 --- a/DownKyi/Services/CheeseInfoService.cs +++ b/DownKyi/Services/CheeseInfoService.cs @@ -3,6 +3,7 @@ using DownKyi.Core.BiliApi.Cheese; using DownKyi.Core.BiliApi.Cheese.Models; using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.BiliApi.VideoStream.Models; +using DownKyi.Core.Settings; using DownKyi.Core.Storage; using DownKyi.Core.Utils; using DownKyi.Utils; @@ -88,10 +89,12 @@ namespace DownKyi.Services }; } + // 文件命名中的时间格式 + string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); // 视频发布时间 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime dateTime = startTime.AddSeconds(episode.ReleaseDate); - page.PublishTime = dateTime.ToString("yyyy-MM-dd"); + page.PublishTime = dateTime.ToString(timeFormat); pages.Add(page); } diff --git a/DownKyi/Services/VideoInfoService.cs b/DownKyi/Services/VideoInfoService.cs index bd927a3..ede4e4d 100644 --- a/DownKyi/Services/VideoInfoService.cs +++ b/DownKyi/Services/VideoInfoService.cs @@ -2,6 +2,7 @@ using DownKyi.Core.BiliApi.Video; using DownKyi.Core.BiliApi.Video.Models; using DownKyi.Core.BiliApi.VideoStream; +using DownKyi.Core.Settings; using DownKyi.Core.Storage; using DownKyi.Core.Utils; using DownKyi.ViewModels.PageViewModels; @@ -96,10 +97,12 @@ namespace DownKyi.Services }; } + // 文件命名中的时间格式 + string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); // 视频发布时间 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime dateTime = startTime.AddSeconds(videoView.Pubdate); - videoPage.PublishTime = dateTime.ToString("yyyy-MM-dd"); + videoPage.PublishTime = dateTime.ToString(timeFormat); videoPages.Add(videoPage); } diff --git a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 002d20f..1a78dca 100644 --- a/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -105,8 +105,21 @@ namespace DownKyi.ViewModels.Settings set => SetProperty(ref selectedOptionalField, value); } - #endregion + private List fileNamePartTimeFormatList; + public List FileNamePartTimeFormatList + { + get => fileNamePartTimeFormatList; + set => SetProperty(ref fileNamePartTimeFormatList, value); + } + + private string selectedFileNamePartTimeFormat; + public string SelectedFileNamePartTimeFormat + { + get => selectedFileNamePartTimeFormat; + set => SetProperty(ref selectedFileNamePartTimeFormat, value); + } + #endregion public ViewVideoViewModel(IEventAggregator eventAggregator) : base(eventAggregator) { @@ -138,6 +151,13 @@ namespace DownKyi.ViewModels.Settings SelectedOptionalField = -1; + // 文件命名中的时间格式 + FileNamePartTimeFormatList = new List + { + "yyyy-MM-dd", + "yyyy.MM.dd", + }; + #endregion } @@ -184,6 +204,9 @@ namespace DownKyi.ViewModels.Settings SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display }); } + // 文件命名中的时间格式 + SelectedFileNamePartTimeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); + isOnNavigatedTo = false; } @@ -313,6 +336,8 @@ namespace DownKyi.ViewModels.Settings isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); PublishTip(isSucceed); + + SelectedOptionalField = -1; } // 可选文件名字段点击事件 @@ -363,8 +388,25 @@ namespace DownKyi.ViewModels.Settings string display = DisplayFileNamePart(item); SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display }); } + + SelectedOptionalField = -1; } + // 文件命名中的时间格式事件 + private DelegateCommand fileNamePartTimeFormatCommand; + public DelegateCommand FileNamePartTimeFormatCommand => fileNamePartTimeFormatCommand ?? (fileNamePartTimeFormatCommand = new DelegateCommand(ExecuteFileNamePartTimeFormatCommand)); + + /// + /// 文件命名中的时间格式事件 + /// + /// + private void ExecuteFileNamePartTimeFormatCommand(object parameter) + { + if (!(parameter is string timeFormat)) { return; } + + bool isSucceed = SettingsManager.GetInstance().SetFileNamePartTimeFormat(timeFormat); + PublishTip(isSucceed); + } #endregion diff --git a/DownKyi/Views/Settings/ViewVideo.xaml b/DownKyi/Views/Settings/ViewVideo.xaml index bd6b8b8..3efb045 100644 --- a/DownKyi/Views/Settings/ViewVideo.xaml +++ b/DownKyi/Views/Settings/ViewVideo.xaml @@ -178,20 +178,20 @@ Grid.Column="0" FontSize="12" Foreground="{DynamicResource BrushTextDark}" - Text="{DynamicResource FileName}" /> + Text="{DynamicResource OptionalFields}" /> - + @@ -201,23 +201,49 @@ Grid.Column="0" FontSize="12" Foreground="{DynamicResource BrushTextDark}" - Text="{DynamicResource OptionalFields}" /> + Text="{DynamicResource FileName}" /> - + + + + + + + + + + + +