[CHANGE] Preparing client init
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -10,4 +10,6 @@ public class ClientAccountEntity : DateTimeBase
|
||||
public string Name { get; set; } = "";
|
||||
public List<PlaylistEntity> Playlists { get; set; } = [];
|
||||
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
|
||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||
public string? UserAgent { get; set; }
|
||||
}
|
Reference in New Issue
Block a user