diff --git a/Manager.YouTube/YouTubeClient.cs b/Manager.YouTube/YouTubeClient.cs index 15cd925..83c4b7a 100644 --- a/Manager.YouTube/YouTubeClient.cs +++ b/Manager.YouTube/YouTubeClient.cs @@ -3,6 +3,7 @@ using System.Net.Mime; using System.Text; using System.Text.Json; using System.Text.Json.Nodes; +using DotBased.Logging; using DotBased.Monads; using Manager.YouTube.Models; using Manager.YouTube.Models.Innertube; @@ -22,12 +23,15 @@ public sealed class YouTubeClient : IDisposable public Cookie? SapisidCookie => CookieContainer.GetAllCookies()["SAPISID"]; public HttpClient HttpClient { get; } - private YouTubeClient(CookieCollection? cookies, string userAgent) + private readonly ILogger _logger; + + private YouTubeClient(CookieCollection? cookies, string userAgent, ILogger logger) { if (string.IsNullOrWhiteSpace(userAgent)) { throw new ArgumentNullException(nameof(userAgent)); } + _logger = logger; UserAgent = userAgent; if (cookies == null || cookies.Count == 0) { @@ -47,10 +51,13 @@ public sealed class YouTubeClient : IDisposable /// /// The cookies to use for making requests. Empty collection or null for anonymous requests. /// The user agent to use for the requests. Only WEB client is supported. + /// The logger that the client is going to use, if null will create a new logger. /// - public static async Task> CreateAsync(CookieCollection? cookies, string userAgent) + public static async Task> CreateAsync(CookieCollection? cookies, string userAgent, ILogger? logger = null) { - var client = new YouTubeClient(cookies, userAgent); + logger ??= LogService.RegisterLogger(); + + var client = new YouTubeClient(cookies, userAgent, logger); var clientInitializeResult = await client.FetchClientDataAsync(); if (!clientInitializeResult.IsSuccess) { @@ -329,7 +336,7 @@ public sealed class YouTubeClient : IDisposable var stateResult = SetClientStateFromHtml(html); if (!stateResult.IsSuccess) { - //TODO: Log warning: failed to update client state! + _logger.Warning("Failed to update client state."); } var htmlParseResult = HtmlParser.GetVideoDataFromHtml(html);