[CHANGE] Preparing client init

This commit is contained in:
max
2025-09-02 15:17:14 +02:00
parent 0ab0a029c4
commit dbf6938a7e
2 changed files with 35 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
using System.Net;
using DotBased.Monads;
using Manager.Data.Entities.LibraryContext;
using Manager.YouTube;
namespace Manager.App.Services.System;
@@ -5,11 +8,37 @@ namespace Manager.App.Services.System;
public class ClientManager : BackgroundService
{
private readonly List<YouTubeClient> _clients = [];
private bool _cancelled;
protected override Task ExecuteAsync(CancellationToken stoppingToken)
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
throw new NotImplementedException();
stoppingToken.Register(CancellationRequested);
}
private void CancellationRequested()
{
_cancelled = true;
// Clear up
}
public async Task<Result<YouTubeClient>> LoadClient(ClientAccountEntity accountEntity)
{
var container = new CookieContainer();
if (accountEntity.HttpCookies.Count != 0)
{
var cookieColl = new CookieCollection();
foreach (var cookieEntity in accountEntity.HttpCookies)
{
cookieColl.Add(new Cookie(cookieEntity.Name, cookieEntity.Value, cookieEntity.Domain));
}
container.Add(cookieColl);
}
var ytClient = new YouTubeClient(container, accountEntity.UserAgent ?? "");
await ytClient.GetStateAsync();
return ytClient;
}
}