新增“解析后自动下载已解析视频”设置

croire 3 years ago
parent 6cd1d58755
commit cd1e6608d3

@ -9,6 +9,7 @@
public AllowStatus IsListenClipboard { get; set; } = AllowStatus.NONE;
public AllowStatus IsAutoParseVideo { get; set; } = AllowStatus.NONE;
public ParseScope ParseScope { get; set; } = ParseScope.NOT_SET;
public AllowStatus IsAutoDownloadAll { get; set; } = AllowStatus.NONE;
public DownloadFinishedSort DownloadFinishedSort { get; set; } = DownloadFinishedSort.NOT_SET;
}
}

@ -14,6 +14,9 @@
// 默认的视频解析项
private readonly ParseScope parseScope = ParseScope.NONE;
// 解析后自动下载解析视频
private readonly AllowStatus isAutoDownloadAll = AllowStatus.NO;
// 下载完成列表排序
private readonly DownloadFinishedSort finishedSort = DownloadFinishedSort.DOWNLOAD;
@ -125,6 +128,33 @@
return SetSettings();
}
/// <summary>
/// 解析后是否自动下载解析视频
/// </summary>
/// <returns></returns>
public AllowStatus IsAutoDownloadAll()
{
appSettings = GetSettings();
if (appSettings.Basic.IsAutoDownloadAll == AllowStatus.NONE)
{
// 第一次获取,先设置默认值
IsAutoParseVideo(isAutoDownloadAll);
return isAutoDownloadAll;
}
return appSettings.Basic.IsAutoDownloadAll;
}
/// <summary>
/// 解析后是否自动下载解析视频
/// </summary>
/// <param name="isAutoDownloadAll"></param>
/// <returns></returns>
public bool IsAutoDownloadAll(AllowStatus isAutoDownloadAll)
{
appSettings.Basic.IsAutoDownloadAll = isAutoDownloadAll;
return SetSettings();
}
/// <summary>
/// 获取下载完成列表排序
/// </summary>

@ -180,6 +180,7 @@
<system:String x:Key="ListenClipboard">监听剪贴板</system:String>
<system:String x:Key="VideoAutoParse">视频自动解析</system:String>
<system:String x:Key="VideoParseScope">视频解析范围:</system:String>
<system:String x:Key="AutoDownloadAll">解析后自动下载已解析视频</system:String>
<system:String x:Key="Network">网络</system:String>
<system:String x:Key="AriaServerPort">Aria服务器端口</system:String>

@ -196,7 +196,7 @@ namespace DownKyi.Services.Download
return directory;
}
public int AddToDownload(IEventAggregator eventAggregator, string directory)
public int AddToDownload(IEventAggregator eventAggregator, string directory, bool isAll = false)
{
if (directory == null || directory == string.Empty) { return -1; }
if (videoSections == null) { return -1; }
@ -212,7 +212,7 @@ namespace DownKyi.Services.Download
foreach (VideoPage page in section.VideoPages)
{
// 只下载选中项,跳过未选中项
if (!page.IsSelected) { continue; }
if (!isAll && !page.IsSelected) { continue; }
// 没有解析的也跳过
if (page.PlayUrl == null) { continue; }

@ -67,6 +67,13 @@ namespace DownKyi.ViewModels.Settings
set { SetProperty(ref selectedParseScope, value); }
}
private bool autoDownloadAll;
public bool AutoDownloadAll
{
get => autoDownloadAll;
set => SetProperty(ref autoDownloadAll, value);
}
#endregion
public ViewBasicViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
@ -113,6 +120,10 @@ namespace DownKyi.ViewModels.Settings
ParseScope parseScope = SettingsManager.GetInstance().GetParseScope();
SelectedParseScope = ParseScopes.FirstOrDefault(t => { return t.ParseScope == parseScope; });
// 解析后是否自动下载解析视频
AllowStatus isAutoDownloadAll = SettingsManager.GetInstance().IsAutoDownloadAll();
AutoDownloadAll = isAutoDownloadAll == AllowStatus.YES;
isOnNavigatedTo = false;
}
@ -193,6 +204,21 @@ namespace DownKyi.ViewModels.Settings
PublishTip(isSucceed);
}
// 解析后是否自动下载解析视频
private DelegateCommand autoDownloadAllCommand;
public DelegateCommand AutoDownloadAllCommand => autoDownloadAllCommand ?? (autoDownloadAllCommand = new DelegateCommand(ExecuteAutoDownloadAllCommand));
/// <summary>
/// 解析后是否自动下载解析视频
/// </summary>
private void ExecuteAutoDownloadAllCommand()
{
AllowStatus isAutoDownloadAll = AutoDownloadAll ? AllowStatus.YES : AllowStatus.NO;
bool isSucceed = SettingsManager.GetInstance().IsAutoDownloadAll(isAutoDownloadAll);
PublishTip(isSucceed);
}
#endregion
/// <summary>

@ -480,6 +480,13 @@ namespace DownKyi.ViewModels
}
LoadingVisibility = Visibility.Collapsed;
// 解析后是否自动下载解析视频
AllowStatus isAutoDownloadAll = SettingsManager.GetInstance().IsAutoDownloadAll();
if (parseScope != ParseScope.NONE && isAutoDownloadAll == AllowStatus.YES)
{
AddToDownload(true);
}
}
/// <summary>
@ -498,56 +505,57 @@ namespace DownKyi.ViewModels
/// <summary>
/// 添加到下载列表事件
/// </summary>
private async void ExecuteAddToDownloadCommand()
{
AddToDownloadService addToDownloadService = null;
// 视频
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO);
}
// 番剧(电影、电视剧)
else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI);
}
// 课程
else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE);
}
else
{
return;
}
// 选择文件夹
string directory = addToDownloadService.SetDirectory(dialogService);
// 视频计数
int i = 0;
await Task.Run(() =>
{
// 传递video对象
addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList());
// 下载
i = addToDownloadService.AddToDownload(eventAggregator, directory);
});
if (directory == null)
{
return;
}
// 通知用户添加到下载列表的结果
if (i <= 0)
{
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipAddDownloadingZero"));
}
else
{
eventAggregator.GetEvent<MessageEvent>().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}");
}
private void ExecuteAddToDownloadCommand()
{
AddToDownload(false);
//AddToDownloadService addToDownloadService = null;
//// 视频
//if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
//{
// addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO);
//}
//// 番剧(电影、电视剧)
//else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
//{
// addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI);
//}
//// 课程
//else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
//{
// addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE);
//}
//else
//{
// return;
//}
//// 选择文件夹
//string directory = addToDownloadService.SetDirectory(dialogService);
//// 视频计数
//int i = 0;
//await Task.Run(() =>
//{
// // 传递video对象
// addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList());
// // 下载
// i = addToDownloadService.AddToDownload(eventAggregator, directory);
//});
//if (directory == null)
//{
// return;
//}
//// 通知用户添加到下载列表的结果
//if (i <= 0)
//{
// eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipAddDownloadingZero"));
//}
//else
//{
// eventAggregator.GetEvent<MessageEvent>().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}");
//}
}
/// <summary>
@ -663,6 +671,62 @@ namespace DownKyi.ViewModels
videoInfoService.GetVideoStream(videoPage);
}
/// <summary>
/// 添加到下载列表事件
/// </summary>
private async void AddToDownload(bool isAll)
{
AddToDownloadService addToDownloadService = null;
// 视频
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO);
}
// 番剧(电影、电视剧)
else if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.BANGUMI);
}
// 课程
else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
{
addToDownloadService = new AddToDownloadService(PlayStreamType.CHEESE);
}
else
{
return;
}
// 选择文件夹
string directory = addToDownloadService.SetDirectory(dialogService);
// 视频计数
int i = 0;
await Task.Run(() =>
{
// 传递video对象
addToDownloadService.GetVideo(VideoInfoView, VideoSections.ToList());
// 下载
i = addToDownloadService.AddToDownload(eventAggregator, directory, isAll);
});
if (directory == null)
{
return;
}
// 通知用户添加到下载列表的结果
if (i <= 0)
{
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipAddDownloadingZero"));
}
else
{
eventAggregator.GetEvent<MessageEvent>().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}");
}
}
#endregion
/// <summary>

@ -63,7 +63,6 @@
Background="{DynamicResource BrushBorder}" />
<CheckBox
Grid.Column="0"
Margin="0,20,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
@ -74,7 +73,6 @@
Style="{StaticResource CheckBoxStyle}" />
<CheckBox
Grid.Column="0"
Margin="0,20,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
@ -105,6 +103,16 @@
</ComboBox>
</StackPanel>
<CheckBox
Margin="0,20,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Command="{Binding AutoDownloadAllCommand}"
Content="{DynamicResource AutoDownloadAll}"
Foreground="{DynamicResource BrushTextDark}"
IsChecked="{Binding AutoDownloadAll, Mode=TwoWay}"
Style="{StaticResource CheckBoxStyle}" />
<StackPanel Margin="10" />
</StackPanel>
</ScrollViewer>

Loading…
Cancel
Save