文件命名格式中,时间格式可设置

croire 3 years ago
parent c1ea829215
commit 778d2829fa

@ -16,5 +16,6 @@ namespace DownKyi.Core.Settings.Models
public List<string> HistoryVideoRootPaths { get; set; } // 历史视频保存路径
public AllowStatus IsUseSaveVideoRootPath { get; set; } // 是否使用默认视频保存路径
public List<FileNamePart> FileNameParts { get; set; } // 文件命名格式
public string FileNamePartTimeFormat { get; set; } // 文件命名中的时间格式
}
}

@ -44,6 +44,9 @@ namespace DownKyi.Core.Settings
FileNamePart.VIDEO_CODEC,
};
// 文件命名中的时间格式
private readonly string fileNamePartTimeFormat = "yyyy-MM-dd";
/// <summary>
/// 获取优先下载的视频编码
/// </summary>
@ -260,5 +263,32 @@ namespace DownKyi.Core.Settings
return SetSettings();
}
/// <summary>
/// 获取文件命名中的时间格式
/// </summary>
/// <returns></returns>
public string GetFileNamePartTimeFormat()
{
appSettings = GetSettings();
if (appSettings.Video.FileNamePartTimeFormat == null || appSettings.Video.FileNamePartTimeFormat == string.Empty)
{
// 第一次获取,先设置默认值
SetFileNamePartTimeFormat(fileNamePartTimeFormat);
return fileNamePartTimeFormat;
}
return appSettings.Video.FileNamePartTimeFormat;
}
/// <summary>
/// 设置文件命名中的时间格式
/// </summary>
/// <param name="fileNamePartTimeFormat"></param>
/// <returns></returns>
public bool SetFileNamePartTimeFormat(string fileNamePartTimeFormat)
{
appSettings.Video.FileNamePartTimeFormat = fileNamePartTimeFormat;
return SetSettings();
}
}
}

@ -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);
}

@ -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);
}

@ -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);
}

@ -105,8 +105,21 @@ namespace DownKyi.ViewModels.Settings
set => SetProperty(ref selectedOptionalField, value);
}
#endregion
private List<string> fileNamePartTimeFormatList;
public List<string> 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<string>
{
"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<object> fileNamePartTimeFormatCommand;
public DelegateCommand<object> FileNamePartTimeFormatCommand => fileNamePartTimeFormatCommand ?? (fileNamePartTimeFormatCommand = new DelegateCommand<object>(ExecuteFileNamePartTimeFormatCommand));
/// <summary>
/// 文件命名中的时间格式事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteFileNamePartTimeFormatCommand(object parameter)
{
if (!(parameter is string timeFormat)) { return; }
bool isSucceed = SettingsManager.GetInstance().SetFileNamePartTimeFormat(timeFormat);
PublishTip(isSucceed);
}
#endregion

@ -178,20 +178,20 @@
Grid.Column="0"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FileName}" />
Text="{DynamicResource OptionalFields}" />
<ListBox
x:Name="nameSelectedFileName"
Name="nameOptionalFields"
Grid.Row="0"
Grid.Column="1"
MinHeight="30"
Margin="0,0,0,20"
ItemContainerStyle="{StaticResource TagItem2Style}"
ItemsSource="{Binding SelectedFileName, Mode=TwoWay}"
ItemsSource="{Binding OptionalFields, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOptionalField}"
SelectionMode="Single"
Style="{StaticResource Tag2Style}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectedFileNameCommand}" CommandParameter="{Binding ElementName=nameSelectedFileName, Path=SelectedItem}" />
<i:InvokeCommandAction Command="{Binding OptionalFieldsCommand}" CommandParameter="{Binding ElementName=nameOptionalFields, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
@ -201,23 +201,49 @@
Grid.Column="0"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource OptionalFields}" />
Text="{DynamicResource FileName}" />
<ListBox
Name="nameOptionalFields"
x:Name="nameSelectedFileName"
Grid.Row="1"
Grid.Column="1"
MinHeight="30"
ItemContainerStyle="{StaticResource TagItem2Style}"
ItemsSource="{Binding OptionalFields, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOptionalField}"
ItemsSource="{Binding SelectedFileName, Mode=TwoWay}"
SelectionMode="Single"
Style="{StaticResource Tag2Style}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding OptionalFieldsCommand}" CommandParameter="{Binding ElementName=nameOptionalFields, Path=SelectedItem}" />
<i:InvokeCommandAction Command="{Binding SelectedFileNameCommand}" CommandParameter="{Binding ElementName=nameSelectedFileName, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<StackPanel
Grid.Row="2"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="时间格式:" />
<ComboBox
Name="nameFileNamePartTimeFormat"
Width="120"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
ItemsSource="{Binding FileNamePartTimeFormatList}"
SelectedItem="{Binding SelectedFileNamePartTimeFormat}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding FileNamePartTimeFormatCommand}" CommandParameter="{Binding ElementName=nameFileNamePartTimeFormat, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<Button
Grid.Row="2"
Grid.Column="1"

Loading…
Cancel
Save