Compare commits

..

24 Commits

Author SHA1 Message Date
849f8d7f5f Added safe-guard against paid content returned for other models 2025-10-08 21:20:11 +02:00
a7121d0676 Fixed lookup for Paid Posts and Messages, due to API changes 2025-10-08 21:20:10 +02:00
023a811643 Extended "output blocked" to also include expired in separate file 2025-10-08 21:19:34 +02:00
ced5607186 Updated blocked user lookup with progress status 2025-10-08 21:19:33 +02:00
e6c6a3a135 Updated non-interactive list user lookup.
Tweaked order to fully replace users before updating DB.
2025-10-08 21:19:33 +02:00
bb0556b233 Debug logging in BuildHeaderAndExecuteRequests 2025-10-08 21:19:32 +02:00
8c1852c8f7 Tweaked publishing script 2025-10-08 21:19:32 +02:00
66ac4df063 Added logic to reset chat read state after downloading messages 2025-10-08 21:19:32 +02:00
92eb2c6a34 Updated subscription lookup to match OF website. 2025-10-08 21:19:31 +02:00
536dff3762 Added logic to save list of blocked users. 2025-10-08 21:19:31 +02:00
ce1a44f57e HttpClient tweaks 2025-10-08 21:19:31 +02:00
8d10d2b5e9 Added earningId to Subscribe model 2025-10-08 21:19:30 +02:00
f2c2e659c9 Improved DB connection creation with delayed retry, and connection caching 2025-10-08 21:19:30 +02:00
0d6b66f567 Extended command line args for NonInteractive 2025-10-08 21:19:30 +02:00
813d14215a Added exiting if other process is detected, to avoid overlapping runs 2025-10-08 21:19:05 +02:00
47c31f98ef Added "x of y" count to "Scraping Data For" console outputs. 2025-10-08 21:19:05 +02:00
d2b1db46b5 Config and project tweaks, plus publish script 2025-10-08 21:19:05 +02:00
00777dbd52 Fixed async usage. 2025-10-08 21:19:05 +02:00
34e6eb1d2b Merge pull request 'feat: Add option to store raw post text without sanitization (Fix #52)' (#53) from wer/OF-DL:master into master
Reviewed-on: sim0n00ps/OF-DL#53
2025-10-07 13:05:15 +00:00
78f6f1e611 Merge pull request 'fix: add widevine request retry logic to work around ratelimits' (#47) from ddirty830/OF-DL:fix-widevine-cloudflare-retry into master
Reviewed-on: sim0n00ps/OF-DL#47
2025-10-07 13:05:02 +00:00
ec88e6e783 Merge pull request 'fix: update post/message api calls due to changes' (#61) from ddirty830/OF-DL:fix-message-downloading into master
Reviewed-on: sim0n00ps/OF-DL#61
2025-10-07 13:04:34 +00:00
0761b28c72 fix: update post/message api calls due to changes 2025-10-06 15:20:55 -05:00
Grey Lee
3e7fd45589 Add DisableTextSanitization config option and update related logic 2025-09-13 17:41:22 +08:00
2c8dbb04ed fix: add widevine request retry logic to work around ratelimits 2025-08-17 12:41:35 -05:00
6 changed files with 117 additions and 40 deletions

View File

@ -104,6 +104,10 @@ 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 string[] NonInteractiveSpecificUsers { get; set; } = [];
public string[] NonInteractiveSpecificLists { get; set; } = [];

View File

@ -571,7 +571,7 @@ public class APIHelper : IAPIHelper
Dictionary<string, string> getParams = new()
{
{ "offset", offset.ToString() },
{ "limit", "50" }
{ "limit", "50" },
};
List<string> users = new();
@ -707,7 +707,8 @@ public class APIHelper : IAPIHelper
getParams = new Dictionary<string, string>
{
{ "limit", post_limit.ToString() },
{ "order", "publish_date_desc" }
{ "order", "publish_date_desc" },
{ "skip_users", "all" }
};
break;
@ -715,7 +716,8 @@ public class APIHelper : IAPIHelper
getParams = new Dictionary<string, string>
{
{ "limit", limit.ToString() },
{ "offset", offset.ToString() }
{ "offset", offset.ToString() },
{ "skip_users", "all" }
};
break;
}
@ -908,7 +910,6 @@ public class APIHelper : IAPIHelper
{ "limit", post_limit.ToString() },
{ "skip_users", "all" },
{ "format", "infinite" },
{ "offset", offset.ToString() },
{ "author", username },
};
@ -1078,7 +1079,8 @@ public class APIHelper : IAPIHelper
{
{ "limit", post_limit.ToString() },
{ "order", "publish_date_desc" },
{ "format", "infinite" }
{ "format", "infinite" },
{ "skip_users", "all" }
};
Enumerations.DownloadDateSelection downloadDateSelection = Enumerations.DownloadDateSelection.before;
@ -1409,7 +1411,8 @@ public class APIHelper : IAPIHelper
{
{ "limit", post_limit.ToString() },
{ "order", "publish_date_desc" },
{ "format", "infinite" }
{ "format", "infinite" },
{ "skip_users", "all" }
};
Enumerations.DownloadDateSelection downloadDateSelection = Enumerations.DownloadDateSelection.before;
@ -3077,11 +3080,11 @@ public class APIHelper : IAPIHelper
try
{
var resp1 = PostData(licenceURL, drmHeaders, new byte[] { 0x08, 0x04 });
var resp1 = await 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 = PostData(licenceURL, drmHeaders, challenge);
var resp2 = await PostData(licenceURL, drmHeaders, challenge);
var licenseB64 = Convert.ToBase64String(resp2);
Log.Debug($"resp1: {resp1}");
Log.Debug($"certDataB64: {certDataB64}");

View File

@ -3,4 +3,7 @@ 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,4 +1,5 @@
using System;
using OF_DL.Helpers;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
@ -13,46 +14,66 @@ namespace WidevineClient
//Proxy = null
});
public static byte[] PostData(string URL, Dictionary<string, string> headers, string postData)
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, string postData)
{
var mediaType = postData.StartsWith("{") ? "application/json" : "application/x-www-form-urlencoded";
StringContent content = new StringContent(postData, Encoding.UTF8, mediaType);
//ByteArrayContent content = new ByteArrayContent(postData);
var response = await PerformOperation(async () =>
{
StringContent content = new StringContent(postData, Encoding.UTF8, mediaType);
//ByteArrayContent content = new ByteArrayContent(postData);
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return bytes;
}
public static byte[] PostData(string URL, Dictionary<string, string> headers, byte[] postData)
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, byte[] postData)
{
ByteArrayContent content = new ByteArrayContent(postData);
var response = await PerformOperation(async () =>
{
ByteArrayContent content = new ByteArrayContent(postData);
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return bytes;
}
public static byte[] PostData(string URL, Dictionary<string, string> headers, Dictionary<string, string> postData)
public static async Task<byte[]> PostData(string URL, Dictionary<string, string> headers, Dictionary<string, string> postData)
{
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
var response = await PerformOperation(async () =>
{
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
HttpResponseMessage response = Post(URL, headers, content);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
return await Post(URL, headers, content);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return bytes;
}
public static string GetWebSource(string URL, Dictionary<string, string> headers = null)
public static async Task<string> GetWebSource(string URL, Dictionary<string, string> headers = null)
{
HttpResponseMessage response = Get(URL, headers);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
var response = await PerformOperation(async () =>
{
return await Get(URL, headers);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return Encoding.UTF8.GetString(bytes);
}
public static byte[] GetBinary(string URL, Dictionary<string, string> headers = null)
public static async Task<byte[]> GetBinary(string URL, Dictionary<string, string> headers = null)
{
HttpResponseMessage response = Get(URL, headers);
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
var response = await PerformOperation(async () =>
{
return await Get(URL, headers);
});
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return bytes;
}
public static string GetString(byte[] bytes)
@ -60,7 +81,7 @@ namespace WidevineClient
return Encoding.UTF8.GetString(bytes);
}
static HttpResponseMessage Get(string URL, Dictionary<string, string> headers = null)
private static async Task<HttpResponseMessage> Get(string URL, Dictionary<string, string> headers = null)
{
HttpRequestMessage request = new HttpRequestMessage()
{
@ -72,10 +93,10 @@ namespace WidevineClient
foreach (KeyValuePair<string, string> header in headers)
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
return Send(request);
return await Send(request);
}
static HttpResponseMessage Post(string URL, Dictionary<string, string> headers, HttpContent content)
private static async Task<HttpResponseMessage> Post(string URL, Dictionary<string, string> headers, HttpContent content)
{
HttpRequestMessage request = new HttpRequestMessage()
{
@ -88,12 +109,41 @@ namespace WidevineClient
foreach (KeyValuePair<string, string> header in headers)
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
return Send(request);
return await Send(request);
}
static HttpResponseMessage Send(HttpRequestMessage request)
private static async Task<HttpResponseMessage> Send(HttpRequestMessage request)
{
return Client.SendAsync(request).Result;
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;
}
}
}

View File

@ -162,6 +162,7 @@ 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("}");
@ -249,7 +250,7 @@ public class Program
{
string hoconText = await File.ReadAllTextAsync("config.conf");
var hoconConfig = ConfigurationFactory.ParseString(hoconText);
var hoconConfig = ConfigurationFactory.ParseString(hoconText);
config = new Entities.Config
{
@ -281,7 +282,9 @@ 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"),
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,
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution", "source")),
// File Settings
@ -346,7 +349,9 @@ public class Program
}
}
levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config
levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config
// Apply text sanitization preference globally
OF_DL.Utils.XmlUtils.Passthrough = config.DisableTextSanitization;
Log.Debug("Configuration:");
string configString = JsonConvert.SerializeObject(config, Formatting.Indented);
Log.Debug(configString);
@ -401,9 +406,11 @@ 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()}");
hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\"");
hoconConfig.AppendLine("}");
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("# File Settings");
hoconConfig.AppendLine("File {");
@ -3039,6 +3046,7 @@ 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("}");
@ -3198,6 +3206,7 @@ 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,8 +9,16 @@ 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>");