[CHANGE] Added old cipher implementation
This commit is contained in:
46
Manager.YouTube/Util/Cipher/CipherManager.cs
Normal file
46
Manager.YouTube/Util/Cipher/CipherManager.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using DotBased.Logging;
|
||||
using DotBased.Monads;
|
||||
|
||||
namespace Manager.YouTube.Util.Cipher;
|
||||
|
||||
public static class CipherManager
|
||||
{
|
||||
private static readonly CipherDecoderCollection LoadedCiphers = [];
|
||||
private static readonly ILogger Logger = LogService.RegisterLogger(typeof(CipherManager));
|
||||
|
||||
public static async Task<Result<CipherDecoder>> GetDecoder(YouTubeClient client)
|
||||
{
|
||||
var relativePlayerJsUrl = client.State?.PlayerJsUrl;
|
||||
if (string.IsNullOrEmpty(relativePlayerJsUrl))
|
||||
{
|
||||
return ResultError.Fail("Could not get player js url.");
|
||||
}
|
||||
var version = GetCipherVersion(relativePlayerJsUrl);
|
||||
|
||||
Logger.Debug($"Getting cipher decoder for version: {version}");
|
||||
if (LoadedCiphers.TryGetValue(version, out var cipher))
|
||||
{
|
||||
return cipher;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var decoder = await CipherDecoder.CreateAsync(relativePlayerJsUrl, version);
|
||||
LoadedCiphers.Add(decoder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "Could not create cipher decoder. Version: {DecoderVersion}", version);
|
||||
}
|
||||
|
||||
return ResultError.Fail($"Could not create cipher decoder for {relativePlayerJsUrl} (v: {version})");
|
||||
}
|
||||
|
||||
private static string GetCipherVersion(string relativePlayerUrl)
|
||||
{
|
||||
var split = relativePlayerUrl.Split('/');
|
||||
var v = split[2];
|
||||
var lang = split[4];
|
||||
return $"{v}_{lang}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user