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

croire 3 years ago
parent 6cd1d58755
commit cd1e6608d3

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

@ -14,6 +14,9 @@
// 默认的视频解析项 // 默认的视频解析项
private readonly ParseScope parseScope = ParseScope.NONE; private readonly ParseScope parseScope = ParseScope.NONE;
// 解析后自动下载解析视频
private readonly AllowStatus isAutoDownloadAll = AllowStatus.NO;
// 下载完成列表排序 // 下载完成列表排序
private readonly DownloadFinishedSort finishedSort = DownloadFinishedSort.DOWNLOAD; private readonly DownloadFinishedSort finishedSort = DownloadFinishedSort.DOWNLOAD;
@ -125,6 +128,33 @@
return SetSettings(); 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>
/// 获取下载完成列表排序 /// 获取下载完成列表排序
/// </summary> /// </summary>

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

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

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

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

@ -63,7 +63,6 @@
Background="{DynamicResource BrushBorder}" /> Background="{DynamicResource BrushBorder}" />
<CheckBox <CheckBox
Grid.Column="0"
Margin="0,20,0,0" Margin="0,20,0,0"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Top" VerticalAlignment="Top"
@ -74,7 +73,6 @@
Style="{StaticResource CheckBoxStyle}" /> Style="{StaticResource CheckBoxStyle}" />
<CheckBox <CheckBox
Grid.Column="0"
Margin="0,20,0,0" Margin="0,20,0,0"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Top" VerticalAlignment="Top"
@ -105,6 +103,16 @@
</ComboBox> </ComboBox>
</StackPanel> </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 Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>

Loading…
Cancel
Save