[CHANGE] Improved hash auth token gen. Added new cookie rotate
This commit is contained in:
@@ -30,8 +30,18 @@ public static class AuthenticationUtilities
|
||||
{
|
||||
throw new ArgumentNullException(nameof(origin));
|
||||
}
|
||||
|
||||
datasyncId = datasyncId.Replace("||", "");
|
||||
|
||||
if (datasyncId.Contains("||", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var ids = datasyncId.Split("||", StringSplitOptions.RemoveEmptyEntries);
|
||||
datasyncId = ids.Length switch
|
||||
{
|
||||
1 => ids[0],
|
||||
2 => ids[1],
|
||||
_ => datasyncId
|
||||
};
|
||||
}
|
||||
|
||||
sapisid = Uri.UnescapeDataString(sapisid);
|
||||
if (string.IsNullOrWhiteSpace(time))
|
||||
{
|
||||
@@ -52,7 +62,7 @@ public static class AuthenticationUtilities
|
||||
private static string GetTime()
|
||||
{
|
||||
var st = new DateTime(1970, 1, 1);
|
||||
var t = DateTime.Now.ToUniversalTime() - st;
|
||||
var t = DateTime.UtcNow - st;
|
||||
var time = (t.TotalMilliseconds + 0.5).ToString(CultureInfo.InvariantCulture);
|
||||
return time[..10];
|
||||
}
|
||||
|
||||
@@ -202,6 +202,22 @@ public sealed class YouTubeClient : IDisposable
|
||||
return tempDatasyncId;
|
||||
}
|
||||
|
||||
public async Task<Result> RotateCookiesPageAsync(string origin = NetworkService.Origin, int ytPid = 1)
|
||||
{
|
||||
if (IsAnonymous)
|
||||
{
|
||||
return ResultError.Fail("Anonymous clients cannot rotate cookies!");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(origin))
|
||||
{
|
||||
return ResultError.Fail("Origin is empty!");
|
||||
}
|
||||
|
||||
var rotatePageCookiesRequest = new HttpRequestMessage(HttpMethod.Get, new Uri($"https://accounts.youtube.com/RotateCookiesPage?origin={origin}&yt_pid={ytPid}"));
|
||||
return await NetworkService.MakeRequestAsync(rotatePageCookiesRequest, this, true);
|
||||
}
|
||||
|
||||
public async Task<Result> RotateCookiesAsync()
|
||||
{
|
||||
if (IsAnonymous)
|
||||
@@ -209,16 +225,8 @@ public sealed class YouTubeClient : IDisposable
|
||||
return ResultError.Fail("Anonymous clients cannot rotate cookies!");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var rotateRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://accounts.youtube.com/RotateCookies"));
|
||||
var response = await HttpClient.SendAsync(rotateRequest);
|
||||
return !response.IsSuccessStatusCode ? ResultError.Fail($"Cookies rotation failed, status code: {response.StatusCode}") : Result.Success();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
}
|
||||
var rotateRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://accounts.youtube.com/RotateCookies"));
|
||||
return await NetworkService.MakeRequestAsync(rotateRequest, this, true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in New Issue
Block a user