新增文件命名模块中序号格式设置

croire 3 years ago
parent d449c42bec
commit 4d7ffe112f

@ -291,6 +291,7 @@
<Compile Include="Logging\LogManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings\Models\VideoContentSettings.cs" />
<Compile Include="Settings\OrderFormat.cs" />
<Compile Include="Settings\ParseScope.cs" />
<Compile Include="Settings\SettingsManager.Video.cs" />
<Compile Include="Settings\SettingsManager.Basic.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<FileNamePart> 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;

@ -18,5 +18,6 @@ namespace DownKyi.Core.Settings.Models
public VideoContentSettings VideoContent { get; set; } = null; // 下载内容
public List<FileNamePart> FileNameParts { get; set; } = null; // 文件命名格式
public string FileNamePartTimeFormat { get; set; } = null; // 文件命名中的时间格式
public OrderFormat OrderFormat { get; set; } = OrderFormat.NOT_SET; // 文件命名中的序号格式
}
}

@ -0,0 +1,9 @@
namespace DownKyi.Core.Settings
{
public enum OrderFormat
{
NOT_SET = 0,
NATURAL, // 自然数
LEADING_ZEROS, // 前导零填充
}
}

@ -51,6 +51,9 @@ namespace DownKyi.Core.Settings
// 文件命名中的时间格式
private readonly string fileNamePartTimeFormat = "yyyy-MM-dd";
// 文件命名中的序号格式
private readonly OrderFormat orderFormat = OrderFormat.NATURAL;
/// <summary>
/// 获取优先下载的视频编码
/// </summary>
@ -321,5 +324,32 @@ namespace DownKyi.Core.Settings
return SetSettings();
}
/// <summary>
/// 获取文件命名中的序号格式
/// </summary>
/// <returns></returns>
public OrderFormat GetOrderFormat()
{
appSettings = GetSettings();
if (appSettings.Video.OrderFormat == OrderFormat.NOT_SET)
{
// 第一次获取,先设置默认值
SetOrderFormat(orderFormat);
return orderFormat;
}
return appSettings.Video.OrderFormat;
}
/// <summary>
/// 设置文件命名中的序号格式
/// </summary>
/// <param name="orderFormat"></param>
/// <returns></returns>
public bool SetOrderFormat(OrderFormat orderFormat)
{
appSettings.Video.OrderFormat = orderFormat;
return SetSettings();
}
}
}

@ -113,6 +113,7 @@
<Compile Include="Models\Downloaded.cs" />
<Compile Include="Models\Downloading.cs" />
<Compile Include="Models\DownloadStatus.cs" />
<Compile Include="Models\OrderFormatDisplay.cs" />
<Compile Include="Services\Download\AddToDownloadService.cs" />
<Compile Include="Services\Download\DownloadStorageService.cs" />
<Compile Include="Services\SearchService.cs" />

@ -221,6 +221,9 @@
<system:String x:Key="DisplayUpName">UP主昵称</system:String>
<system:String x:Key="Reset">恢复默认</system:String>
<system:String x:Key="FileNameTimeFormat">时间格式:</system:String>
<system:String x:Key="OrderFormat">序号格式:</system:String>
<system:String x:Key="OrderFormatNatural">自然数</system:String>
<system:String x:Key="OrderFormatLeadingZeros">前导零填充</system:String>
<system:String x:Key="SettingDanmaku">弹幕</system:String>
<system:String x:Key="FilterType">按类型屏蔽</system:String>

@ -0,0 +1,10 @@
using DownKyi.Core.Settings;
namespace DownKyi.Models
{
public class OrderFormatDisplay
{
public string Name { get; set; }
public OrderFormat OrderFormat { get; set; }
}
}

@ -304,8 +304,7 @@ namespace DownKyi.Services.Download
// 文件路径
List<FileNamePart> 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());
// 视频类别

@ -84,10 +84,10 @@ namespace DownKyi.ViewModels.Settings
// 解析范围
ParseScopes = new List<ParseScopeDisplay>()
{
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

@ -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<OrderFormatDisplay> orderFormatList;
public List<OrderFormatDisplay> 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<OrderFormatDisplay>
{
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<object> orderFormatCommand;
public DelegateCommand<object> OrderFormatCommand => orderFormatCommand ?? (orderFormatCommand = new DelegateCommand<object>(ExecuteOrderFormatCommandCommand));
/// <summary>
/// 文件命名中的序号格式事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteOrderFormatCommandCommand(object parameter)
{
if (!(parameter is OrderFormatDisplay orderFormatDisplay)) { return; }
bool isSucceed = SettingsManager.GetInstance().SetOrderFormat(orderFormatDisplay.OrderFormat);
PublishTip(isSucceed);
}
#endregion
/// <summary>

@ -282,43 +282,78 @@
</ListBox.ItemContainerStyle>
</ListBox>
<StackPanel
<Grid
Grid.Row="2"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<TextBlock
Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FileNameTimeFormat}" />
<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>
<StackPanel
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource OrderFormat}" />
<ComboBox
Name="nameOrderFormat"
Width="120"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
DisplayMemberPath="Name"
ItemsSource="{Binding OrderFormatList}"
SelectedItem="{Binding OrderFormatDisplay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding OrderFormatCommand}" CommandParameter="{Binding ElementName=nameOrderFormat, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<Button
Grid.Column="2"
Width="75"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Command="{Binding ResetCommand}"
Content="{DynamicResource Reset}"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FileNameTimeFormat}" />
<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>
Style="{StaticResource BtnBorderStyle}" />
</Grid>
<Button
Grid.Row="2"
Grid.Column="1"
Width="75"
Margin="0,20,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Command="{Binding ResetCommand}"
Content="{DynamicResource Reset}"
FontSize="12"
Style="{StaticResource BtnBorderStyle}" />
</Grid>
</GroupBox>

Loading…
Cancel
Save