[CHANGE] Improved hash auth token gen. Added new cookie rotate
This commit is contained in:
@@ -31,7 +31,17 @@ public static class AuthenticationUtilities
|
|||||||
throw new ArgumentNullException(nameof(origin));
|
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);
|
sapisid = Uri.UnescapeDataString(sapisid);
|
||||||
if (string.IsNullOrWhiteSpace(time))
|
if (string.IsNullOrWhiteSpace(time))
|
||||||
{
|
{
|
||||||
@@ -52,7 +62,7 @@ public static class AuthenticationUtilities
|
|||||||
private static string GetTime()
|
private static string GetTime()
|
||||||
{
|
{
|
||||||
var st = new DateTime(1970, 1, 1);
|
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);
|
var time = (t.TotalMilliseconds + 0.5).ToString(CultureInfo.InvariantCulture);
|
||||||
return time[..10];
|
return time[..10];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,6 +202,22 @@ public sealed class YouTubeClient : IDisposable
|
|||||||
return tempDatasyncId;
|
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()
|
public async Task<Result> RotateCookiesAsync()
|
||||||
{
|
{
|
||||||
if (IsAnonymous)
|
if (IsAnonymous)
|
||||||
@@ -209,16 +225,8 @@ public sealed class YouTubeClient : IDisposable
|
|||||||
return ResultError.Fail("Anonymous clients cannot rotate cookies!");
|
return ResultError.Fail("Anonymous clients cannot rotate cookies!");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var rotateRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://accounts.youtube.com/RotateCookies"));
|
var rotateRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://accounts.youtube.com/RotateCookies"));
|
||||||
var response = await HttpClient.SendAsync(rotateRequest);
|
return await NetworkService.MakeRequestAsync(rotateRequest, this, true);
|
||||||
return !response.IsSuccessStatusCode ? ResultError.Fail($"Cookies rotation failed, status code: {response.StatusCode}") : Result.Success();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return ResultError.Error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user