feat: improve recording automation and task workflows
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using LiveRecorder.Application.Abstractions.Auth;
|
||||
using LiveRecorder.Application.Abstractions.Logging;
|
||||
using LiveRecorder.Application.Abstractions.Notifications;
|
||||
using LiveRecorder.Application.Abstractions.Persistence;
|
||||
using LiveRecorder.Application.Abstractions.Platforms;
|
||||
using LiveRecorder.Application.Abstractions.Recording;
|
||||
using LiveRecorder.Application.Abstractions.Scripting;
|
||||
using LiveRecorder.Application.Abstractions.Settings;
|
||||
using LiveRecorder.Application.Abstractions.Storage;
|
||||
using LiveRecorder.Application.Services;
|
||||
using LiveRecorder.Infrastructure.Persistence;
|
||||
using LiveRecorder.Infrastructure.Persistence.Repositories;
|
||||
using LiveRecorder.Infrastructure.Platforms.Bilibili;
|
||||
using LiveRecorder.Infrastructure.Platforms.Bilibili.Danmaku;
|
||||
using LiveRecorder.Infrastructure.Platforms.Douyin;
|
||||
using LiveRecorder.Infrastructure.Platforms.Douyin.Danmaku;
|
||||
using LiveRecorder.Infrastructure.Platforms.Douyin.Signing;
|
||||
using LiveRecorder.Infrastructure.Platforms.Huya;
|
||||
using LiveRecorder.Infrastructure.Services;
|
||||
using LiveRecorder.WebApi.Middleware;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
@@ -75,16 +81,46 @@ builder.Services.AddHttpClient("douyin", client =>
|
||||
client.DefaultRequestVersion = HttpVersion.Version11;
|
||||
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
|
||||
})
|
||||
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
|
||||
.ConfigurePrimaryHttpMessageHandler(() => CreateDouyinHttpHandler(useProxy: true));
|
||||
|
||||
builder.Services.AddHttpClient("douyin-direct", client =>
|
||||
{
|
||||
client.Timeout = TimeSpan.FromSeconds(20);
|
||||
client.DefaultRequestVersion = HttpVersion.Version11;
|
||||
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
|
||||
})
|
||||
.ConfigurePrimaryHttpMessageHandler(() => CreateDouyinHttpHandler(useProxy: false));
|
||||
|
||||
builder.Services.AddHttpClient("bilibili", client =>
|
||||
{
|
||||
client.Timeout = TimeSpan.FromSeconds(20);
|
||||
client.DefaultRequestVersion = HttpVersion.Version11;
|
||||
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
|
||||
})
|
||||
.ConfigurePrimaryHttpMessageHandler(static () => new SocketsHttpHandler
|
||||
{
|
||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
|
||||
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
|
||||
PooledConnectionLifetime = TimeSpan.FromMinutes(5),
|
||||
PooledConnectionIdleTimeout = TimeSpan.FromSeconds(30),
|
||||
MaxConnectionsPerServer = 8
|
||||
MaxConnectionsPerServer = 8,
|
||||
ConnectTimeout = TimeSpan.FromSeconds(10),
|
||||
UseCookies = false,
|
||||
SslOptions = new SslClientAuthenticationOptions
|
||||
{
|
||||
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13
|
||||
}
|
||||
});
|
||||
|
||||
var sqliteConnectionStringBuilder = new SqliteConnectionStringBuilder(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"))
|
||||
{
|
||||
Cache = SqliteCacheMode.Shared,
|
||||
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||
DefaultTimeout = 30
|
||||
};
|
||||
|
||||
builder.Services.AddDbContext<LiveRecorderDbContext>(options =>
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
options.UseSqlite(sqliteConnectionStringBuilder.ToString()));
|
||||
|
||||
builder.Services.AddScoped<IUnitOfWork>(provider => provider.GetRequiredService<LiveRecorderDbContext>());
|
||||
builder.Services.AddScoped<IAppSettingRepository, AppSettingRepository>();
|
||||
@@ -99,24 +135,31 @@ builder.Services.AddScoped<IUserSessionRepository, UserSessionRepository>();
|
||||
builder.Services.AddScoped<ISystemSettingsService, SystemSettingsService>();
|
||||
builder.Services.AddScoped<ISystemLogService, SystemLogService>();
|
||||
builder.Services.AddScoped<IEmailNotificationService, EmailNotificationService>();
|
||||
builder.Services.AddScoped<IEventScriptService, EventScriptService>();
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<LiveRoomService>();
|
||||
builder.Services.AddScoped<LiveRoomStatusService>();
|
||||
builder.Services.AddScoped<LiveRoomRecordingSettingsResolver>();
|
||||
builder.Services.AddScoped<RecordService>();
|
||||
builder.Services.AddScoped<RecordSessionService>();
|
||||
builder.Services.AddScoped<StoppedOrphanRecordSessionCleanupService>();
|
||||
builder.Services.AddScoped<DatabaseInitializer>();
|
||||
|
||||
builder.Services.AddSingleton<BilibiliWbiSigner>();
|
||||
builder.Services.AddScoped<BilibiliHttpClient>();
|
||||
builder.Services.AddScoped<DouyinHttpClient>();
|
||||
builder.Services.AddSingleton<DouyinXBogusSigner>();
|
||||
builder.Services.AddSingleton<DouyinLiveWsSignatureSigner>();
|
||||
builder.Services.AddScoped<ILivePlatformAdapter, DouyinLivePlatformAdapter>();
|
||||
builder.Services.AddScoped<ILivePlatformAdapter, BilibiliLivePlatformAdapter>();
|
||||
builder.Services.AddScoped<ILivePlatformAdapter, HuyaLivePlatformAdapter>();
|
||||
builder.Services.AddScoped<ILivePlatformAdapterFactory, LivePlatformAdapterFactory>();
|
||||
builder.Services.AddScoped<ILiveDanmakuAdapter, DouyinDanmakuAdapter>();
|
||||
builder.Services.AddScoped<ILiveDanmakuAdapter, BilibiliDanmakuAdapter>();
|
||||
builder.Services.AddScoped<ILiveDanmakuAdapterFactory, LiveDanmakuAdapterFactory>();
|
||||
|
||||
builder.Services.AddSingleton<IFfmpegService, FfmpegService>();
|
||||
builder.Services.AddSingleton<IStorageGuardService, StorageGuardService>();
|
||||
builder.Services.AddScoped<IRecordMediaService, RecordMediaService>();
|
||||
builder.Services.AddHostedService<LiveRoomPollingBackgroundService>();
|
||||
|
||||
@@ -179,3 +222,21 @@ static async Task<Dictionary<string, long>> ReadRecordingDataCountsAsync(LiveRec
|
||||
item => item.LiveRoomId != null || item.RecordSessionId != null || item.RecordTaskId != null)
|
||||
};
|
||||
}
|
||||
|
||||
static SocketsHttpHandler CreateDouyinHttpHandler(bool useProxy)
|
||||
{
|
||||
return new SocketsHttpHandler
|
||||
{
|
||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
|
||||
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
|
||||
PooledConnectionIdleTimeout = TimeSpan.FromSeconds(30),
|
||||
MaxConnectionsPerServer = 8,
|
||||
ConnectTimeout = TimeSpan.FromSeconds(10),
|
||||
UseCookies = false,
|
||||
UseProxy = useProxy,
|
||||
SslOptions = new SslClientAuthenticationOptions
|
||||
{
|
||||
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user