[CHANGE] Linked decipher to video implementation
This commit is contained in:
@@ -3,7 +3,7 @@ namespace Manager.YouTube.Models.Innertube;
|
||||
public class StreamingFormat
|
||||
{
|
||||
public int Itag { get; set; }
|
||||
public string Url { get; set; } = "";
|
||||
public string? Url { get; set; }
|
||||
public string MimeType { get; set; } = "";
|
||||
public uint Bitrate { get; set; }
|
||||
public uint? Width { get; set; }
|
||||
@@ -26,5 +26,6 @@ public class StreamingFormat
|
||||
public int? AudioChannels { get; set; }
|
||||
public double? LoudnessDb { get; set; }
|
||||
public bool? IsDrc { get; set; }
|
||||
public string? SignatureCipher { get; set; }
|
||||
public string QualityOrdinal { get; set; } = "";
|
||||
}
|
||||
@@ -31,8 +31,13 @@ public partial class CipherDecoder
|
||||
return decoder;
|
||||
}
|
||||
|
||||
public string Decipher(string signatureCipher)
|
||||
public string Decipher(string? signatureCipher)
|
||||
{
|
||||
if (string.IsNullOrEmpty(signatureCipher))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var urlBuilder = new StringBuilder();
|
||||
|
||||
var indexStart = signatureCipher.IndexOf("s=", StringComparison.Ordinal);
|
||||
|
||||
@@ -9,6 +9,7 @@ using Manager.YouTube.Models;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
using Manager.YouTube.Parsers;
|
||||
using Manager.YouTube.Parsers.Json;
|
||||
using Manager.YouTube.Util.Cipher;
|
||||
|
||||
namespace Manager.YouTube;
|
||||
|
||||
@@ -351,8 +352,38 @@ public sealed class YouTubeClient : IDisposable
|
||||
return videoParseResult;
|
||||
}
|
||||
|
||||
//TODO: decipher stream urls
|
||||
await DecipherSignatures(videoParseResult.Value);
|
||||
|
||||
return videoParseResult.Value;
|
||||
}
|
||||
|
||||
private async Task DecipherSignatures(YouTubeVideo video)
|
||||
{
|
||||
var streamingData = video.StreamingData;
|
||||
if (streamingData == null)
|
||||
{
|
||||
_logger.Debug("No streaming data available, skipping decipher.");
|
||||
return;
|
||||
}
|
||||
|
||||
var formatsWithCipher = streamingData.Formats.Concat(streamingData.AdaptiveFormats).Where(x => !string.IsNullOrWhiteSpace(x.SignatureCipher)).ToList();
|
||||
if (formatsWithCipher.Count == 0)
|
||||
{
|
||||
_logger.Debug("Skipping decipher, no signatures found to decipher.");
|
||||
return;
|
||||
}
|
||||
|
||||
var decipherDecoderResult = await CipherManager.GetDecoderAsync(this);
|
||||
if (!decipherDecoderResult.IsSuccess)
|
||||
{
|
||||
_logger.Warning(decipherDecoderResult.Error?.Description ?? "Failed to get the cipher decoder!");
|
||||
return;
|
||||
}
|
||||
var decoder = decipherDecoderResult.Value;
|
||||
|
||||
foreach (var format in formatsWithCipher)
|
||||
{
|
||||
format.Url = decoder.Decipher(format.SignatureCipher);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user