mirror of
https://github.com/leiurayer/downkyi.git
synced 2025-03-23 07:40:12 +08:00
IVideoInfoService接入
This commit is contained in:
parent
e075463ccf
commit
781cd5b739
@ -1,4 +1,6 @@
|
||||
using Downkyi.BiliSharp.Api.Models.Video;
|
||||
using Downkyi.BiliSharp.Api.Login;
|
||||
using Downkyi.BiliSharp.Api.Models.Video;
|
||||
using Downkyi.BiliSharp.Api.Sign;
|
||||
using Downkyi.Core.Bili.Models;
|
||||
using Downkyi.Core.Bili.Utils;
|
||||
|
||||
@ -19,6 +21,13 @@ internal class Video : IVideo
|
||||
|
||||
_input = input;
|
||||
|
||||
// 设置wbi keys
|
||||
var info = LoginInfo.GetNavigationInfo();
|
||||
var imgKey = info.Data.WbiImg.ImgUrl.Split('/').ToList().Last().Split('.')[0];
|
||||
var subKey = info.Data.WbiImg.SubUrl.Split('/').ToList().Last().Split('.')[0];
|
||||
var keys = new Tuple<string, string>(imgKey, subKey);
|
||||
WbiSign.SetKey(keys);
|
||||
|
||||
if (ParseEntrance.IsAvId(input) || ParseEntrance.IsAvUrl(input))
|
||||
{
|
||||
long avid = ParseEntrance.GetAvId(input);
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
11
src/Downkyi.UI/Services/VideoInfo/BangumiInfoService.cs
Normal file
11
src/Downkyi.UI/Services/VideoInfo/BangumiInfoService.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Downkyi.UI.Models;
|
||||
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public class BangumiInfoService : IVideoInfoService
|
||||
{
|
||||
public VideoInfoView? GetVideoView(string input)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
11
src/Downkyi.UI/Services/VideoInfo/CheeseInfoService.cs
Normal file
11
src/Downkyi.UI/Services/VideoInfo/CheeseInfoService.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Downkyi.UI.Models;
|
||||
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public class CheeseInfoService : IVideoInfoService
|
||||
{
|
||||
public VideoInfoView? GetVideoView(string input)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Downkyi.UI.Models;
|
||||
|
||||
namespace Downkyi.UI.Services;
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public interface IVideoInfoService
|
||||
{
|
@ -0,0 +1,6 @@
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public interface IVideoInfoServiceFactory
|
||||
{
|
||||
IVideoInfoService Create(string input);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using Downkyi.Core.Bili;
|
||||
using Downkyi.UI.Models;
|
||||
|
||||
namespace Downkyi.UI.Services;
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public class VideoInfoService : IVideoInfoService
|
||||
{
|
||||
@ -13,7 +13,7 @@ public class VideoInfoService : IVideoInfoService
|
||||
var video = BiliLocator.Video(input);
|
||||
var videoInfo = video.GetVideoInfo();
|
||||
|
||||
|
||||
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
32
src/Downkyi.UI/Services/VideoInfo/VideoInfoServiceFactory.cs
Normal file
32
src/Downkyi.UI/Services/VideoInfo/VideoInfoServiceFactory.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Downkyi.Core.Bili.Utils;
|
||||
|
||||
namespace Downkyi.UI.Services.VideoInfo;
|
||||
|
||||
public class VideoInfoServiceFactory(IServiceProvider serviceProvider) : IVideoInfoServiceFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider = serviceProvider;
|
||||
|
||||
public IVideoInfoService Create(string input)
|
||||
{
|
||||
// 视频
|
||||
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<VideoInfoService>();
|
||||
}
|
||||
|
||||
// 番剧(电影、电视剧)
|
||||
if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<BangumiInfoService>();
|
||||
}
|
||||
|
||||
// 课程
|
||||
if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<BangumiInfoService>();
|
||||
}
|
||||
|
||||
throw new ArgumentException("Invalid type", nameof(input));
|
||||
}
|
||||
}
|
@ -2,11 +2,14 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Downkyi.Core.Log;
|
||||
using Downkyi.Core.Settings;
|
||||
using Downkyi.Core.Settings.Enum;
|
||||
using Downkyi.Core.Settings.Models;
|
||||
using Downkyi.UI.Models;
|
||||
using Downkyi.UI.Mvvm;
|
||||
using Downkyi.UI.Services.VideoInfo;
|
||||
using Downkyi.UI.ViewModels.DownloadManager;
|
||||
using Downkyi.UI.ViewModels.User;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Downkyi.UI.ViewModels.Video;
|
||||
|
||||
@ -14,6 +17,8 @@ public partial class VideoDetailViewModel : ViewModelBase
|
||||
{
|
||||
public const string Key = "VideoDetail";
|
||||
|
||||
private readonly IVideoInfoServiceFactory _videoInfoServiceFactory;
|
||||
|
||||
// 保存输入字符串,避免被用户修改
|
||||
private string? _input = null;
|
||||
|
||||
@ -33,8 +38,11 @@ public partial class VideoDetailViewModel : ViewModelBase
|
||||
|
||||
#endregion
|
||||
|
||||
public VideoDetailViewModel(BaseServices baseServices) : base(baseServices)
|
||||
public VideoDetailViewModel(BaseServices baseServices,
|
||||
IVideoInfoServiceFactory videoInfoServiceFactory) : base(baseServices)
|
||||
{
|
||||
_videoInfoServiceFactory = videoInfoServiceFactory;
|
||||
|
||||
#region 属性初始化
|
||||
|
||||
ContentVisibility = true;
|
||||
@ -66,7 +74,28 @@ public partial class VideoDetailViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Input() { }
|
||||
private async Task InputAsync()
|
||||
{
|
||||
if (InputText == null || InputText == string.Empty) { return; }
|
||||
|
||||
Log.Logger.Debug($"InputText: {InputText}");
|
||||
_input = Regex.Replace(InputText, @"[【]*[^【]*[^】]*[】 ]", "");
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
// 根据输入创建对应VideoInfoService(视频、番剧、课程...)
|
||||
IVideoInfoService service = _videoInfoServiceFactory.Create(_input);
|
||||
|
||||
// 更新页面
|
||||
var tryVideoInfoView = service.GetVideoView(_input);
|
||||
|
||||
// 是否自动解析视频
|
||||
if (SettingsManager.GetInstance().IsAutoParseVideo() == AllowStatus.YES)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[RelayCommand(FlowExceptionsToTaskScheduler = true)]
|
||||
private async Task DownloadManager()
|
||||
@ -118,14 +147,20 @@ public partial class VideoDetailViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNavigatedTo(Dictionary<string, object>? parameter)
|
||||
public override async void OnNavigatedTo(Dictionary<string, object>? parameter)
|
||||
{
|
||||
base.OnNavigatedTo(parameter);
|
||||
|
||||
if (parameter!.TryGetValue("value", out object? value))
|
||||
{
|
||||
_input = (string)value;
|
||||
InputText = _input;
|
||||
// 正在执行任务时不开启新任务
|
||||
if (!LoadingVisibility)
|
||||
{
|
||||
_input = (string)value;
|
||||
InputText = _input;
|
||||
|
||||
await InputAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Downkyi.UI.Services;
|
||||
using Downkyi.Views;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Downkyi;
|
||||
|
||||
|
@ -42,7 +42,6 @@
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.1" />
|
||||
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
|
||||
<PackageReference Include="MessageBox.Avalonia" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -14,6 +14,28 @@ internal class Program
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
//[STAThread]
|
||||
//public static void Main(string[] args)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// // prepare and run your App here
|
||||
// BuildAvaloniaApp()
|
||||
// .StartWithClassicDesktopLifetime(args);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// // here we can work with the exception, for example add it to our log file
|
||||
// Log.Logger.Fatal(e, "Something very bad happened");
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// // This block is optional.
|
||||
// // Use the finally-block if you need to clean things up or similar
|
||||
// LogManager.Shutdown();
|
||||
// }
|
||||
//}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using Downkyi.Services;
|
||||
using Downkyi.UI.Mvvm;
|
||||
using Downkyi.UI.Services;
|
||||
using Downkyi.UI.Services.Event;
|
||||
using Downkyi.UI.Services.VideoInfo;
|
||||
using Downkyi.UI.ViewModels;
|
||||
using Downkyi.UI.ViewModels.DownloadManager;
|
||||
using Downkyi.UI.ViewModels.Login;
|
||||
@ -105,6 +106,11 @@ public static class ServiceLocator
|
||||
.AddSingleton<INavigationService, NavigationService>()
|
||||
.AddSingleton<IStoragePicker, StoragePicker>()
|
||||
.AddSingleton<IStorageService, StorageService>()
|
||||
// 注册多个 IVideoInfoService 实现
|
||||
.AddTransient<VideoInfoService>()
|
||||
.AddTransient<BangumiInfoService>()
|
||||
.AddTransient<CheeseInfoService>()
|
||||
.AddSingleton<IVideoInfoServiceFactory, VideoInfoServiceFactory>()
|
||||
//ViewModels
|
||||
.AddSingleton<MainWindowViewModel>()
|
||||
.AddSingleton<IndexViewModel>()
|
||||
|
Loading…
Reference in New Issue
Block a user