diff --git a/Manager.App/Services/System/ClientManager.cs b/Manager.App/Services/System/ClientManager.cs index 178aab4..19c6a37 100644 --- a/Manager.App/Services/System/ClientManager.cs +++ b/Manager.App/Services/System/ClientManager.cs @@ -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 _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> 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; } - - } \ No newline at end of file diff --git a/Manager.Data/Entities/LibraryContext/ClientAccountEntity.cs b/Manager.Data/Entities/LibraryContext/ClientAccountEntity.cs index e29c442..300804c 100644 --- a/Manager.Data/Entities/LibraryContext/ClientAccountEntity.cs +++ b/Manager.Data/Entities/LibraryContext/ClientAccountEntity.cs @@ -10,4 +10,6 @@ public class ClientAccountEntity : DateTimeBase public string Name { get; set; } = ""; public List Playlists { get; set; } = []; public List HttpCookies { get; set; } = []; + [MaxLength(DataConstants.DbContext.DefaultDbStringSize)] + public string? UserAgent { get; set; } } \ No newline at end of file