diff --git a/Manager.YouTube/YouTubeClient.cs b/Manager.YouTube/YouTubeClient.cs index 8252a83..7038b30 100644 --- a/Manager.YouTube/YouTubeClient.cs +++ b/Manager.YouTube/YouTubeClient.cs @@ -21,30 +21,33 @@ public sealed class YouTubeClient : IDisposable public Cookie? SapisidCookie => CookieContainer.GetAllCookies()["SAPISID"]; public HttpClient HttpClient { get; } - private YouTubeClient(CookieCollection cookies, string userAgent) + private YouTubeClient(CookieCollection? cookies, string userAgent) { if (string.IsNullOrWhiteSpace(userAgent)) { throw new ArgumentNullException(nameof(userAgent)); } UserAgent = userAgent; - if (cookies.Count == 0) + if (cookies == null || cookies.Count == 0) { Id = $"anon_{Guid.NewGuid()}"; IsAnonymous = true; } - - CookieContainer.Add(cookies); + else + { + CookieContainer.Add(cookies); + } + HttpClient = new HttpClient(GetHttpClientHandler()); } /// /// Loads the given cookies and fetch client state. /// - /// The cookies to use for making requests. Empty collection for anonymous requests. + /// 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. /// - public static async Task> CreateAsync(CookieCollection cookies, string userAgent) + public static async Task> CreateAsync(CookieCollection? cookies, string userAgent) { var client = new YouTubeClient(cookies, userAgent); var clientInitializeResult = await client.FetchClientDataAsync();