Compare commits

..

No commits in common. "master" and "fix-message-downloading" have entirely different histories.

7 changed files with 39 additions and 113 deletions

View File

@ -103,10 +103,6 @@ namespace OF_DL.Entities
[JsonConverter(typeof(StringEnumConverter))]
public VideoResolution DownloadVideoResolution { get; set; } = VideoResolution.source;
// When enabled, post/message text is stored as-is without XML stripping.
[ToggleableConfig]
public bool DisableTextSanitization { get; set; } = false;
}
public class CreatorConfig : IFileNameFormatConfig

View File

@ -2812,11 +2812,11 @@ public class APIHelper : IAPIHelper
try
{
var resp1 = await PostData(licenceURL, drmHeaders, new byte[] { 0x08, 0x04 });
var resp1 = PostData(licenceURL, drmHeaders, new byte[] { 0x08, 0x04 });
var certDataB64 = Convert.ToBase64String(resp1);
var cdm = new CDMApi();
var challenge = cdm.GetChallenge(pssh, certDataB64, false, false);
var resp2 = await PostData(licenceURL, drmHeaders, challenge);
var resp2 = PostData(licenceURL, drmHeaders, challenge);
var licenseB64 = Convert.ToBase64String(resp2);
Log.Debug($"resp1: {resp1}");
Log.Debug($"certDataB64: {certDataB64}");

View File

@ -3,7 +3,4 @@ namespace OF_DL.Helpers;
public static class Constants
{
public const string API_URL = "https://onlyfans.com/api2/v2";
public const int WIDEVINE_RETRY_DELAY = 10;
public const int WIDEVINE_MAX_RETRIES = 3;
}

View File

@ -1,5 +1,4 @@
using OF_DL.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
@ -14,66 +13,46 @@ namespace WidevineClient
//Proxy = null
});
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, string postData)
public static byte[] PostData(string URL, Dictionary<string, string> headers, string postData)
{
var mediaType = postData.StartsWith("{") ? "application/json" : "application/x-www-form-urlencoded";
var response = await PerformOperation(async () =>
{
StringContent content = new StringContent(postData, Encoding.UTF8, mediaType);
//ByteArrayContent content = new ByteArrayContent(postData);
StringContent content = new StringContent(postData, Encoding.UTF8, mediaType);
//ByteArrayContent content = new ByteArrayContent(postData);
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return bytes;
}
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, byte[] postData)
public static byte[] PostData(string URL, Dictionary<string, string> headers, byte[] postData)
{
var response = await PerformOperation(async () =>
{
ByteArrayContent content = new ByteArrayContent(postData);
ByteArrayContent content = new ByteArrayContent(postData);
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return bytes;
}
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, Dictionary<string, string> postData)
public static byte[] PostData(string URL, Dictionary<string, string> headers, Dictionary<string, string> postData)
{
var response = await PerformOperation(async () =>
{
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return bytes;
}
public static async Task<string> GetWebSource(string URL, Dictionary<string, string> headers = null)
public static string GetWebSource(string URL, Dictionary<string, string> headers = null)
{
var response = await PerformOperation(async () =>
{
return await Get(URL, headers);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
HttpResponseMessage response = Get(URL, headers);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return Encoding.UTF8.GetString(bytes);
}
public static async Task<byte[]> GetBinary(string URL, Dictionary<string, string> headers = null)
public static byte[] GetBinary(string URL, Dictionary<string, string> headers = null)
{
var response = await PerformOperation(async () =>
{
return await Get(URL, headers);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
HttpResponseMessage response = Get(URL, headers);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return bytes;
}
public static string GetString(byte[] bytes)
@ -81,7 +60,7 @@ namespace WidevineClient
return Encoding.UTF8.GetString(bytes);
}
private static async Task<HttpResponseMessage> Get(string URL, Dictionary<string, string> headers = null)
static HttpResponseMessage Get(string URL, Dictionary<string, string> headers = null)
{
HttpRequestMessage request = new HttpRequestMessage()
{
@ -93,10 +72,10 @@ namespace WidevineClient
foreach (KeyValuePair<string, string> header in headers)
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
return await Send(request);
return Send(request);
}
private static async Task<HttpResponseMessage> Post(string URL, Dictionary<string, string> headers, HttpContent content)
static HttpResponseMessage Post(string URL, Dictionary<string, string> headers, HttpContent content)
{
HttpRequestMessage request = new HttpRequestMessage()
{
@ -109,41 +88,12 @@ namespace WidevineClient
foreach (KeyValuePair<string, string> header in headers)
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
return await Send(request);
return Send(request);
}
private static async Task<HttpResponseMessage> Send(HttpRequestMessage request)
static HttpResponseMessage Send(HttpRequestMessage request)
{
return await Client.SendAsync(request);
}
private static async Task<HttpResponseMessage> PerformOperation(Func<Task<HttpResponseMessage>> operation)
{
var response = await operation();
var retryCount = 0;
while (retryCount < Constants.WIDEVINE_MAX_RETRIES && response.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
{
//
// We've hit a rate limit, so we should wait before retrying.
//
var retryAfterSeconds = Constants.WIDEVINE_RETRY_DELAY * (retryCount + 1); // Default retry time. Increases with each retry.
if (response.Headers.RetryAfter != null && response.Headers.RetryAfter.Delta.HasValue)
{
if (response.Headers.RetryAfter.Delta.Value.TotalSeconds > 0)
retryAfterSeconds = (int)response.Headers.RetryAfter.Delta.Value.TotalSeconds + 1; // Add 1 second to ensure we wait a bit longer than the suggested time
}
await Task.Delay(retryAfterSeconds * 1000); // Peform the delay
response = await operation();
retryCount++;
}
response.EnsureSuccessStatusCode(); // Throw an exception if the response is not successful
return response;
return Client.SendAsync(request).Result;
}
}
}

View File

@ -160,7 +160,6 @@ public class Program
hoconConfig.AppendLine($" DownloadDateSelection = \"{jsonConfig.DownloadDateSelection.ToString().ToLower()}\"");
hoconConfig.AppendLine($" CustomDate = \"{jsonConfig.CustomDate?.ToString("yyyy-MM-dd")}\"");
hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}");
hoconConfig.AppendLine($" DisableTextSanitization = false");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");
@ -248,7 +247,7 @@ public class Program
{
string hoconText = File.ReadAllText("config.conf");
var hoconConfig = ConfigurationFactory.ParseString(hoconText);
var hoconConfig = ConfigurationFactory.ParseString(hoconText);
config = new Entities.Config
{
@ -280,9 +279,7 @@ public class Program
DownloadOnlySpecificDates = hoconConfig.GetBoolean("Download.DownloadOnlySpecificDates"),
DownloadDateSelection = Enum.Parse<DownloadDateSelection>(hoconConfig.GetString("Download.DownloadDateSelection"), true),
CustomDate = !string.IsNullOrWhiteSpace(hoconConfig.GetString("Download.CustomDate")) ? DateTime.Parse(hoconConfig.GetString("Download.CustomDate")) : null,
ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"),
// Optional flag; default to false when missing
DisableTextSanitization = bool.TryParse(hoconConfig.GetString("Download.DisableTextSanitization", "false"), out var dts) ? dts : false,
ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"),
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution", "source")),
// File Settings
@ -347,9 +344,7 @@ public class Program
}
}
levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config
// Apply text sanitization preference globally
OF_DL.Utils.XmlUtils.Passthrough = config.DisableTextSanitization;
levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config
Log.Debug("Configuration:");
string configString = JsonConvert.SerializeObject(config, Formatting.Indented);
Log.Debug(configString);
@ -404,11 +399,9 @@ public class Program
hoconConfig.AppendLine($" DownloadOnlySpecificDates = {jsonConfig.DownloadOnlySpecificDates.ToString().ToLower()}");
hoconConfig.AppendLine($" DownloadDateSelection = \"{jsonConfig.DownloadDateSelection.ToString().ToLower()}\"");
hoconConfig.AppendLine($" CustomDate = \"{jsonConfig.CustomDate?.ToString("yyyy-MM-dd")}\"");
hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}");
// New option defaults to false when converting legacy json
hoconConfig.AppendLine($" DisableTextSanitization = false");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");
hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");
hoconConfig.AppendLine("# File Settings");
hoconConfig.AppendLine("File {");
@ -2911,7 +2904,6 @@ public class Program
hoconConfig.AppendLine($" DownloadDateSelection = \"{newConfig.DownloadDateSelection.ToString().ToLower()}\"");
hoconConfig.AppendLine($" CustomDate = \"{newConfig.CustomDate?.ToString("yyyy-MM-dd")}\"");
hoconConfig.AppendLine($" ShowScrapeSize = {newConfig.ShowScrapeSize.ToString().ToLower()}");
hoconConfig.AppendLine($" DisableTextSanitization = {newConfig.DisableTextSanitization.ToString().ToLower()}");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(newConfig.DownloadVideoResolution == VideoResolution.source ? "source" : newConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");
@ -3071,7 +3063,6 @@ public class Program
hoconConfig.AppendLine($" DownloadDateSelection = \"{newConfig.DownloadDateSelection.ToString().ToLower()}\"");
hoconConfig.AppendLine($" CustomDate = \"{newConfig.CustomDate?.ToString("yyyy-MM-dd")}\"");
hoconConfig.AppendLine($" ShowScrapeSize = {newConfig.ShowScrapeSize.ToString().ToLower()}");
hoconConfig.AppendLine($" DisableTextSanitization = {newConfig.DisableTextSanitization.ToString().ToLower()}");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(newConfig.DownloadVideoResolution == VideoResolution.source ? "source" : newConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");

View File

@ -9,16 +9,8 @@ namespace OF_DL.Utils
{
internal static class XmlUtils
{
// When true, return original text without parsing/stripping.
public static bool Passthrough { get; set; } = false;
public static string EvaluateInnerText(string xmlValue)
{
if (Passthrough)
{
return xmlValue ?? string.Empty;
}
try
{
var parsedText = XElement.Parse($"<root>{xmlValue}</root>");

View File

@ -2,11 +2,6 @@ site_name: OF-DL Docs
site_url: https://docs.ofdl.tools
nav:
- Home: index.md
- Installation:
- Windows: installation/windows.md
- macOS: installation/macos.md
- Linux: installation/linux.md
- Docker: installation/docker.md
- Running the Program: running-the-program.md
- Config:
- Authentication: config/auth.md
@ -14,6 +9,11 @@ nav:
- Configuration: config/configuration.md
- All Configuration Options: config/all-configuration-options.md
- Custom Filename Formats: config/custom-filename-formats.md
- Installation:
- Windows: installation/windows.md
- macOS: installation/macos.md
- Linux: installation/linux.md
- Docker: installation/docker.md
theme:
name: material
features: