fix: 修复工具箱错误

This commit is contained in:
姚彪
2023-12-26 22:19:40 +08:00
parent 2aa0ba2a84
commit 4d48dc8409
6 changed files with 115 additions and 144 deletions

View File

@@ -15,36 +15,36 @@ public class ViewBiliHelperViewModel : ViewModelBase
#region
private string avid;
private string _avid;
public string Avid
{
get => avid;
set => SetProperty(ref avid, value);
get => _avid;
set => SetProperty(ref _avid, value);
}
private string bvid;
private string _bvid;
public string Bvid
{
get => bvid;
set => SetProperty(ref bvid, value);
get => _bvid;
set => SetProperty(ref _bvid, value);
}
private string danmakuUserID;
private string _danmakuUserId;
public string DanmakuUserID
public string DanmakuUserId
{
get => danmakuUserID;
set => SetProperty(ref danmakuUserID, value);
get => _danmakuUserId;
set => SetProperty(ref _danmakuUserId, value);
}
private string userMid;
private string _userMid;
public string UserMid
{
get => userMid;
set => SetProperty(ref userMid, value);
get => _userMid;
set => SetProperty(ref _userMid, value);
}
#endregion
@@ -59,10 +59,9 @@ public class ViewBiliHelperViewModel : ViewModelBase
#region
// 输入avid事件
private DelegateCommand<string> avidCommand;
private DelegateCommand<string>? _avidCommand;
public DelegateCommand<string> AvidCommand =>
avidCommand ?? (avidCommand = new DelegateCommand<string>(ExecuteAvidCommand));
public DelegateCommand<string> AvidCommand => _avidCommand ??= new DelegateCommand<string>(ExecuteAvidCommand);
/// <summary>
/// 输入avid事件
@@ -79,7 +78,7 @@ public class ViewBiliHelperViewModel : ViewModelBase
return;
}
long avid = ParseEntrance.GetAvId(parameter);
var avid = ParseEntrance.GetAvId(parameter);
if (avid == -1)
{
return;
@@ -89,10 +88,9 @@ public class ViewBiliHelperViewModel : ViewModelBase
}
// 输入bvid事件
private DelegateCommand<string> bvidCommand;
private DelegateCommand<string>? _bvidCommand;
public DelegateCommand<string> BvidCommand =>
bvidCommand ?? (bvidCommand = new DelegateCommand<string>(ExecuteBvidCommand));
public DelegateCommand<string> BvidCommand => _bvidCommand ??= new DelegateCommand<string>(ExecuteBvidCommand);
/// <summary>
/// 输入bvid事件
@@ -112,16 +110,15 @@ public class ViewBiliHelperViewModel : ViewModelBase
await Task.Run(() =>
{
ulong avid = BvId.Bv2Av(parameter);
var avid = BvId.Bv2Av(parameter);
Avid = $"av{avid}";
});
}
// 访问网页事件
private DelegateCommand gotoWebCommand;
private DelegateCommand? _gotoWebCommand;
public DelegateCommand GotoWebCommand =>
gotoWebCommand ?? (gotoWebCommand = new DelegateCommand(ExecuteGotoWebCommand));
public DelegateCommand GotoWebCommand => _gotoWebCommand ??= new DelegateCommand(ExecuteGotoWebCommand);
/// <summary>
/// 访问网页事件
@@ -133,11 +130,9 @@ public class ViewBiliHelperViewModel : ViewModelBase
}
// 查询弹幕发送者事件
private DelegateCommand findDanmakuSenderCommand;
private DelegateCommand? _findDanmakuSenderCommand;
public DelegateCommand FindDanmakuSenderCommand => findDanmakuSenderCommand ??
(findDanmakuSenderCommand =
new DelegateCommand(ExecuteFindDanmakuSenderCommand));
public DelegateCommand FindDanmakuSenderCommand => _findDanmakuSenderCommand ??= new DelegateCommand(ExecuteFindDanmakuSenderCommand);
/// <summary>
/// 查询弹幕发送者事件
@@ -148,7 +143,7 @@ public class ViewBiliHelperViewModel : ViewModelBase
{
try
{
UserMid = DanmakuSender.FindDanmakuSender(DanmakuUserID);
UserMid = DanmakuSender.FindDanmakuSender(DanmakuUserId);
}
catch (Exception e)
{
@@ -161,11 +156,9 @@ public class ViewBiliHelperViewModel : ViewModelBase
}
// 访问用户空间事件
private DelegateCommand visitUserSpaceCommand;
private DelegateCommand? _visitUserSpaceCommand;
public DelegateCommand VisitUserSpaceCommand => visitUserSpaceCommand ??
(visitUserSpaceCommand =
new DelegateCommand(ExecuteVisitUserSpaceCommand));
public DelegateCommand VisitUserSpaceCommand => _visitUserSpaceCommand ??= new DelegateCommand(ExecuteVisitUserSpaceCommand);
/// <summary>
/// 访问用户空间事件

View File

@@ -1,5 +1,7 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.VisualTree;
using DownKyi.Core.FFMpeg;
using DownKyi.Events;
using DownKyi.Utils;
@@ -13,56 +15,56 @@ public class ViewDelogoViewModel : ViewModelBase
public const string Tag = "PageToolboxDelogo";
// 是否正在执行去水印任务
private bool isDelogo = false;
private bool _isDelogo = false;
#region
private string videoPath;
private string _videoPath;
public string VideoPath
{
get { return videoPath; }
set { SetProperty(ref videoPath, value); }
get => _videoPath;
set => SetProperty(ref _videoPath, value);
}
private int logoWidth;
private int _logoWidth;
public int LogoWidth
{
get { return logoWidth; }
set { SetProperty(ref logoWidth, value); }
get => _logoWidth;
set => SetProperty(ref _logoWidth, value);
}
private int logoHeight;
private int _logoHeight;
public int LogoHeight
{
get { return logoHeight; }
set { SetProperty(ref logoHeight, value); }
get => _logoHeight;
set => SetProperty(ref _logoHeight, value);
}
private int logoX;
private int _logoX;
public int LogoX
{
get { return logoX; }
set { SetProperty(ref logoX, value); }
get => _logoX;
set => SetProperty(ref _logoX, value);
}
private int logoY;
private int _logoY;
public int LogoY
{
get { return logoY; }
set { SetProperty(ref logoY, value); }
get => _logoY;
set => SetProperty(ref _logoY, value);
}
private string status;
private string _status;
public string Status
{
get { return status; }
set { SetProperty(ref status, value); }
get => _status;
set => SetProperty(ref _status, value);
}
#endregion
@@ -84,17 +86,16 @@ public class ViewDelogoViewModel : ViewModelBase
#region
// 选择视频事件
private DelegateCommand selectVideoCommand;
private DelegateCommand? _selectVideoCommand;
public DelegateCommand SelectVideoCommand =>
selectVideoCommand ?? (selectVideoCommand = new DelegateCommand(ExecuteSelectVideoCommand));
public DelegateCommand SelectVideoCommand => _selectVideoCommand ??= new DelegateCommand(ExecuteSelectVideoCommand);
/// <summary>
/// 选择视频事件
/// </summary>
private async void ExecuteSelectVideoCommand()
{
if (isDelogo)
if (_isDelogo)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished"));
return;
@@ -104,17 +105,16 @@ public class ViewDelogoViewModel : ViewModelBase
}
// 去水印事件
private DelegateCommand delogoCommand;
private DelegateCommand? _delogoCommand;
public DelegateCommand DelogoCommand =>
delogoCommand ?? (delogoCommand = new DelegateCommand(ExecuteDelogoCommand));
public DelegateCommand DelogoCommand => _delogoCommand ??= new DelegateCommand(ExecuteDelogoCommand);
/// <summary>
/// 去水印事件
/// </summary>
private async void ExecuteDelogoCommand()
{
if (isDelogo)
if (_isDelogo)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished"));
return;
@@ -151,26 +151,25 @@ public class ViewDelogoViewModel : ViewModelBase
}
// 新文件名
string newFileName = VideoPath.Insert(VideoPath.Length - 4, "_delogo");
var newFileName = VideoPath.Insert(VideoPath.Length - 4, "_delogo");
Status = string.Empty;
await Task.Run(() =>
{
// 执行去水印程序
isDelogo = true;
_isDelogo = true;
FFMpeg.Instance.Delogo(VideoPath, newFileName, LogoX, LogoY, LogoWidth, LogoHeight, output =>
{
Status += output + "\n";
});
isDelogo = false;
_isDelogo = false;
});
}
// Status改变事件
private DelegateCommand<object> statusCommand;
private DelegateCommand<object>? _statusCommand;
public DelegateCommand<object> StatusCommand =>
statusCommand ?? (statusCommand = new DelegateCommand<object>(ExecuteStatusCommand));
public DelegateCommand<object> StatusCommand => _statusCommand ??= new DelegateCommand<object>(ExecuteStatusCommand);
/// <summary>
/// Status改变事件
@@ -178,13 +177,13 @@ public class ViewDelogoViewModel : ViewModelBase
/// <param name="parameter"></param>
private void ExecuteStatusCommand(object parameter)
{
if (!(parameter is TextBox output))
if (parameter is not TextChangedEventArgs output)
{
return;
}
// TextBox滚动到底部
// output.ScrollToEnd();
((TextBox?)output.Source)?.GetVisualDescendants().OfType<ScrollViewer>().FirstOrDefault()?.ScrollToEnd();
}
#endregion

View File

@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.VisualTree;
using DownKyi.Core.FFMpeg;
using DownKyi.Events;
using DownKyi.Utils;
@@ -14,36 +16,36 @@ public class ViewExtractMediaViewModel : ViewModelBase
public const string Tag = "PageToolboxExtractMedia";
// 是否正在执行任务
private bool isExtracting = false;
private bool _isExtracting;
#region
private string videoPathsStr;
private string _videoPathsStr;
public string VideoPathsStr
{
get => videoPathsStr;
set { SetProperty(ref videoPathsStr, value); }
get => _videoPathsStr;
set => SetProperty(ref _videoPathsStr, value);
}
private string[] videoPaths;
private string[] _videoPaths;
public string[] VideoPaths
{
get => videoPaths;
get => _videoPaths;
set
{
videoPaths = value;
_videoPaths = value;
VideoPathsStr = string.Join(Environment.NewLine, value);
}
}
private string status;
private string _status;
public string Status
{
get => status;
set => SetProperty(ref status, value);
get => _status;
set => SetProperty(ref _status, value);
}
#endregion
@@ -52,7 +54,7 @@ public class ViewExtractMediaViewModel : ViewModelBase
{
#region
VideoPaths = new string[0];
VideoPaths = Array.Empty<string>();
#endregion
}
@@ -60,17 +62,16 @@ public class ViewExtractMediaViewModel : ViewModelBase
#region
// 选择视频事件
private DelegateCommand selectVideoCommand;
private DelegateCommand? _selectVideoCommand;
public DelegateCommand SelectVideoCommand =>
selectVideoCommand ?? (selectVideoCommand = new DelegateCommand(ExecuteSelectVideoCommand));
public DelegateCommand SelectVideoCommand => _selectVideoCommand ??= new DelegateCommand(ExecuteSelectVideoCommand);
/// <summary>
/// 选择视频事件
/// </summary>
private async void ExecuteSelectVideoCommand()
{
if (isExtracting)
if (_isExtracting)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished"));
return;
@@ -80,24 +81,22 @@ public class ViewExtractMediaViewModel : ViewModelBase
}
// 提取音频事件
private DelegateCommand extractAudioCommand;
private DelegateCommand? _extractAudioCommand;
public DelegateCommand ExtractAudioCommand => extractAudioCommand ??
(extractAudioCommand =
new DelegateCommand(ExecuteExtractAudioCommand));
public DelegateCommand ExtractAudioCommand => _extractAudioCommand ??= new DelegateCommand(ExecuteExtractAudioCommand);
/// <summary>
/// 提取音频事件
/// </summary>
private async void ExecuteExtractAudioCommand()
{
if (isExtracting)
if (_isExtracting)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished"));
return;
}
if (VideoPaths.Length <= 0)
if (VideoPaths?.Length <= 0)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo"));
return;
@@ -107,35 +106,30 @@ public class ViewExtractMediaViewModel : ViewModelBase
await Task.Run(() =>
{
isExtracting = true;
_isExtracting = true;
foreach (var item in VideoPaths)
{
// 音频文件名
string audioFileName = item.Remove(item.Length - 4, 4) + ".aac";
var audioFileName = item.Remove(item.Length - 4, 4) + ".aac";
// 执行提取音频程序
FFMpeg.Instance.ExtractAudio(item, audioFileName, output =>
{
Status += output + "\n";
});
FFMpeg.Instance.ExtractAudio(item, audioFileName, output => { Status += output + "\n"; });
}
isExtracting = false;
_isExtracting = false;
});
}
// 提取视频事件
private DelegateCommand extractVideoCommand;
private DelegateCommand? _extractVideoCommand;
public DelegateCommand ExtractVideoCommand => extractVideoCommand ??
(extractVideoCommand =
new DelegateCommand(ExecuteExtractVideoCommand));
public DelegateCommand ExtractVideoCommand => _extractVideoCommand ??= new DelegateCommand(ExecuteExtractVideoCommand);
/// <summary>
/// 提取视频事件
/// </summary>
private async void ExecuteExtractVideoCommand()
{
if (isExtracting)
if (_isExtracting)
{
EventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipWaitTaskFinished"));
return;
@@ -151,27 +145,23 @@ public class ViewExtractMediaViewModel : ViewModelBase
await Task.Run(() =>
{
isExtracting = true;
_isExtracting = true;
foreach (var item in VideoPaths)
{
// 视频文件名
string videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4";
var videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4";
// 执行提取视频程序
FFMpeg.Instance.ExtractVideo(item, videoFileName, new Action<string>((output) =>
{
Status += output + "\n";
}));
FFMpeg.Instance.ExtractVideo(item, videoFileName, new Action<string>((output) => { Status += output + "\n"; }));
}
isExtracting = false;
_isExtracting = false;
});
}
// Status改变事件
private DelegateCommand<object> statusCommand;
private DelegateCommand<object>? _statusCommand;
public DelegateCommand<object> StatusCommand =>
statusCommand ?? (statusCommand = new DelegateCommand<object>(ExecuteStatusCommand));
public DelegateCommand<object> StatusCommand => _statusCommand ??= new DelegateCommand<object>(ExecuteStatusCommand);
/// <summary>
/// Status改变事件
@@ -179,13 +169,13 @@ public class ViewExtractMediaViewModel : ViewModelBase
/// <param name="parameter"></param>
private void ExecuteStatusCommand(object parameter)
{
if (!(parameter is TextBox output))
if (parameter is not TextChangedEventArgs output)
{
return;
}
// TextBox滚动到底部
// output.ScrollToEnd();
((TextBox?)output.Source)?.GetVisualDescendants().OfType<ScrollViewer>().FirstOrDefault()?.ScrollToEnd();
}
#endregion

View File

@@ -98,7 +98,7 @@
Height="25"
Margin="10"
VerticalContentAlignment="Center"
Text="{Binding DanmakuUserID, Mode=TwoWay}" />
Text="{Binding DanmakuUserId, Mode=TwoWay}" />
</StackPanel>
<Button
@@ -120,21 +120,19 @@
FontSize="12"
IsReadOnly="True"
Text="{Binding UserMid, Mode=TwoWay}">
<!--<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="PointerReleased">
<ia:InvokeCommandAction Command="{Binding VisitUserSpaceCommand}" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<TextBox.Styles>
<Style Selector="TextBox">
<Setter Property="Foreground" Value="{DynamicResource BrushTextDark}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource BrushPrimary}" />
</Trigger>
</Style.Triggers>
<Style Selector="^:pointerover">
<Setter Property="Foreground" Value="{DynamicResource BrushPrimary}" />
</Style>
</Style>
</TextBox.Style>-->
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding VisitUserSpaceCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>-->
</TextBox.Styles>
</TextBox>
</StackPanel>

View File

@@ -115,7 +115,7 @@
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="TextChanged">
<ia:InvokeCommandAction Command="{Binding StatusCommand}"
CommandParameter="{Binding ElementName=NameStatus}" />
PassEventArgsToCommand="True" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBox>

View File

@@ -1,8 +1,6 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DownKyi.Views.Toolbox.ViewExtractMedia"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:i="using:Avalonia.Xaml.Interactivity"
xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
xmlns:vm="clr-namespace:DownKyi.ViewModels.Toolbox"
@@ -38,11 +36,7 @@
Content="{DynamicResource SelectVideo}"
Theme="{StaticResource BtnBorderStyle}" />
</StackPanel>
<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Grid Margin="0,20,0,0" ColumnDefinitions="200,200">
<Button
Grid.Column="0"
@@ -66,17 +60,13 @@
Grid.Row="1"
Margin="0,20"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
VerticalAlignment="Stretch" RowDefinitions="20,*">
<TextBlock
Grid.Row="0"
VerticalAlignment="Bottom"
Text="{DynamicResource OutputInfo}" />
<TextBox
Name="nameStatus"
Name="NameStatus"
Grid.Row="1"
Background="Black"
Foreground="White"
@@ -86,8 +76,9 @@
ScrollViewer.VerticalScrollBarVisibility="Visible">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="TextChanged">
<ia:InvokeCommandAction Command="{Binding StatusCommand}"
CommandParameter="{Binding ElementName=nameStatus}" />
<ia:InvokeCommandAction
Command="{Binding StatusCommand}"
PassEventArgsToCommand="True" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBox>